Uri Class
Constructors
Code new Uri._fromMatch(Match m) #
Uri._fromMatch(Match m) : this.fromComponents(_emptyIfNull(m[_COMPONENT_SCHEME]), _emptyIfNull(m[_COMPONENT_USER_INFO]), _emptyIfNull(m[_COMPONENT_DOMAIN]), _parseIntOrZero(m[_COMPONENT_PORT]), _emptyIfNull(m[_COMPONENT_PATH]), _emptyIfNull(m[_COMPONENT_QUERY_DATA]), _emptyIfNull(m[_COMPONENT_FRAGMENT]));
Code new Uri.fromString(String uri) #
Uri.fromString(String uri) : this._fromMatch(_splitRe.firstMatch(uri));
Code const Uri.fromComponents([String scheme = "", String userInfo = "", String domain = "", int port = 0, String path = "", String query = "", String fragment = ""]) #
const Uri.fromComponents([String this.scheme = "", String this.userInfo ="", String this.domain = "", int this.port = 0, String this.path = "", String this.query = "", String this.fragment = ""]);
Methods
Code bool hasAuthority() #
bool hasAuthority() { return (userInfo != "") || (domain != "") || (port != 0); }
Code bool isAbsolute() #
Returns true
if the URI is absolute.
bool isAbsolute() { if ("" == scheme) return false; if ("" != fragment) return false; return true; /* absolute-URI = scheme ":" hier-part [ "?" query ] * hier-part = "//" authority path-abempty * / path-absolute * / path-rootless * / path-empty * * path = path-abempty ; begins with "/" or is empty * / path-absolute ; begins with "/" but not "//" * / path-noscheme ; begins with a non-colon segment * / path-rootless ; begins with a segment * / path-empty ; zero characters * * path-abempty = *( "/" segment ) * path-absolute = "/" [ segment-nz *( "/" segment ) ] * path-noscheme = segment-nz-nc *( "/" segment ) * path-rootless = segment-nz *( "/" segment ) * path-empty = 0<pchar> * segment = *pchar * segment-nz = 1*pchar * segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) * ; non-zero-length segment without any colon ":" * * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" */ }
Code Uri resolve(String uri) #
Uri resolve(String uri) { return resolveUri(new Uri.fromString(uri)); }
Code Uri resolveUri(Uri reference) #
Uri resolveUri(Uri reference) { // From RFC 3986. String targetScheme; String targetUserInfo; String targetDomain; int targetPort; String targetPath; String targetQuery; if (reference.scheme != "") { targetScheme = reference.scheme; targetUserInfo = reference.userInfo; targetDomain = reference.domain; targetPort = reference.port; targetPath = removeDotSegments(reference.path); targetQuery = reference.query; } else { if (reference.hasAuthority()) { targetUserInfo = reference.userInfo; targetDomain = reference.domain; targetPort = reference.port; targetPath = removeDotSegments(reference.path); targetQuery = reference.query; } else { if (reference.path == "") { targetPath = this.path; if (reference.query != "") { targetQuery = reference.query; } else { targetQuery = this.query; } } else { if (reference.path.startsWith("/")) { targetPath = removeDotSegments(reference.path); } else { targetPath = removeDotSegments(merge(this.path, reference.path)); } targetQuery = reference.query; } targetUserInfo = this.userInfo; targetDomain = this.domain; targetPort = this.port; } targetScheme = this.scheme; } return new Uri.fromComponents(targetScheme, targetUserInfo, targetDomain, targetPort, targetPath, targetQuery, reference.fragment); }
Code String toString() #
String toString() { StringBuffer sb = new StringBuffer(); _addIfNonEmpty(sb, scheme, scheme, ':'); if (hasAuthority() || (scheme == "file")) { sb.add("//"); _addIfNonEmpty(sb, userInfo, userInfo, "@"); sb.add(domain === null ? "null" : domain); if (port != 0) { sb.add(":"); sb.add(port.toString()); } } sb.add(path === null ? "null" : path); _addIfNonEmpty(sb, query, "?", query); _addIfNonEmpty(sb, fragment, "#", fragment); return sb.toString(); }