OLD | NEW |
---|---|
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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 /// a context with a relative path for [current]. | 317 /// a context with a relative path for [current]. |
318 /// | 318 /// |
319 /// var context = new Context(r'some/relative/path'); | 319 /// var context = new Context(r'some/relative/path'); |
320 /// context.relative(r'/absolute/path'); // -> '/absolute/path' | 320 /// context.relative(r'/absolute/path'); // -> '/absolute/path' |
321 /// | 321 /// |
322 /// If [root] is relative, it may be impossible to determine a path from | 322 /// If [root] is relative, it may be impossible to determine a path from |
323 /// [from] to [path]. For example, if [root] and [path] are "." and [from] is | 323 /// [from] to [path]. For example, if [root] and [path] are "." and [from] is |
324 /// "/", no path can be determined. In this case, a [PathException] will be | 324 /// "/", no path can be determined. In this case, a [PathException] will be |
325 /// thrown. | 325 /// thrown. |
326 String relative(String path, {String from}) { | 326 String relative(String path, {String from}) { |
327 from = from == null ? current : this.join(current, from); | 327 if (from == null) { |
328 from = current; | |
329 } else if (this.isRelative(from) || this.isRootRelative(from)) { | |
Bob Nystrom
2015/02/18 17:09:08
Document this:
// Avoid calling [current] since i
| |
330 from = this.join(current, from); | |
331 } | |
328 | 332 |
329 // We can't determine the path from a relative path to an absolute path. | 333 // We can't determine the path from a relative path to an absolute path. |
330 if (this.isRelative(from) && this.isAbsolute(path)) { | 334 if (this.isRelative(from) && this.isAbsolute(path)) { |
331 return this.normalize(path); | 335 return this.normalize(path); |
332 } | 336 } |
333 | 337 |
334 // If the given path is relative, resolve it relative to the context's | 338 // If the given path is relative, resolve it relative to the context's |
335 // current directory. | 339 // current directory. |
336 if (this.isRelative(path) || this.isRootRelative(path)) { | 340 if (this.isRelative(path) || this.isRootRelative(path)) { |
337 path = this.absolute(path); | 341 path = this.absolute(path); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 var message = new StringBuffer(); | 554 var message = new StringBuffer(); |
551 message.write("$method("); | 555 message.write("$method("); |
552 message.write(args | 556 message.write(args |
553 .take(numArgs) | 557 .take(numArgs) |
554 .map((arg) => arg == null ? "null" : '"$arg"') | 558 .map((arg) => arg == null ? "null" : '"$arg"') |
555 .join(", ")); | 559 .join(", ")); |
556 message.write("): part ${i - 1} was null, but part $i was not."); | 560 message.write("): part ${i - 1} was null, but part $i was not."); |
557 throw new ArgumentError(message.toString()); | 561 throw new ArgumentError(message.toString()); |
558 } | 562 } |
559 } | 563 } |
OLD | NEW |