Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: dart/lib/uri/uri.dart

Issue 10850015: Changed default Uri constructor to Uri.fromComponents(), new default constructor is Uri.fromString(… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/lib/compiler/implementation/filenames.dart ('k') | dart/runtime/bin/builtin.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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('dart:uri'); 5 #library('dart:uri');
6 6
7 #import('dart:utf'); 7 #import('dart:utf');
8 8
9 #source('encode_decode.dart'); 9 #source('encode_decode.dart');
10 #source('helpers.dart'); 10 #source('helpers.dart');
11 11
12 /** 12 /**
13 * A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][]. 13 * A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][].
14 * [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html 14 * [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html
15 * [RFC-3986]: http://tools.ietf.org/html/rfc3986#section-4.3) 15 * [RFC-3986]: http://tools.ietf.org/html/rfc3986#section-4.3)
16 */ 16 */
17 class Uri { 17 class Uri {
18 final String scheme; 18 final String scheme;
19 final String userInfo; 19 final String userInfo;
20 final String domain; 20 final String domain;
21 final int port; 21 final int port;
22 final String path; 22 final String path;
23 final String query; 23 final String query;
24 final String fragment; 24 final String fragment;
25 25
26 Uri.fromString(String uri) : this._fromMatch(_splitRe.firstMatch(uri)); 26 Uri.fromString(String uri) : this._fromMatch(_splitRe.firstMatch(uri));
27 27
28 Uri._fromMatch(Match m) : this(_emptyIfNull(m[_COMPONENT_SCHEME]), 28 Uri._fromMatch(Match m) :
29 _emptyIfNull(m[_COMPONENT_USER_INFO]), 29 this.fromComponents(_emptyIfNull(m[_COMPONENT_SCHEME]),
30 _emptyIfNull(m[_COMPONENT_DOMAIN]), 30 _emptyIfNull(m[_COMPONENT_USER_INFO]),
31 _parseIntOrZero(m[_COMPONENT_PORT]), 31 _emptyIfNull(m[_COMPONENT_DOMAIN]),
32 _emptyIfNull(m[_COMPONENT_PATH]), 32 _parseIntOrZero(m[_COMPONENT_PORT]),
33 _emptyIfNull(m[_COMPONENT_QUERY_DATA]), 33 _emptyIfNull(m[_COMPONENT_PATH]),
34 _emptyIfNull(m[_COMPONENT_FRAGMENT])); 34 _emptyIfNull(m[_COMPONENT_QUERY_DATA]),
35 _emptyIfNull(m[_COMPONENT_FRAGMENT]));
35 36
36 const Uri([String this.scheme = "", String this.userInfo ="", 37 const Uri.fromComponents([String this.scheme = "", String this.userInfo ="",
37 String this.domain = "", int this.port = 0, 38 String this.domain = "", int this.port = 0,
38 String this.path = "", String this.query = "", 39 String this.path = "", String this.query = "",
39 String this.fragment = ""]); 40 String this.fragment = ""]);
41
42 Uri(String uri) : this.fromString(uri);
40 43
41 static String _emptyIfNull(String val) => val != null ? val : ''; 44 static String _emptyIfNull(String val) => val != null ? val : '';
42 45
43 static int _parseIntOrZero(String val) { 46 static int _parseIntOrZero(String val) {
44 if (val !== null && val != '') { 47 if (val !== null && val != '') {
45 return Math.parseInt(val); 48 return Math.parseInt(val);
46 } else { 49 } else {
47 return 0; 50 return 0;
48 } 51 }
49 } 52 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 targetPath = removeDotSegments(merge(this.path, reference.path)); 155 targetPath = removeDotSegments(merge(this.path, reference.path));
153 } 156 }
154 targetQuery = reference.query; 157 targetQuery = reference.query;
155 } 158 }
156 targetUserInfo = this.userInfo; 159 targetUserInfo = this.userInfo;
157 targetDomain = this.domain; 160 targetDomain = this.domain;
158 targetPort = this.port; 161 targetPort = this.port;
159 } 162 }
160 targetScheme = this.scheme; 163 targetScheme = this.scheme;
161 } 164 }
162 return new Uri(targetScheme, targetUserInfo, targetDomain, targetPort, 165 return new Uri.fromComponents(targetScheme, targetUserInfo, targetDomain,
163 targetPath, targetQuery, reference.fragment); 166 targetPort, targetPath, targetQuery,
167 reference.fragment);
164 } 168 }
165 169
166 bool hasAuthority() { 170 bool hasAuthority() {
167 return (userInfo != "") || (domain != "") || (port != 0); 171 return (userInfo != "") || (domain != "") || (port != 0);
168 } 172 }
169 173
170 String toString() { 174 String toString() {
171 StringBuffer sb = new StringBuffer(); 175 StringBuffer sb = new StringBuffer();
172 _addIfNonEmpty(sb, scheme, scheme, ':'); 176 _addIfNonEmpty(sb, scheme, scheme, ':');
173 if (hasAuthority() || (scheme == "file")) { 177 if (hasAuthority() || (scheme == "file")) {
(...skipping 12 matching lines...) Expand all
186 } 190 }
187 191
188 static void _addIfNonEmpty(StringBuffer sb, String test, 192 static void _addIfNonEmpty(StringBuffer sb, String test,
189 String first, String second) { 193 String first, String second) {
190 if ("" != test) { 194 if ("" != test) {
191 sb.add(first === null ? "null" : first); 195 sb.add(first === null ? "null" : first);
192 sb.add(second === null ? "null" : second); 196 sb.add(second === null ? "null" : second);
193 } 197 }
194 } 198 }
195 } 199 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/filenames.dart ('k') | dart/runtime/bin/builtin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698