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

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

Issue 12473003: Remove deprecated StringBuffer.add, addAll and addCharCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
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 part of dart.uri; 5 part of dart.uri;
6 6
7 /** 7 /**
8 * A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][]. 8 * A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][].
9 * [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html 9 * [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html
10 * [RFC-3986]: http://tools.ietf.org/html/rfc3986#section-4.3) 10 * [RFC-3986]: http://tools.ietf.org/html/rfc3986#section-4.3)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (scheme == "") { 187 if (scheme == "") {
188 // TODO(aprelev@gmail.com): Use StateException instead 188 // TODO(aprelev@gmail.com): Use StateException instead
189 throw new ArgumentError("Cannot use origin without a scheme"); 189 throw new ArgumentError("Cannot use origin without a scheme");
190 } 190 }
191 if (scheme != "http" && scheme != "https") { 191 if (scheme != "http" && scheme != "https") {
192 // TODO(aprelev@gmail.com): Use StateException instead 192 // TODO(aprelev@gmail.com): Use StateException instead
193 throw new ArgumentError( 193 throw new ArgumentError(
194 "origin is applicable to http/https schemes only. Not \'$scheme\'"); 194 "origin is applicable to http/https schemes only. Not \'$scheme\'");
195 } 195 }
196 StringBuffer sb = new StringBuffer(); 196 StringBuffer sb = new StringBuffer();
197 sb.add(scheme); 197 sb.write(scheme);
198 sb.add(":"); 198 sb.write(":");
199 if (domain == null || domain == "") { 199 if (domain == null || domain == "") {
200 // TODO(aprelev@gmail.com): Use StateException instead 200 // TODO(aprelev@gmail.com): Use StateException instead
201 throw new ArgumentError("Cannot use origin without a domain"); 201 throw new ArgumentError("Cannot use origin without a domain");
202 } 202 }
203 203
204 sb.add("//"); 204 sb.write("//");
205 sb.add(domain); 205 sb.write(domain);
206 if (port != 0) { 206 if (port != 0) {
207 sb.add(":"); 207 sb.write(":");
208 sb.add(port); 208 sb.write(port);
209 } 209 }
210 return sb.toString(); 210 return sb.toString();
211 } 211 }
212 212
213 String toString() { 213 String toString() {
214 StringBuffer sb = new StringBuffer(); 214 StringBuffer sb = new StringBuffer();
215 _addIfNonEmpty(sb, scheme, scheme, ':'); 215 _addIfNonEmpty(sb, scheme, scheme, ':');
216 if (hasAuthority || (scheme == "file")) { 216 if (hasAuthority || (scheme == "file")) {
217 sb.add("//"); 217 sb.write("//");
218 _addIfNonEmpty(sb, userInfo, userInfo, "@"); 218 _addIfNonEmpty(sb, userInfo, userInfo, "@");
219 sb.add(domain == null ? "null" : domain); 219 sb.write(domain == null ? "null" : domain);
220 if (port != 0) { 220 if (port != 0) {
221 sb.add(":"); 221 sb.write(":");
222 sb.add(port.toString()); 222 sb.write(port.toString());
223 } 223 }
224 } 224 }
225 sb.add(path == null ? "null" : path); 225 sb.write(path == null ? "null" : path);
226 _addIfNonEmpty(sb, query, "?", query); 226 _addIfNonEmpty(sb, query, "?", query);
227 _addIfNonEmpty(sb, fragment, "#", fragment); 227 _addIfNonEmpty(sb, fragment, "#", fragment);
228 return sb.toString(); 228 return sb.toString();
229 } 229 }
230 230
231 bool operator==(other) { 231 bool operator==(other) {
232 if (other is! Uri) return false; 232 if (other is! Uri) return false;
233 Uri uri = other; 233 Uri uri = other;
234 return scheme == uri.scheme && 234 return scheme == uri.scheme &&
235 userInfo == uri.userInfo && 235 userInfo == uri.userInfo &&
236 domain == uri.domain && 236 domain == uri.domain &&
237 port == uri.port && 237 port == uri.port &&
238 path == uri.path && 238 path == uri.path &&
239 query == uri.query && 239 query == uri.query &&
240 fragment == uri.fragment; 240 fragment == uri.fragment;
241 } 241 }
242 242
243 int get hashCode { 243 int get hashCode {
244 int combine(part, current) { 244 int combine(part, current) {
245 // The sum is truncated to 30 bits to make sure it fits into a Smi. 245 // The sum is truncated to 30 bits to make sure it fits into a Smi.
246 return (current * 31 + part.hashCode) & 0x3FFFFFFF; 246 return (current * 31 + part.hashCode) & 0x3FFFFFFF;
247 } 247 }
248 return combine(scheme, combine(userInfo, combine(domain, combine(port, 248 return combine(scheme, combine(userInfo, combine(domain, combine(port,
249 combine(path, combine(query, combine(fragment, 1))))))); 249 combine(path, combine(query, combine(fragment, 1)))))));
250 } 250 }
251 251
252 static void _addIfNonEmpty(StringBuffer sb, String test, 252 static void _addIfNonEmpty(StringBuffer sb, String test,
253 String first, String second) { 253 String first, String second) {
254 if ("" != test) { 254 if ("" != test) {
255 sb.add(first == null ? "null" : first); 255 sb.write(first == null ? "null" : first);
256 sb.add(second == null ? "null" : second); 256 sb.write(second == null ? "null" : second);
257 } 257 }
258 } 258 }
259 } 259 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698