blob: 07872d518352a26a0ae290cb0c00e59ee71382b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// original code: http://code.google.com/p/js-uri/
// Based on the regex in RFC2396 Appendix B.
var URI_RE = /^(?:([^:\/?\#]+):)?(?:\/\/([^\/?\#]*))?([^?\#]*)(?:\?([^\#]*))?(?:\#(.*))?/;
/**
* Uniform Resource Identifier (URI) - RFC3986
*/
var URI = exports.URI = function(str) {
if (!str) str = "";
var result = str.match(URI_RE);
this.scheme = result[1] || null;
this.authority = result[2] || null;
this.path = result[3] || null;
this.query = result[4] || null;
this.fragment = result[5] || null;
}
/**
* Convert the URI to a String.
*/
URI.prototype.toString = function () {
var str = "";
if (this.scheme)
str += this.scheme + ":";
if (this.authority)
str += "//" + this.authority;
if (this.path)
str += this.path;
if (this.query)
str += "?" + this.query;
if (this.fragment)
str += "#" + this.fragment;
return str;
}
URI.parse = function(uri) {
return new URI(uri);
}
|