| 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'; |
| 11 import '../path.dart' as p; | 11 import '../path.dart' as p; |
| 12 | 12 |
| 13 Context createInternal() => new Context._internal(); |
| 14 |
| 13 /// An instantiable class for manipulating paths. Unlike the top-level | 15 /// An instantiable class for manipulating paths. Unlike the top-level |
| 14 /// functions, this lets you explicitly select what platform the paths will use. | 16 /// functions, this lets you explicitly select what platform the paths will use. |
| 15 class Context { | 17 class Context { |
| 16 /// Creates a new path context for the given style and current directory. | 18 /// Creates a new path context for the given style and current directory. |
| 17 /// | 19 /// |
| 18 /// If [style] is omitted, it uses the host operating system's path style. If | 20 /// If [style] is omitted, it uses the host operating system's path style. If |
| 19 /// only [current] is omitted, it defaults ".". If *both* [style] and | 21 /// only [current] is omitted, it defaults ".". If *both* [style] and |
| 20 /// [current] are omitted, [current] defaults to the real current working | 22 /// [current] are omitted, [current] defaults to the real current working |
| 21 /// directory. | 23 /// directory. |
| 22 /// | 24 /// |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 if (style == null) { | 36 if (style == null) { |
| 35 style = Style.platform; | 37 style = Style.platform; |
| 36 } else if (style is! InternalStyle) { | 38 } else if (style is! InternalStyle) { |
| 37 throw new ArgumentError("Only styles defined by the path package are " | 39 throw new ArgumentError("Only styles defined by the path package are " |
| 38 "allowed."); | 40 "allowed."); |
| 39 } | 41 } |
| 40 | 42 |
| 41 return new Context._(style, current); | 43 return new Context._(style, current); |
| 42 } | 44 } |
| 43 | 45 |
| 44 Context._(this.style, this.current); | 46 /// Create a [Context] to be used internally within path. |
| 47 Context._internal() : style = Style.platform; |
| 48 |
| 49 Context._(this.style, this._current); |
| 45 | 50 |
| 46 /// The style of path that this context works with. | 51 /// The style of path that this context works with. |
| 47 final InternalStyle style; | 52 final InternalStyle style; |
| 48 | 53 |
| 49 /// The current directory that relative paths will be relative to. | 54 /// The current directory given when Context was created. If null, current |
| 50 final String current; | 55 /// directory is evaluated from 'p.current'. |
| 56 final String _current; |
| 57 |
| 58 /// The current directory that relative paths are relative to. |
| 59 String get current => _current != null ? _current : p.current; |
| 51 | 60 |
| 52 /// Gets the path separator for the context's [style]. On Mac and Linux, | 61 /// Gets the path separator for the context's [style]. On Mac and Linux, |
| 53 /// this is `/`. On Windows, it's `\`. | 62 /// this is `/`. On Windows, it's `\`. |
| 54 String get separator => style.separator; | 63 String get separator => style.separator; |
| 55 | 64 |
| 56 /// Creates a new path by appending the given path parts to [current]. | 65 /// Creates a new path by appending the given path parts to [current]. |
| 57 /// Equivalent to [join()] with [current] as the first argument. Example: | 66 /// Equivalent to [join()] with [current] as the first argument. Example: |
| 58 /// | 67 /// |
| 59 /// var context = new Context(current: '/root'); | 68 /// var context = new Context(current: '/root'); |
| 60 /// context.absolute('path', 'to', 'foo'); // -> '/root/path/to/foo' | 69 /// context.absolute('path', 'to', 'foo'); // -> '/root/path/to/foo' |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 // Show the arguments. | 547 // Show the arguments. |
| 539 var message = new StringBuffer(); | 548 var message = new StringBuffer(); |
| 540 message.write("$method("); | 549 message.write("$method("); |
| 541 message.write(args.take(numArgs) | 550 message.write(args.take(numArgs) |
| 542 .map((arg) => arg == null ? "null" : '"$arg"') | 551 .map((arg) => arg == null ? "null" : '"$arg"') |
| 543 .join(", ")); | 552 .join(", ")); |
| 544 message.write("): part ${i - 1} was null, but part $i was not."); | 553 message.write("): part ${i - 1} was null, but part $i was not."); |
| 545 throw new ArgumentError(message.toString()); | 554 throw new ArgumentError(message.toString()); |
| 546 } | 555 } |
| 547 } | 556 } |
| OLD | NEW |