Dart API Referencedart:uri

dart:uri library

Functions

String removeDotSegments(String path) #

String removeDotSegments(String path) {
 List<String> output = [];
 bool appendSlash = false;
 for (String segment in path.split("/")) {
   appendSlash = false;
   if (segment == "..") {
     if (!output.isEmpty &&
         ((output.length != 1) || (output[0] != ""))) output.removeLast();
     appendSlash = true;
   } else if ("." == segment) {
     appendSlash = true;
   } else {
     output.add(segment);
   }
 }
 if (appendSlash) output.add("");
 return output.join("/");
}

String merge(String base, String reference) #

String merge(String base, String reference) {
 if (base == "") return "/$reference";
 return "${base.substring(0, base.lastIndexOf("/") + 1)}$reference";
}

String decodeUriComponent(String encodedComponent) #

An implementation of JavaScript's decodeURIComponent function. Decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine. It returns the unescaped string.

String decodeUriComponent(String encodedComponent) {
 return _uriDecode(encodedComponent);
}

String encodeUriComponent(String component) #

A javaScript-like URI component encoder, this encodes a URI component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters). To avoid unexpected requests to the server, you should call encodeURIComponent on any user-entered parameters that will be passed as part of a URI. For example, a user could type "Thyme &time=again" for a variable comment. Not using encodeURIComponent on this variable will give comment=Thyme%20&time=again. Note that the ampersand and the equal sign mark a new key and value pair. So instead of having a POST comment key equal to "Thyme &time=again", you have two POST keys, one equal to "Thyme " and another (time) equal to again. It returns the escaped string.

String encodeUriComponent(String component) {
 // Bit vector of 128 bits where each bit indicate whether a
 // character code on the 0-127 needs to be escaped or not.
 const canonicalTable = const [
               //             LSB            MSB
               //              |              |
     0x0000,   // 0x00 - 0x0f  0000000000000000
     0x0000,   // 0x10 - 0x1f  0000000000000000
               //               !     '()*  -.
     0x6782,   // 0x20 - 0x2f  0100000111100110
               //              0123456789
     0x03ff,   // 0x30 - 0x3f  1111111111000000
               //              @ABCDEFGHIJKLMNO
     0xfffe,   // 0x40 - 0x4f  0111111111111111
               //              PQRSTUVWXYZ    _
     0x87ff,   // 0x50 - 0x5f  1111111111100001
               //               abcdefghijklmno
     0xfffe,   // 0x60 - 0x6f  0111111111111111
               //              pqrstuvwxyz   ~
     0x47ff];  // 0x70 - 0x7f  1111111111100010
 return _uriEncode(canonicalTable, component);
}

String decodeUri(String uri) #

An implementation of JavaScript's decodeURIComponent function. Decodes a Uniform Resource Identifier uri previously created by encodeURI or by a similar routine. It replaces each escape sequence in uri with the character that it represents. It does not decode escape sequences that could not have been introduced by encodeURI. It returns the unescaped URI.

String decodeUri(String uri) {
 return _uriDecode(uri);
}

String encodeUri(String uri) #

Javascript-like URI encode/decode functions. The documentation here borrows heavily from the original Javascript doumentation on MDN at: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects

A JavaScript-like URI encoder. Encodes Uniform Resource Identifier uri by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters). This assumes that uri is a complete URI, so does not encode reserved characters that have special meaning in the URI: #;,/?:@&=+\$ It returns the escaped URI.

String encodeUri(String uri) {
 // Bit vector of 128 bits where each bit indicate whether a
 // character code on the 0-127 needs to be escaped or not.
 const canonicalTable = const [
               //             LSB            MSB
               //              |              |
     0x0000,   // 0x00 - 0x0f  0000000000000000
     0x0000,   // 0x10 - 0x1f  0000000000000000
               //               ! #$ &'()*+,-./
     0xf7da,   // 0x20 - 0x2f  0101101111101111
               //              0123456789:; = ?
     0xafff,   // 0x30 - 0x3f  1111111111110101
               //              @ABCDEFGHIJKLMNO
     0xffff,   // 0x40 - 0x4f  1111111111111111
               //              PQRSTUVWXYZ    _
     0x87ff,   // 0x50 - 0x5f  1111111111100001
               //               abcdefghijklmno
     0xfffe,   // 0x60 - 0x6f  0111111111111111
               //              pqrstuvwxyz   ~
     0x47ff];  // 0x70 - 0x7f  1111111111100010
 return _uriEncode(canonicalTable, uri);
}

Classes

Uri