| 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 28 matching lines...) Expand all Loading... |
| 39 /// underlying platform that the program is running on, you can create a | 39 /// underlying platform that the program is running on, you can create a |
| 40 /// [Builder] and give it an explicit [Style]: | 40 /// [Builder] and give it an explicit [Style]: |
| 41 /// | 41 /// |
| 42 /// var builder = new path.Builder(style: Style.windows); | 42 /// var builder = new path.Builder(style: Style.windows); |
| 43 /// builder.join("directory", "file.txt"); | 43 /// builder.join("directory", "file.txt"); |
| 44 /// | 44 /// |
| 45 /// This will join "directory" and "file.txt" using the Windows path separator, | 45 /// This will join "directory" and "file.txt" using the Windows path separator, |
| 46 /// even when the program is run on a POSIX machine. | 46 /// even when the program is run on a POSIX machine. |
| 47 library path; | 47 library path; |
| 48 | 48 |
| 49 /// An internal builder for the current OS so we can provide a straight | |
| 50 /// functional interface and not require users to create one. | |
| 51 final _builder = new Builder(); | |
| 52 | |
| 53 /// A default builder for manipulating POSIX paths. | 49 /// A default builder for manipulating POSIX paths. |
| 54 final posix = new Builder(style: Style.posix); | 50 final posix = new Builder(style: Style.posix); |
| 55 | 51 |
| 56 /// A default builder for manipulating Windows paths. | 52 /// A default builder for manipulating Windows paths. |
| 57 final windows = new Builder(style: Style.windows); | 53 final windows = new Builder(style: Style.windows); |
| 58 | 54 |
| 59 /// A default builder for manipulating URLs. | 55 /// A default builder for manipulating URLs. |
| 60 final url = new Builder(style: Style.url); | 56 final url = new Builder(style: Style.url); |
| 61 | 57 |
| 62 /// Inserts [length] elements in front of the [list] and fills them with the | 58 /// Inserts [length] elements in front of the [list] and fills them with the |
| 63 /// [fillValue]. | 59 /// [fillValue]. |
| 64 void _growListFront(List list, int length, fillValue) => | 60 void _growListFront(List list, int length, fillValue) => |
| 65 list.insertAll(0, new List.filled(length, fillValue)); | 61 list.insertAll(0, new List.filled(length, fillValue)); |
| 66 | 62 |
| 63 /// The result of [Uri.base] last time the current working directory was |
| 64 /// calculated. |
| 65 /// |
| 66 /// This is used to invalidate [_cachedBuilder] when the working directory has |
| 67 /// changed since the last time a function was called. |
| 68 Uri _lastBaseUri; |
| 69 |
| 70 /// An internal builder for the current OS so we can provide a straight |
| 71 /// functional interface and not require users to create one. |
| 72 Builder get _builder { |
| 73 if (_cachedBuilder != null && Uri.base == _lastBaseUri) return _cachedBuilder; |
| 74 _lastBaseUri = Uri.base; |
| 75 _cachedBuilder = new Builder(); |
| 76 return _cachedBuilder; |
| 77 } |
| 78 Builder _cachedBuilder; |
| 67 | 79 |
| 68 /// Gets the path to the current working directory. | 80 /// Gets the path to the current working directory. |
| 69 /// | 81 /// |
| 70 /// In the browser, this means the current URL, without the last file segment. | 82 /// In the browser, this means the current URL, without the last file segment. |
| 71 String get current { | 83 String get current { |
| 72 var uri = Uri.base; | 84 var uri = Uri.base; |
| 73 if (Style.platform == Style.url) { | 85 if (Style.platform == Style.url) { |
| 74 return uri.resolve('.').toString(); | 86 return uri.resolve('.').toString(); |
| 75 } else { | 87 } else { |
| 76 var path = uri.toFilePath(); | 88 var path = uri.toFilePath(); |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 // doesn't count. | 1191 // doesn't count. |
| 1180 if (lastDot <= 0) return [file, '']; | 1192 if (lastDot <= 0) return [file, '']; |
| 1181 | 1193 |
| 1182 return [file.substring(0, lastDot), file.substring(lastDot)]; | 1194 return [file.substring(0, lastDot), file.substring(lastDot)]; |
| 1183 } | 1195 } |
| 1184 | 1196 |
| 1185 _ParsedPath clone() => new _ParsedPath( | 1197 _ParsedPath clone() => new _ParsedPath( |
| 1186 style, root, isRootRelative, | 1198 style, root, isRootRelative, |
| 1187 new List.from(parts), new List.from(separators)); | 1199 new List.from(parts), new List.from(separators)); |
| 1188 } | 1200 } |
| OLD | NEW |