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

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

Issue 1473563003: Cache the current working directory. (Closed) Base URL: git@github.com:dart-lang/path@master
Patch Set: Code review changes Created 5 years 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
« lib/path.dart ('K') | « lib/path.dart ('k') | no next file » | 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 'characters.dart' as chars; 7 import 'characters.dart' as chars;
8 import 'internal_style.dart'; 8 import 'internal_style.dart';
9 import 'style.dart'; 9 import 'style.dart';
10 import 'parsed_path.dart'; 10 import 'parsed_path.dart';
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 /// a context with a relative path for [current]. 404 /// a context with a relative path for [current].
405 /// 405 ///
406 /// var context = new Context(r'some/relative/path'); 406 /// var context = new Context(r'some/relative/path');
407 /// context.relative(r'/absolute/path'); // -> '/absolute/path' 407 /// context.relative(r'/absolute/path'); // -> '/absolute/path'
408 /// 408 ///
409 /// If [root] is relative, it may be impossible to determine a path from 409 /// If [root] is relative, it may be impossible to determine a path from
410 /// [from] to [path]. For example, if [root] and [path] are "." and [from] is 410 /// [from] to [path]. For example, if [root] and [path] are "." and [from] is
411 /// "/", no path can be determined. In this case, a [PathException] will be 411 /// "/", no path can be determined. In this case, a [PathException] will be
412 /// thrown. 412 /// thrown.
413 String relative(String path, {String from}) { 413 String relative(String path, {String from}) {
414 // Avoid expensive computation if the path is already relative.
415 if (from == null && this.isRelative(path)) return path;
416
414 // Avoid calling [current] since it is slow and calling join() when 417 // Avoid calling [current] since it is slow and calling join() when
415 // [from] is absolute does nothing. 418 // [from] is absolute does nothing.
416 if (from == null) { 419 if (from == null) {
417 from = current; 420 from = current;
418 } else if (this.isRelative(from) || this.isRootRelative(from)) { 421 } else if (this.isRelative(from) || this.isRootRelative(from)) {
419 from = this.join(current, from); 422 from = this.join(current, from);
420 } 423 }
421 424
422 // We can't determine the path from a relative path to an absolute path. 425 // We can't determine the path from a relative path to an absolute path.
423 if (this.isRelative(from) && this.isAbsolute(path)) { 426 if (this.isRelative(from) && this.isAbsolute(path)) {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 var message = new StringBuffer(); 646 var message = new StringBuffer();
644 message.write("$method("); 647 message.write("$method(");
645 message.write(args 648 message.write(args
646 .take(numArgs) 649 .take(numArgs)
647 .map((arg) => arg == null ? "null" : '"$arg"') 650 .map((arg) => arg == null ? "null" : '"$arg"')
648 .join(", ")); 651 .join(", "));
649 message.write("): part ${i - 1} was null, but part $i was not."); 652 message.write("): part ${i - 1} was null, but part $i was not.");
650 throw new ArgumentError(message.toString()); 653 throw new ArgumentError(message.toString());
651 } 654 }
652 } 655 }
OLDNEW
« lib/path.dart ('K') | « lib/path.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698