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

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

Issue 11878015: Default constructor for dart:io Path now handles native Windows paths. Path() now does the same as… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't change tools/version.dart until the binaries are updated. Created 7 years, 11 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/directory_impl.dart ('k') | sdk/lib/io/path_impl.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 /** 7 /**
8 * A Path, which is a String interpreted as a sequence of path segments, 8 * A Path is an immutable wrapper of a String, with additional member functions
9 * which are strings, separated by forward slashes. 9 * for useful path manipulations and queries.
10 * Paths are immutable wrappers of a String, that offer member functions for 10 * On the Windows platform, Path also converts from and to native paths.
11 * useful path manipulations and queries. Joining of paths and normalization 11 *
12 * interpret '.' and '..' in the usual way. 12 * Joining of paths and path normalization handle '.' and '..' in the usual way.
13 */ 13 */
14 abstract class Path { 14 abstract class Path {
15 /** 15 /**
16 * Creates a Path from the String [source]. [source] is used as-is, so if
17 * the string does not consist of segments separated by forward slashes, the
18 * behavior may not be as expected. Paths are immutable.
19 */
20 factory Path(String source) => new _Path(source);
21
22 /**
23 * Creates a Path from a String that uses the native filesystem's conventions. 16 * Creates a Path from a String that uses the native filesystem's conventions.
24 * 17 *
25 * On Windows, this converts '\' to '/' and has special handling for drive 18 * On Windows, this converts '\' to '/' and has special handling for drive
26 * letters and shares. 19 * letters and shares.
27 * 20 *
28 * If the path contains a drive letter a '/' is added before the drive letter. 21 * If the path starts with a drive letter, like 'C:', a '/' is added
22 * before the drive letter.
29 * 23 *
30 * new Path.fromNative(r'c:\a\b').toString() == '/c:/a/b' 24 * new Path(r'c:\a\b').toString() == '/c:/a/b'
31 * 25 *
32 * A path starting with '/c:/' (or any other character instead of 'c') is 26 * A path starting with '/c:/' (or any other character instead of 'c') is
33 * treated specially. Backwards links ('..') cannot cancel the drive letter. 27 * treated specially. Backwards links ('..') cannot cancel the drive letter.
34 * 28 *
35 * If the path is a share path this is recorded in the Path object and 29 * If the path is a share path this is recorded in the Path object and
36 * maintained in operations on the Path object. 30 * maintained in operations on the Path object.
37 * 31 *
38 * var share = new Path.fromNative(r'\\share\a\b\c'); 32 * var share = new Path(r'\\share\a\b\c');
39 * share.isWindowsShare == true 33 * share.isWindowsShare == true
40 * share.toString() == '/share/a/b/c' 34 * share.toString() == '/share/a/b/c'
41 * share.toNativePath() == r'\\share\a\b\c' 35 * share.toNativePath() == r'\\share\a\b\c'
42 * share.append('final').isWindowsShare == true 36 * share.append('final').isWindowsShare == true
43 */ 37 */
44 factory Path.fromNative(String source) => new _Path.fromNative(source); 38 factory Path(String source) => new _Path(source);
39
40 /**
41 * Creates a Path from the String [source]. [source] is used as-is, so if
42 * the string does not consist of segments separated by forward slashes, the
43 * behavior may not be as expected. Paths are immutable.
44 */
45 factory Path.raw(String source) => new _Path.raw(source);
45 46
46 /** 47 /**
47 * Is this path the empty string? 48 * Is this path the empty string?
48 */ 49 */
49 bool get isEmpty; 50 bool get isEmpty;
50 51
51 /** 52 /**
52 * Is this path an absolute path, beginning with a path separator? 53 * Is this path an absolute path, beginning with a path separator?
53 */ 54 */
54 bool get isAbsolute; 55 bool get isAbsolute;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 * 122 *
122 * On Windows, converts path separators to backwards slashes, and removes 123 * On Windows, converts path separators to backwards slashes, and removes
123 * the leading path separator if the path starts with a drive specification. 124 * the leading path separator if the path starts with a drive specification.
124 * For most valid Windows paths, this should be the inverse of the 125 * For most valid Windows paths, this should be the inverse of the
125 * constructor Path.fromNative. 126 * constructor Path.fromNative.
126 */ 127 */
127 String toNativePath(); 128 String toNativePath();
128 129
129 /** 130 /**
130 * Returns the path as a string. If this path is constructed using 131 * Returns the path as a string. If this path is constructed using
131 * new Path() or new Path.fromNative() on a non-Windows system, the 132 * new Path.raw(), or new Path() on a non-Windows system, the
132 * returned value is the original string argument to the constructor. 133 * returned value is the original string argument to the constructor.
133 */ 134 */
134 String toString(); 135 String toString();
135 136
136 /** 137 /**
137 * Gets the segments of a Path. Paths beginning or ending with the 138 * Gets the segments of a Path. Paths beginning or ending with the
138 * path separator do not have leading or terminating empty segments. 139 * path separator do not have leading or terminating empty segments.
139 * Other than that, the segments are just the result of splitting the 140 * Other than that, the segments are just the result of splitting the
140 * path on the path separator. 141 * path on the path separator.
141 * 142 *
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 189
189 /** 190 /**
190 * The part of [filename] after the last '.', or '' if [filename] 191 * The part of [filename] after the last '.', or '' if [filename]
191 * contains no '.'. If [filename] is '.' or '..', returns ''. 192 * contains no '.'. If [filename] is '.' or '..', returns ''.
192 * 193 *
193 * new Path('tiger.svg').extension == 'svg' 194 * new Path('tiger.svg').extension == 'svg'
194 * new Path('/src/dart/dart_secrets').extension == '' 195 * new Path('/src/dart/dart_secrets').extension == ''
195 */ 196 */
196 String get extension; 197 String get extension;
197 } 198 }
OLDNEW
« no previous file with comments | « sdk/lib/io/directory_impl.dart ('k') | sdk/lib/io/path_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698