Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
ngeoffray
2012/03/12 23:18:36
This file should soon be removed. The original uri
| |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('uri'); | 5 #library('uri'); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A parsed URI, inspired by: | 8 * A parsed URI, inspired by: |
| 9 * http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html | 9 * http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html |
| 10 */ | 10 */ |
| 11 // TODO(ngeoffray): Remove this file once Leg support compile-time constants. | |
| 11 class Uri { | 12 class Uri { |
| 12 final String scheme; | 13 final String scheme; |
| 13 final String userInfo; | 14 final String userInfo; |
| 14 final String domain; | 15 final String domain; |
| 15 final int port; | 16 final int port; |
| 16 final String path; | 17 final String path; |
| 17 final String query; | 18 final String query; |
| 18 final String fragment; | 19 final String fragment; |
| 19 | 20 |
| 20 Uri.fromString(String uri) : this._fromMatch(_splitRe.firstMatch(uri)); | 21 Uri.fromString(String uri) : this._fromMatch(_splitRe.firstMatch(uri)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 36 | 37 |
| 37 static int _parseIntOrZero(String val) { | 38 static int _parseIntOrZero(String val) { |
| 38 if (val !== null && val != '') { | 39 if (val !== null && val != '') { |
| 39 return Math.parseInt(val); | 40 return Math.parseInt(val); |
| 40 } else { | 41 } else { |
| 41 return 0; | 42 return 0; |
| 42 } | 43 } |
| 43 } | 44 } |
| 44 | 45 |
| 45 // NOTE: This code was ported from: closure-library/closure/goog/uri/utils.js | 46 // NOTE: This code was ported from: closure-library/closure/goog/uri/utils.js |
| 46 static final RegExp _splitRe = const RegExp( | 47 static RegExp _regexp; |
| 47 '^' + | 48 static RegExp get _splitRe() { |
| 48 '(?:' + | 49 if (_regexp == null) { |
| 49 '([^:/?#.]+)' + // scheme - ignore special characters | 50 _regexp = new RegExp( |
| 50 // used by other URL parts such as :, | 51 '^' + |
| 51 // ?, /, #, and . | 52 '(?:' + |
| 52 ':)?' + | 53 '([^:/?#.]+)' + // scheme - ignore special characters |
| 53 '(?://' + | 54 // used by other URL parts such as :, |
| 54 '(?:([^/?#]*)@)?' + // userInfo | 55 // ?, /, #, and . |
| 55 '([\\w\\d\\-\\u0100-\\uffff.%]*)' + | 56 ':)?' + |
| 56 // domain - restrict to letters, | 57 '(?://' + |
| 57 // digits, dashes, dots, percent | 58 '(?:([^/?#]*)@)?' + // userInfo |
| 58 // escapes, and unicode characters. | 59 '([\\w\\d\\-\\u0100-\\uffff.%]*)' + |
| 59 '(?::([0-9]+))?' + // port | 60 // domain - restrict to letters, |
| 60 ')?' + | 61 // digits, dashes, dots, percent |
| 61 '([^?#]+)?' + // path | 62 // escapes, and unicode characters. |
| 62 '(?:\\?([^#]*))?' + // query | 63 '(?::([0-9]+))?' + // port |
| 63 '(?:#(.*))?' + // fragment | 64 ')?' + |
| 64 '\$'); | 65 '([^?#]+)?' + // path |
| 66 '(?:\\?([^#]*))?' + // query | |
| 67 '(?:#(.*))?' + // fragment | |
| 68 '\$'); | |
| 69 } | |
| 70 return _regexp; | |
| 71 } | |
| 65 | 72 |
| 66 static final _COMPONENT_SCHEME = 1; | 73 static final _COMPONENT_SCHEME = 1; |
| 67 static final _COMPONENT_USER_INFO = 2; | 74 static final _COMPONENT_USER_INFO = 2; |
| 68 static final _COMPONENT_DOMAIN = 3; | 75 static final _COMPONENT_DOMAIN = 3; |
| 69 static final _COMPONENT_PORT = 4; | 76 static final _COMPONENT_PORT = 4; |
| 70 static final _COMPONENT_PATH = 5; | 77 static final _COMPONENT_PATH = 5; |
| 71 static final _COMPONENT_QUERY_DATA = 6; | 78 static final _COMPONENT_QUERY_DATA = 6; |
| 72 static final _COMPONENT_FRAGMENT = 7; | 79 static final _COMPONENT_FRAGMENT = 7; |
| 73 | 80 |
| 74 /** | 81 /** |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 appendSlash = true; | 213 appendSlash = true; |
| 207 } else if ("." == segment) { | 214 } else if ("." == segment) { |
| 208 appendSlash = true; | 215 appendSlash = true; |
| 209 } else { | 216 } else { |
| 210 output.add(segment); | 217 output.add(segment); |
| 211 } | 218 } |
| 212 } | 219 } |
| 213 if (appendSlash) output.add(""); | 220 if (appendSlash) output.add(""); |
| 214 return Strings.join(output, "/"); | 221 return Strings.join(output, "/"); |
| 215 } | 222 } |
| OLD | NEW |