| 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 class _Path implements Path { | 5 class _Path implements Path { |
| 6 final String _path; | 6 final String _path; |
| 7 | 7 |
| 8 const _Path(String source) : _path = source; | 8 const _Path(String source) : _path = source; |
| 9 _Path.fromNative(String source) : _path = _clean(source); | 9 _Path.fromNative(String source) : _path = _clean(source); |
| 10 | 10 |
| 11 int hashCode() => _path.hashCode(); |
| 12 |
| 11 static String _clean(String source) { | 13 static String _clean(String source) { |
| 12 switch (Platform.operatingSystem) { | 14 switch (Platform.operatingSystem) { |
| 13 case 'windows': | 15 case 'windows': |
| 14 return _cleanWindows(source); | 16 return _cleanWindows(source); |
| 15 default: | 17 default: |
| 16 return source; | 18 return source; |
| 17 } | 19 } |
| 18 } | 20 } |
| 19 | 21 |
| 20 static String _cleanWindows(source) { | 22 static String _cleanWindows(source) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 174 } |
| 173 | 175 |
| 174 List<String> segments() { | 176 List<String> segments() { |
| 175 List result = _path.split('/'); | 177 List result = _path.split('/'); |
| 176 if (isAbsolute) result.removeRange(0, 1); | 178 if (isAbsolute) result.removeRange(0, 1); |
| 177 if (hasTrailingSeparator) result.removeLast(); | 179 if (hasTrailingSeparator) result.removeLast(); |
| 178 return result; | 180 return result; |
| 179 } | 181 } |
| 180 | 182 |
| 181 Path append(String finalSegment) { | 183 Path append(String finalSegment) { |
| 182 if (hasTrailingSeparator) { | 184 if (isEmpty) { |
| 185 return new Path(finalSegment); |
| 186 } else if (hasTrailingSeparator) { |
| 183 return new Path('$_path$finalSegment'); | 187 return new Path('$_path$finalSegment'); |
| 184 } else { | 188 } else { |
| 185 return new Path('$_path/$finalSegment'); | 189 return new Path('$_path/$finalSegment'); |
| 186 } | 190 } |
| 187 } | 191 } |
| 188 | 192 |
| 189 String get filenameWithoutExtension() { | 193 String get filenameWithoutExtension() { |
| 190 var name = filename; | 194 var name = filename; |
| 191 if (name == '.' || name == '..') return name; | 195 if (name == '.' || name == '..') return name; |
| 192 int pos = name.lastIndexOf('.'); | 196 int pos = name.lastIndexOf('.'); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 204 if (pos < 0) return new Path(''); | 208 if (pos < 0) return new Path(''); |
| 205 while (pos > 0 && _path[pos - 1] == '/') --pos; | 209 while (pos > 0 && _path[pos - 1] == '/') --pos; |
| 206 return new Path((pos > 0) ? _path.substring(0, pos) : '/'); | 210 return new Path((pos > 0) ? _path.substring(0, pos) : '/'); |
| 207 } | 211 } |
| 208 | 212 |
| 209 String get filename() { | 213 String get filename() { |
| 210 int pos = _path.lastIndexOf('/'); | 214 int pos = _path.lastIndexOf('/'); |
| 211 return _path.substring(pos + 1); | 215 return _path.substring(pos + 1); |
| 212 } | 216 } |
| 213 } | 217 } |
| OLD | NEW |