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

Side by Side Diff: sdk/lib/io/path_impl.dart

Issue 12426013: dart:io | The empty path should return "." for its toNativePath value. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « sdk/lib/io/path.dart ('k') | tests/standalone/io/path_test.dart » ('j') | 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 dart.io; 5 part of dart.io;
6 6
7 class _Path implements Path { 7 class _Path implements Path {
8 final String _path; 8 final String _path;
9 final bool isWindowsShare; 9 final bool isWindowsShare;
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return further.canonicalize(); 147 return further.canonicalize();
148 } 148 }
149 if (hasTrailingSeparator) { 149 if (hasTrailingSeparator) {
150 var joined = new _Path._internal('$_path${further}', isWindowsShare); 150 var joined = new _Path._internal('$_path${further}', isWindowsShare);
151 return joined.canonicalize(); 151 return joined.canonicalize();
152 } 152 }
153 var joined = new _Path._internal('$_path/${further}', isWindowsShare); 153 var joined = new _Path._internal('$_path/${further}', isWindowsShare);
154 return joined.canonicalize(); 154 return joined.canonicalize();
155 } 155 }
156 156
157 // Note: The URI RFC names for these operations are normalize, resolve, and 157 // Note: The URI RFC names for canonicalize, join, and relativeTo
158 // relativize. 158 // are normalize, resolve, and relativize. But resolve and relativize
159 // drop the last segment of the base path (the filename), on URIs.
159 Path canonicalize() { 160 Path canonicalize() {
160 if (isCanonical) return this; 161 if (isCanonical) return this;
161 return makeCanonical(); 162 return makeCanonical();
162 } 163 }
163 164
164 bool get isCanonical { 165 bool get isCanonical {
165 // Contains no consecutive path separators. 166 // Contains no consecutive path separators.
166 // Contains no segments that are '.'. 167 // Contains no segments that are '.'.
167 // Absolute paths have no segments that are '..'. 168 // Absolute paths have no segments that are '..'.
168 // All '..' segments of a relative path are at the beginning. 169 // All '..' segments of a relative path are at the beginning.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } else { 239 } else {
239 segmentsToJoin.addAll(newSegs); 240 segmentsToJoin.addAll(newSegs);
240 if (hasTrailingSeparator) { 241 if (hasTrailingSeparator) {
241 segmentsToJoin.add(''); 242 segmentsToJoin.add('');
242 } 243 }
243 } 244 }
244 return new _Path._internal(segmentsToJoin.join('/'), isWindowsShare); 245 return new _Path._internal(segmentsToJoin.join('/'), isWindowsShare);
245 } 246 }
246 247
247 String toNativePath() { 248 String toNativePath() {
249 if (isEmpty) return '.';
248 if (Platform.operatingSystem == 'windows') { 250 if (Platform.operatingSystem == 'windows') {
249 String nativePath = _path; 251 String nativePath = _path;
250 // Drop '/' before a drive letter. 252 // Drop '/' before a drive letter.
251 if (nativePath.length >= 3 && 253 if (nativePath.length >= 3 &&
252 nativePath.startsWith('/') && 254 nativePath.startsWith('/') &&
253 nativePath[2] == ':') { 255 nativePath[2] == ':') {
254 nativePath = nativePath.substring(1); 256 nativePath = nativePath.substring(1);
255 } 257 }
256 nativePath = nativePath.replaceAll('/', '\\'); 258 nativePath = nativePath.replaceAll('/', '\\');
257 if (isWindowsShare) { 259 if (isWindowsShare) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 while (pos > 0 && _path[pos - 1] == '/') --pos; 300 while (pos > 0 && _path[pos - 1] == '/') --pos;
299 var dirPath = (pos > 0) ? _path.substring(0, pos) : '/'; 301 var dirPath = (pos > 0) ? _path.substring(0, pos) : '/';
300 return new _Path._internal(dirPath, isWindowsShare); 302 return new _Path._internal(dirPath, isWindowsShare);
301 } 303 }
302 304
303 String get filename { 305 String get filename {
304 int pos = _path.lastIndexOf('/'); 306 int pos = _path.lastIndexOf('/');
305 return _path.substring(pos + 1); 307 return _path.substring(pos + 1);
306 } 308 }
307 } 309 }
OLDNEW
« no previous file with comments | « sdk/lib/io/path.dart ('k') | tests/standalone/io/path_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698