| 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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 | 750 |
| 751 // Remove the root prefix, if any. | 751 // Remove the root prefix, if any. |
| 752 var root = style.getRoot(path); | 752 var root = style.getRoot(path); |
| 753 var isRootRelative = style.getRelativeRoot(path) != null; | 753 var isRootRelative = style.getRelativeRoot(path) != null; |
| 754 if (root != null) path = path.substring(root.length); | 754 if (root != null) path = path.substring(root.length); |
| 755 | 755 |
| 756 // Split the parts on path separators. | 756 // Split the parts on path separators. |
| 757 var parts = []; | 757 var parts = []; |
| 758 var separators = []; | 758 var separators = []; |
| 759 | 759 |
| 760 var firstSeparator = style.separatorPattern.firstMatch(path); | 760 var firstSeparator = style.separatorPattern.matchAsPrefix(path); |
| 761 if (firstSeparator != null && firstSeparator.start == 0) { | 761 if (firstSeparator != null) { |
| 762 separators.add(firstSeparator[0]); | 762 separators.add(firstSeparator[0]); |
| 763 path = path.substring(firstSeparator[0].length); | 763 path = path.substring(firstSeparator[0].length); |
| 764 } else { | 764 } else { |
| 765 separators.add(''); | 765 separators.add(''); |
| 766 } | 766 } |
| 767 | 767 |
| 768 var start = 0; | 768 var start = 0; |
| 769 for (var match in style.separatorPattern.allMatches(path)) { | 769 for (var match in style.separatorPattern.allMatches(path)) { |
| 770 parts.add(path.substring(start, match.start)); | 770 parts.add(path.substring(start, match.start)); |
| 771 separators.add(match[0]); | 771 separators.add(match[0]); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 /// The [Pattern] that can be used to match the root prefix of a root-relative | 832 /// The [Pattern] that can be used to match the root prefix of a root-relative |
| 833 /// path in this style. | 833 /// path in this style. |
| 834 /// | 834 /// |
| 835 /// This can be null to indicate that this style doesn't support root-relative | 835 /// This can be null to indicate that this style doesn't support root-relative |
| 836 /// paths. | 836 /// paths. |
| 837 final Pattern relativeRootPattern = null; | 837 final Pattern relativeRootPattern = null; |
| 838 | 838 |
| 839 /// Gets the root prefix of [path] if path is absolute. If [path] is relative, | 839 /// Gets the root prefix of [path] if path is absolute. If [path] is relative, |
| 840 /// returns `null`. | 840 /// returns `null`. |
| 841 String getRoot(String path) { | 841 String getRoot(String path) { |
| 842 var match = rootPattern.firstMatch(path); | 842 // TODO(rnystrom): Use firstMatch() when #7080 is fixed. |
| 843 if (match != null) return match[0]; | 843 var matches = rootPattern.allMatches(path); |
| 844 if (matches.isNotEmpty) return matches.first[0]; |
| 844 return getRelativeRoot(path); | 845 return getRelativeRoot(path); |
| 845 } | 846 } |
| 846 | 847 |
| 847 /// Gets the root prefix of [path] if it's root-relative. | 848 /// Gets the root prefix of [path] if it's root-relative. |
| 848 /// | 849 /// |
| 849 /// If [path] is relative or absolute and not root-relative, returns `null`. | 850 /// If [path] is relative or absolute and not root-relative, returns `null`. |
| 850 String getRelativeRoot(String path) { | 851 String getRelativeRoot(String path) { |
| 851 if (relativeRootPattern == null) return null; | 852 if (relativeRootPattern == null) return null; |
| 852 var match = relativeRootPattern.firstMatch(path); | 853 // TODO(rnystrom): Use firstMatch() when #7080 is fixed. |
| 853 if (match == null) return null; | 854 var matches = relativeRootPattern.allMatches(path); |
| 854 return match[0]; | 855 if (matches.isEmpty) return null; |
| 856 return matches.first[0]; |
| 855 } | 857 } |
| 856 | 858 |
| 857 /// Returns the path represented by [uri] in this style. | 859 /// Returns the path represented by [uri] in this style. |
| 858 String pathFromUri(Uri uri); | 860 String pathFromUri(Uri uri); |
| 859 | 861 |
| 860 /// Returns the URI that represents [path]. | 862 /// Returns the URI that represents [path]. |
| 861 /// | 863 /// |
| 862 /// Pathos will always path an absolute path for [path]. Relative paths are | 864 /// Pathos will always path an absolute path for [path]. Relative paths are |
| 863 /// handled automatically by [Builder]. | 865 /// handled automatically by [Builder]. |
| 864 Uri pathToUri(String path); | 866 Uri pathToUri(String path); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 // doesn't count. | 1125 // doesn't count. |
| 1124 if (lastDot <= 0) return [file, '']; | 1126 if (lastDot <= 0) return [file, '']; |
| 1125 | 1127 |
| 1126 return [file.substring(0, lastDot), file.substring(lastDot)]; | 1128 return [file.substring(0, lastDot), file.substring(lastDot)]; |
| 1127 } | 1129 } |
| 1128 | 1130 |
| 1129 _ParsedPath clone() => new _ParsedPath( | 1131 _ParsedPath clone() => new _ParsedPath( |
| 1130 style, root, isRootRelative, | 1132 style, root, isRootRelative, |
| 1131 new List.from(parts), new List.from(separators)); | 1133 new List.from(parts), new List.from(separators)); |
| 1132 } | 1134 } |
| OLD | NEW |