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 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 if (style == null) { | 36 if (style == null) { |
37 style = Style.platform; | 37 style = Style.platform; |
38 } else if (style is! InternalStyle) { | 38 } else if (style is! InternalStyle) { |
39 throw new ArgumentError("Only styles defined by the path package are " | 39 throw new ArgumentError("Only styles defined by the path package are " |
40 "allowed."); | 40 "allowed."); |
41 } | 41 } |
42 | 42 |
43 return new Context._(style, current); | 43 return new Context._(style as InternalStyle, current); |
44 } | 44 } |
45 | 45 |
46 /// Create a [Context] to be used internally within path. | 46 /// Create a [Context] to be used internally within path. |
47 Context._internal() | 47 Context._internal() |
48 : style = Style.platform, | 48 : style = Style.platform as InternalStyle, |
49 _current = null; | 49 _current = null; |
50 | 50 |
51 Context._(this.style, this._current); | 51 Context._(this.style, this._current); |
52 | 52 |
53 /// The style of path that this context works with. | 53 /// The style of path that this context works with. |
54 final InternalStyle style; | 54 final InternalStyle style; |
55 | 55 |
56 /// The current directory given when Context was created. If null, current | 56 /// The current directory given when Context was created. If null, current |
57 /// directory is evaluated from 'p.current'. | 57 /// directory is evaluated from 'p.current'. |
58 final String _current; | 58 final String _current; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 /// be added: | 190 /// be added: |
191 /// | 191 /// |
192 /// context.join('path/', 'to', 'foo'); // -> 'path/to/foo | 192 /// context.join('path/', 'to', 'foo'); // -> 'path/to/foo |
193 /// | 193 /// |
194 /// If a part is an absolute path, then anything before that will be ignored: | 194 /// If a part is an absolute path, then anything before that will be ignored: |
195 /// | 195 /// |
196 /// context.join('path', '/to', 'foo'); // -> '/to/foo' | 196 /// context.join('path', '/to', 'foo'); // -> '/to/foo' |
197 /// | 197 /// |
198 String join(String part1, [String part2, String part3, String part4, | 198 String join(String part1, [String part2, String part3, String part4, |
199 String part5, String part6, String part7, String part8]) { | 199 String part5, String part6, String part7, String part8]) { |
200 var parts = [part1, part2, part3, part4, part5, part6, part7, part8]; | 200 var parts = <String>[ |
| 201 part1, |
| 202 part2, |
| 203 part3, |
| 204 part4, |
| 205 part5, |
| 206 part6, |
| 207 part7, |
| 208 part8 |
| 209 ]; |
201 _validateArgList("join", parts); | 210 _validateArgList("join", parts); |
202 return joinAll(parts.where((part) => part != null)); | 211 return joinAll(parts.where((part) => part != null)); |
203 } | 212 } |
204 | 213 |
205 /// Joins the given path parts into a single path. Example: | 214 /// Joins the given path parts into a single path. Example: |
206 /// | 215 /// |
207 /// context.joinAll(['path', 'to', 'foo']); // -> 'path/to/foo' | 216 /// context.joinAll(['path', 'to', 'foo']); // -> 'path/to/foo' |
208 /// | 217 /// |
209 /// If any part ends in a path separator, then a redundant separator will not | 218 /// If any part ends in a path separator, then a redundant separator will not |
210 /// be added: | 219 /// be added: |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 var message = new StringBuffer(); | 565 var message = new StringBuffer(); |
557 message.write("$method("); | 566 message.write("$method("); |
558 message.write(args | 567 message.write(args |
559 .take(numArgs) | 568 .take(numArgs) |
560 .map((arg) => arg == null ? "null" : '"$arg"') | 569 .map((arg) => arg == null ? "null" : '"$arg"') |
561 .join(", ")); | 570 .join(", ")); |
562 message.write("): part ${i - 1} was null, but part $i was not."); | 571 message.write("): part ${i - 1} was null, but part $i was not."); |
563 throw new ArgumentError(message.toString()); | 572 throw new ArgumentError(message.toString()); |
564 } | 573 } |
565 } | 574 } |
OLD | NEW |