Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: tools/testing/dart/legacy_path.dart

Issue 560643002: Allow trailing / in directory paths (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of utils; 5 part of utils;
6 6
7 class Path { 7 class Path {
8 final String _path; 8 final String _path;
9 final bool isWindowsShare; 9 final bool isWindowsShare;
10 10
11 Path(String source) 11 Path(String source)
12 : _path = _clean(source), isWindowsShare = _isWindowsShare(source); 12 : _path = _clean(source), isWindowsShare = _isWindowsShare(source);
13 13
14 Path.raw(String source) : _path = source, isWindowsShare = false; 14 Path.raw(String source) : _path = source, isWindowsShare = false;
15 15
16 Path._internal(String this._path, bool this.isWindowsShare); 16 Path._internal(String this._path, bool this.isWindowsShare);
17 17
18 static String _clean(String source) { 18 static String _clean(String source) {
19 if (Platform.operatingSystem == 'windows') return _cleanWindows(source); 19 if (Platform.operatingSystem == 'windows') return _cleanWindows(source);
20 // Remove trailing slash from directories:
21 if (source.length > 1 && source.endsWith('/')) {
22 return source.substring(0, source.length - 1);
23 }
20 return source; 24 return source;
21 } 25 }
22 26
23 static String _cleanWindows(String source) { 27 static String _cleanWindows(String source) {
24 // Change \ to /. 28 // Change \ to /.
25 var clean = source.replaceAll('\\', '/'); 29 var clean = source.replaceAll('\\', '/');
26 // Add / before intial [Drive letter]: 30 // Add / before intial [Drive letter]:
27 if (clean.length >= 2 && clean[1] == ':') { 31 if (clean.length >= 2 && clean[1] == ':') {
28 clean = '/$clean'; 32 clean = '/$clean';
29 } 33 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 while (pos > 0 && _path[pos - 1] == '/') --pos; 304 while (pos > 0 && _path[pos - 1] == '/') --pos;
301 var dirPath = (pos > 0) ? _path.substring(0, pos) : '/'; 305 var dirPath = (pos > 0) ? _path.substring(0, pos) : '/';
302 return new Path._internal(dirPath, isWindowsShare); 306 return new Path._internal(dirPath, isWindowsShare);
303 } 307 }
304 308
305 String get filename { 309 String get filename {
306 int pos = _path.lastIndexOf('/'); 310 int pos = _path.lastIndexOf('/');
307 return _path.substring(pos + 1); 311 return _path.substring(pos + 1);
308 } 312 }
309 } 313 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698