OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// A comprehensive, cross-platform path manipulation library. | 5 /// A comprehensive, cross-platform path manipulation library. |
6 /// | 6 /// |
7 /// ## Installing ## | 7 /// ## Installing ## |
8 /// | 8 /// |
9 /// Use [pub][] to install this package. Add the following to your | 9 /// Use [pub][] to install this package. Add the following to your |
10 /// `pubspec.yaml` file. | 10 /// `pubspec.yaml` file. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 /// Returns the [Style] of the current context. | 72 /// Returns the [Style] of the current context. |
73 /// | 73 /// |
74 /// This is the style that all top-level path functions will use. | 74 /// This is the style that all top-level path functions will use. |
75 Style get style => context.style; | 75 Style get style => context.style; |
76 | 76 |
77 /// Gets the path to the current working directory. | 77 /// Gets the path to the current working directory. |
78 /// | 78 /// |
79 /// In the browser, this means the current URL, without the last file segment. | 79 /// In the browser, this means the current URL, without the last file segment. |
80 String get current { | 80 String get current { |
81 var uri = Uri.base; | 81 var uri = Uri.base; |
82 if (uri == _oldUriBase) return _oldCurrent; | |
Bob Nystrom
2015/11/24 17:25:16
Document that reparsing the base URI is slow so it
nweiz
2015/11/30 22:52:10
Done.
| |
83 _oldUriBase = uri; | |
84 | |
82 if (Style.platform == Style.url) { | 85 if (Style.platform == Style.url) { |
83 return uri.resolve('.').toString(); | 86 _oldCurrent = uri.resolve('.').toString(); |
87 return _oldCurrent; | |
84 } else { | 88 } else { |
85 var path = uri.toFilePath(); | 89 var path = uri.toFilePath(); |
86 // Remove trailing '/' or '\'. | 90 // Remove trailing '/' or '\'. |
87 int lastIndex = path.length - 1; | 91 var lastIndex = path.length - 1; |
88 assert(path[lastIndex] == '/' || path[lastIndex] == '\\'); | 92 assert(path[lastIndex] == '/' || path[lastIndex] == '\\'); |
89 return path.substring(0, lastIndex); | 93 _oldCurrent = path.substring(0, lastIndex); |
94 return _oldCurrent; | |
90 } | 95 } |
91 } | 96 } |
92 | 97 |
98 /// The last value returned by [Uri.base]. | |
99 /// | |
100 /// This is used to cache the current working directory. | |
101 Uri _oldUriBase; | |
102 | |
103 /// The last known value of the current working directory. | |
104 /// | |
105 /// This is cached because [current] is called frequently but rarely actually | |
106 /// changes. | |
107 String _oldCurrent; | |
Bob Nystrom
2015/11/24 17:25:16
Instead of "old", how about "_currentUriBase" and
nweiz
2015/11/30 22:52:10
Done.
| |
108 | |
93 /// Gets the path separator for the current platform. This is `\` on Windows | 109 /// Gets the path separator for the current platform. This is `\` on Windows |
94 /// and `/` on other platforms (including the browser). | 110 /// and `/` on other platforms (including the browser). |
95 String get separator => context.separator; | 111 String get separator => context.separator; |
96 | 112 |
97 /// Creates a new path by appending the given path parts to [current]. | 113 /// Creates a new path by appending the given path parts to [current]. |
98 /// Equivalent to [join()] with [current] as the first argument. Example: | 114 /// Equivalent to [join()] with [current] as the first argument. Example: |
99 /// | 115 /// |
100 /// path.absolute('path', 'to/foo'); // -> '/your/current/dir/path/to/foo' | 116 /// path.absolute('path', 'to/foo'); // -> '/your/current/dir/path/to/foo' |
101 String absolute(String part1, [String part2, String part3, String part4, | 117 String absolute(String part1, [String part2, String part3, String part4, |
102 String part5, String part6, String part7]) => | 118 String part5, String part6, String part7]) => |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 /// | 388 /// |
373 /// // Windows at "C:\root\path" | 389 /// // Windows at "C:\root\path" |
374 /// path.prettyUri('file:///C:/root/path/a/b.dart'); // -> r'a\b.dart' | 390 /// path.prettyUri('file:///C:/root/path/a/b.dart'); // -> r'a\b.dart' |
375 /// path.prettyUri('http://dartlang.org/'); // -> 'http://dartlang.org' | 391 /// path.prettyUri('http://dartlang.org/'); // -> 'http://dartlang.org' |
376 /// | 392 /// |
377 /// // URL at "http://dartlang.org/root/path" | 393 /// // URL at "http://dartlang.org/root/path" |
378 /// path.prettyUri('http://dartlang.org/root/path/a/b.dart'); | 394 /// path.prettyUri('http://dartlang.org/root/path/a/b.dart'); |
379 /// // -> r'a/b.dart' | 395 /// // -> r'a/b.dart' |
380 /// path.prettyUri('file:///root/path'); // -> 'file:///root/path' | 396 /// path.prettyUri('file:///root/path'); // -> 'file:///root/path' |
381 String prettyUri(uri) => context.prettyUri(uri); | 397 String prettyUri(uri) => context.prettyUri(uri); |
OLD | NEW |