| 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. |
| 11 /// | 11 /// |
| 12 /// dependencies: | 12 /// dependencies: |
| 13 /// path: any | 13 /// path: any |
| 14 /// | 14 /// |
| 15 /// Then run `pub install`. | 15 /// Then run `pub install`. |
| 16 /// | 16 /// |
| 17 /// For more information, see the [path package on pub.dartlang.org][pkg]. | 17 /// For more information, see the [path package on pub.dartlang.org][pkg]. |
| 18 /// | 18 /// |
| 19 /// [pub]: http://pub.dartlang.org | 19 /// [pub]: http://pub.dartlang.org |
| 20 /// [pkg]: http://pub.dartlang.org/packages/path | 20 /// [pkg]: http://pub.dartlang.org/packages/path |
| 21 library path; | 21 library path; |
| 22 | 22 |
| 23 @MirrorsUsed(targets: 'dart.dom.html.window, ' |
| 24 'dart.io.Directory.current, ' |
| 25 'dart.io.Platform.operatingSystem') |
| 23 import 'dart:mirrors'; | 26 import 'dart:mirrors'; |
| 24 | 27 |
| 25 /// An internal builder for the current OS so we can provide a straight | 28 /// An internal builder for the current OS so we can provide a straight |
| 26 /// functional interface and not require users to create one. | 29 /// functional interface and not require users to create one. |
| 27 final _builder = new Builder(); | 30 final _builder = new Builder(); |
| 28 | 31 |
| 29 /** | 32 /** |
| 30 * Inserts [length] elements in front of the [list] and fills them with the | 33 * Inserts [length] elements in front of the [list] and fills them with the |
| 31 * [fillValue]. | 34 * [fillValue]. |
| 32 */ | 35 */ |
| 33 void _growListFront(List list, int length, fillValue) => | 36 void _growListFront(List list, int length, fillValue) => |
| 34 list.insertAll(0, new List.filled(length, fillValue)); | 37 list.insertAll(0, new List.filled(length, fillValue)); |
| 35 | 38 |
| 36 /// If we're running in the server-side Dart VM, this will return a | 39 /// If we're running in the server-side Dart VM, this will return a |
| 37 /// [LibraryMirror] that gives access to the `dart:io` library. | 40 /// [LibraryMirror] that gives access to the `dart:io` library. |
| 38 /// | 41 /// |
| 39 /// If `dart:io` is not available, this returns null. | 42 /// If `dart:io` is not available, this returns null. |
| 40 LibraryMirror get _io { | 43 LibraryMirror get _io => currentMirrorSystem().libraries[Uri.parse('dart:io')]; |
| 41 try { | |
| 42 return currentMirrorSystem().libraries[Uri.parse('dart:io')]; | |
| 43 } catch (_) { | |
| 44 return null; | |
| 45 } | |
| 46 } | |
| 47 | 44 |
| 48 // TODO(nweiz): when issue 6490 or 6943 are fixed, make this work under dart2js. | 45 // TODO(nweiz): when issue 6490 or 6943 are fixed, make this work under dart2js. |
| 49 /// If we're running in Dartium, this will return a [LibraryMirror] that gives | 46 /// If we're running in Dartium, this will return a [LibraryMirror] that gives |
| 50 /// access to the `dart:html` library. | 47 /// access to the `dart:html` library. |
| 51 /// | 48 /// |
| 52 /// If `dart:html` is not available, this returns null. | 49 /// If `dart:html` is not available, this returns null. |
| 53 LibraryMirror get _html { | 50 LibraryMirror get _html => |
| 54 try { | 51 currentMirrorSystem().libraries[Uri.parse('dart:html')]; |
| 55 return currentMirrorSystem().libraries[Uri.parse('dart:html')]; | |
| 56 } catch (_) { | |
| 57 return null; | |
| 58 } | |
| 59 } | |
| 60 | 52 |
| 61 /// Gets the path to the current working directory. | 53 /// Gets the path to the current working directory. |
| 62 /// | 54 /// |
| 63 /// In the browser, this means the current URL. When using dart2js, this | 55 /// In the browser, this means the current URL. When using dart2js, this |
| 64 /// currently returns `.` due to technical constraints. In the future, it will | 56 /// currently returns `.` due to technical constraints. In the future, it will |
| 65 /// return the current URL. | 57 /// return the current URL. |
| 66 String get current { | 58 String get current { |
| 67 if (_io != null) { | 59 if (_io != null) { |
| 68 return _io.classes[const Symbol('Directory')] | 60 return _io.classes[const Symbol('Directory')] |
| 69 .getField(const Symbol('current')).reflectee.path; | 61 .getField(const Symbol('current')).reflectee.path; |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 // doesn't count. | 1123 // doesn't count. |
| 1132 if (lastDot <= 0) return [file, '']; | 1124 if (lastDot <= 0) return [file, '']; |
| 1133 | 1125 |
| 1134 return [file.substring(0, lastDot), file.substring(lastDot)]; | 1126 return [file.substring(0, lastDot), file.substring(lastDot)]; |
| 1135 } | 1127 } |
| 1136 | 1128 |
| 1137 _ParsedPath clone() => new _ParsedPath( | 1129 _ParsedPath clone() => new _ParsedPath( |
| 1138 style, root, isRootRelative, | 1130 style, root, isRootRelative, |
| 1139 new List.from(parts), new List.from(separators)); | 1131 new List.from(parts), new List.from(separators)); |
| 1140 } | 1132 } |
| OLD | NEW |