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

Side by Side Diff: pkg/path/lib/src/context.dart

Issue 309803003: Avoid using RegExps in path to work around issue 19090. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 6 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 | « pkg/path/lib/src/characters.dart ('k') | pkg/path/lib/src/internal_style.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 path.context; 5 library path.context;
6 6
7 import 'internal_style.dart'; 7 import 'internal_style.dart';
8 import 'style.dart'; 8 import 'style.dart';
9 import 'parsed_path.dart'; 9 import 'parsed_path.dart';
10 import 'path_exception.dart'; 10 import 'path_exception.dart';
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 var buffer = new StringBuffer(); 212 var buffer = new StringBuffer();
213 var needsSeparator = false; 213 var needsSeparator = false;
214 var isAbsoluteAndNotRootRelative = false; 214 var isAbsoluteAndNotRootRelative = false;
215 215
216 for (var part in parts.where((part) => part != '')) { 216 for (var part in parts.where((part) => part != '')) {
217 if (this.isRootRelative(part) && isAbsoluteAndNotRootRelative) { 217 if (this.isRootRelative(part) && isAbsoluteAndNotRootRelative) {
218 // If the new part is root-relative, it preserves the previous root but 218 // If the new part is root-relative, it preserves the previous root but
219 // replaces the path after it. 219 // replaces the path after it.
220 var parsed = _parse(part); 220 var parsed = _parse(part);
221 parsed.root = this.rootPrefix(buffer.toString()); 221 parsed.root = this.rootPrefix(buffer.toString());
222 if (parsed.root.contains(style.needsSeparatorPattern)) { 222 if (style.needsSeparator(parsed.root)) {
223 parsed.separators[0] = style.separator; 223 parsed.separators[0] = style.separator;
224 } 224 }
225 buffer.clear(); 225 buffer.clear();
226 buffer.write(parsed.toString()); 226 buffer.write(parsed.toString());
227 } else if (this.isAbsolute(part)) { 227 } else if (this.isAbsolute(part)) {
228 isAbsoluteAndNotRootRelative = !this.isRootRelative(part); 228 isAbsoluteAndNotRootRelative = !this.isRootRelative(part);
229 // An absolute path discards everything before it. 229 // An absolute path discards everything before it.
230 buffer.clear(); 230 buffer.clear();
231 buffer.write(part); 231 buffer.write(part);
232 } else { 232 } else {
233 if (part.length > 0 && part[0].contains(style.separatorPattern)) { 233 if (part.length > 0 && style.containsSeparator(part[0])) {
234 // The part starts with a separator, so we don't need to add one. 234 // The part starts with a separator, so we don't need to add one.
235 } else if (needsSeparator) { 235 } else if (needsSeparator) {
236 buffer.write(separator); 236 buffer.write(separator);
237 } 237 }
238 238
239 buffer.write(part); 239 buffer.write(part);
240 } 240 }
241 241
242 // Unless this part ends with a separator, we'll need to add one before 242 // Unless this part ends with a separator, we'll need to add one before
243 // the next part. 243 // the next part.
244 needsSeparator = part.contains(style.needsSeparatorPattern); 244 needsSeparator = style.needsSeparator(part);
245 } 245 }
246 246
247 return buffer.toString(); 247 return buffer.toString();
248 } 248 }
249 249
250 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. 250 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed.
251 /// Splits [path] into its components using the current platform's 251 /// Splits [path] into its components using the current platform's
252 /// [separator]. Example: 252 /// [separator]. Example:
253 /// 253 ///
254 /// context.split('path/to/foo'); // -> ['path', 'to', 'foo'] 254 /// context.split('path/to/foo'); // -> ['path', 'to', 'foo']
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // Show the arguments. 538 // Show the arguments.
539 var message = new StringBuffer(); 539 var message = new StringBuffer();
540 message.write("$method("); 540 message.write("$method(");
541 message.write(args.take(numArgs) 541 message.write(args.take(numArgs)
542 .map((arg) => arg == null ? "null" : '"$arg"') 542 .map((arg) => arg == null ? "null" : '"$arg"')
543 .join(", ")); 543 .join(", "));
544 message.write("): part ${i - 1} was null, but part $i was not."); 544 message.write("): part ${i - 1} was null, but part $i was not.");
545 throw new ArgumentError(message.toString()); 545 throw new ArgumentError(message.toString());
546 } 546 }
547 } 547 }
OLDNEW
« no previous file with comments | « pkg/path/lib/src/characters.dart ('k') | pkg/path/lib/src/internal_style.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698