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.parsed_path; | 5 library path.parsed_path; |
6 | 6 |
7 import 'internal_style.dart'; | 7 import 'internal_style.dart'; |
8 import 'style.dart'; | 8 import 'style.dart'; |
9 | 9 |
10 class ParsedPath { | 10 class ParsedPath { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Remove the root prefix, if any. | 46 // Remove the root prefix, if any. |
47 var root = style.getRoot(path); | 47 var root = style.getRoot(path); |
48 var isRootRelative = style.getRelativeRoot(path) != null; | 48 var isRootRelative = style.getRelativeRoot(path) != null; |
49 if (root != null) path = path.substring(root.length); | 49 if (root != null) path = path.substring(root.length); |
50 | 50 |
51 // Split the parts on path separators. | 51 // Split the parts on path separators. |
52 var parts = []; | 52 var parts = []; |
53 var separators = []; | 53 var separators = []; |
54 | 54 |
55 var firstSeparator = style.separatorPattern.matchAsPrefix(path); | 55 var start = 0; |
56 if (firstSeparator != null) { | 56 |
57 separators.add(firstSeparator[0]); | 57 if (path.isNotEmpty && style.isSeparator(path.codeUnitAt(0))) { |
58 path = path.substring(firstSeparator[0].length); | 58 separators.add(path[0]); |
| 59 start = 1; |
59 } else { | 60 } else { |
60 separators.add(''); | 61 separators.add(''); |
61 } | 62 } |
62 | 63 |
63 var start = 0; | 64 for (var i = start; i < path.length; i++) { |
64 for (var match in style.separatorPattern.allMatches(path)) { | 65 if (style.isSeparator(path.codeUnitAt(i))) { |
65 parts.add(path.substring(start, match.start)); | 66 parts.add(path.substring(start, i)); |
66 separators.add(match[0]); | 67 separators.add(path[i]); |
67 start = match.end; | 68 start = i + 1; |
| 69 } |
68 } | 70 } |
69 | 71 |
70 // Add the final part, if any. | 72 // Add the final part, if any. |
71 if (start < path.length) { | 73 if (start < path.length) { |
72 parts.add(path.substring(start)); | 74 parts.add(path.substring(start)); |
73 separators.add(''); | 75 separators.add(''); |
74 } | 76 } |
75 | 77 |
76 return new ParsedPath._(style, root, isRootRelative, parts, separators); | 78 return new ParsedPath._(style, root, isRootRelative, parts, separators); |
77 } | 79 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 128 |
127 // If we collapsed down to nothing, do ".". | 129 // If we collapsed down to nothing, do ".". |
128 if (newParts.length == 0 && !isAbsolute) { | 130 if (newParts.length == 0 && !isAbsolute) { |
129 newParts.add('.'); | 131 newParts.add('.'); |
130 } | 132 } |
131 | 133 |
132 // Canonicalize separators. | 134 // Canonicalize separators. |
133 var newSeparators = new List.generate( | 135 var newSeparators = new List.generate( |
134 newParts.length, (_) => style.separator, growable: true); | 136 newParts.length, (_) => style.separator, growable: true); |
135 newSeparators.insert(0, | 137 newSeparators.insert(0, |
136 isAbsolute && newParts.length > 0 && | 138 isAbsolute && newParts.length > 0 && style.needsSeparator(root) ? |
137 root.contains(style.needsSeparatorPattern) ? | |
138 style.separator : ''); | 139 style.separator : ''); |
139 | 140 |
140 parts = newParts; | 141 parts = newParts; |
141 separators = newSeparators; | 142 separators = newSeparators; |
142 | 143 |
143 // Normalize the Windows root if needed. | 144 // Normalize the Windows root if needed. |
144 if (root != null && style == Style.windows) { | 145 if (root != null && style == Style.windows) { |
145 root = root.replaceAll('/', '\\'); | 146 root = root.replaceAll('/', '\\'); |
146 } | 147 } |
147 removeTrailingSeparators(); | 148 removeTrailingSeparators(); |
(...skipping 29 matching lines...) Expand all Loading... |
177 if (lastDot <= 0) return [file, '']; | 178 if (lastDot <= 0) return [file, '']; |
178 | 179 |
179 return [file.substring(0, lastDot), file.substring(lastDot)]; | 180 return [file.substring(0, lastDot), file.substring(lastDot)]; |
180 } | 181 } |
181 | 182 |
182 ParsedPath clone() => new ParsedPath._( | 183 ParsedPath clone() => new ParsedPath._( |
183 style, root, isRootRelative, | 184 style, root, isRootRelative, |
184 new List.from(parts), new List.from(separators)); | 185 new List.from(parts), new List.from(separators)); |
185 } | 186 } |
186 | 187 |
OLD | NEW |