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

Side by Side Diff: pkg/path/lib/path.dart

Issue 447773003: Make path's top-level context field public. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | « pkg/path/CHANGELOG.md ('k') | pkg/path/pubspec.yaml » ('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 /// A comprehensive, cross-platform path manipulation library. 5 /// A comprehensive, cross-platform path manipulation library.
6 /// 6 ///
7 /// ## Installing ## 7 /// ## Installing ##
8 /// 8 ///
9 /// Use [pub][] to install this package. Add the following to your 9 /// Use [pub][] to install this package. Add the following to your
10 /// `pubspec.yaml` file. 10 /// `pubspec.yaml` file.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 /// A default context for manipulating POSIX paths. 56 /// A default context for manipulating POSIX paths.
57 final posix = new Context(style: Style.posix); 57 final posix = new Context(style: Style.posix);
58 58
59 /// A default context for manipulating Windows paths. 59 /// A default context for manipulating Windows paths.
60 final windows = new Context(style: Style.windows); 60 final windows = new Context(style: Style.windows);
61 61
62 /// A default context for manipulating URLs. 62 /// A default context for manipulating URLs.
63 final url = new Context(style: Style.url); 63 final url = new Context(style: Style.url);
64 64
65 /// An internal context for the current OS so we can provide a straight 65 /// The system path context.
66 /// functional interface and not require users to create one. 66 ///
67 final Context _context = createInternal(); 67 /// This differs from a context created with [new Context] in that its
68 /// [Context.current] is always the current working directory, rather than being
69 /// set once when the context is created.
70 final Context context = createInternal();
68 71
69 /// Returns the [Style] of the current context. 72 /// Returns the [Style] of the current context.
70 /// 73 ///
71 /// This is the style that all top-level path functions will use. 74 /// This is the style that all top-level path functions will use.
72 Style get style => _context.style; 75 Style get style => context.style;
73 76
74 /// Gets the path to the current working directory. 77 /// Gets the path to the current working directory.
75 /// 78 ///
76 /// In the browser, this means the current URL, without the last file segment. 79 /// In the browser, this means the current URL, without the last file segment.
77 String get current { 80 String get current {
78 var uri = Uri.base; 81 var uri = Uri.base;
79 if (Style.platform == Style.url) { 82 if (Style.platform == Style.url) {
80 return uri.resolve('.').toString(); 83 return uri.resolve('.').toString();
81 } else { 84 } else {
82 var path = uri.toFilePath(); 85 var path = uri.toFilePath();
83 // Remove trailing '/' or '\'. 86 // Remove trailing '/' or '\'.
84 int lastIndex = path.length - 1; 87 int lastIndex = path.length - 1;
85 assert(path[lastIndex] == '/' || path[lastIndex] == '\\'); 88 assert(path[lastIndex] == '/' || path[lastIndex] == '\\');
86 return path.substring(0, lastIndex); 89 return path.substring(0, lastIndex);
87 } 90 }
88 } 91 }
89 92
90 /// Gets the path separator for the current platform. This is `\` on Windows 93 /// Gets the path separator for the current platform. This is `\` on Windows
91 /// and `/` on other platforms (including the browser). 94 /// and `/` on other platforms (including the browser).
92 String get separator => _context.separator; 95 String get separator => context.separator;
93 96
94 /// Creates a new path by appending the given path parts to [current]. 97 /// Creates a new path by appending the given path parts to [current].
95 /// Equivalent to [join()] with [current] as the first argument. Example: 98 /// Equivalent to [join()] with [current] as the first argument. Example:
96 /// 99 ///
97 /// path.absolute('path', 'to/foo'); // -> '/your/current/dir/path/to/foo' 100 /// path.absolute('path', 'to/foo'); // -> '/your/current/dir/path/to/foo'
98 String absolute(String part1, [String part2, String part3, String part4, 101 String absolute(String part1, [String part2, String part3, String part4,
99 String part5, String part6, String part7]) => 102 String part5, String part6, String part7]) =>
100 _context.absolute(part1, part2, part3, part4, part5, part6, part7); 103 context.absolute(part1, part2, part3, part4, part5, part6, part7);
101 104
102 /// Gets the part of [path] after the last separator. 105 /// Gets the part of [path] after the last separator.
103 /// 106 ///
104 /// path.basename('path/to/foo.dart'); // -> 'foo.dart' 107 /// path.basename('path/to/foo.dart'); // -> 'foo.dart'
105 /// path.basename('path/to'); // -> 'to' 108 /// path.basename('path/to'); // -> 'to'
106 /// 109 ///
107 /// Trailing separators are ignored. 110 /// Trailing separators are ignored.
108 /// 111 ///
109 /// path.basename('path/to/'); // -> 'to' 112 /// path.basename('path/to/'); // -> 'to'
110 String basename(String path) => _context.basename(path); 113 String basename(String path) => context.basename(path);
111 114
112 /// Gets the part of [path] after the last separator, and without any trailing 115 /// Gets the part of [path] after the last separator, and without any trailing
113 /// file extension. 116 /// file extension.
114 /// 117 ///
115 /// path.basenameWithoutExtension('path/to/foo.dart'); // -> 'foo' 118 /// path.basenameWithoutExtension('path/to/foo.dart'); // -> 'foo'
116 /// 119 ///
117 /// Trailing separators are ignored. 120 /// Trailing separators are ignored.
118 /// 121 ///
119 /// path.basenameWithoutExtension('path/to/foo.dart/'); // -> 'foo' 122 /// path.basenameWithoutExtension('path/to/foo.dart/'); // -> 'foo'
120 String basenameWithoutExtension(String path) => 123 String basenameWithoutExtension(String path) =>
121 _context.basenameWithoutExtension(path); 124 context.basenameWithoutExtension(path);
122 125
123 /// Gets the part of [path] before the last separator. 126 /// Gets the part of [path] before the last separator.
124 /// 127 ///
125 /// path.dirname('path/to/foo.dart'); // -> 'path/to' 128 /// path.dirname('path/to/foo.dart'); // -> 'path/to'
126 /// path.dirname('path/to'); // -> 'path' 129 /// path.dirname('path/to'); // -> 'path'
127 /// 130 ///
128 /// Trailing separators are ignored. 131 /// Trailing separators are ignored.
129 /// 132 ///
130 /// path.dirname('path/to/'); // -> 'path' 133 /// path.dirname('path/to/'); // -> 'path'
131 /// 134 ///
132 /// If an absolute path contains no directories, only a root, then the root 135 /// If an absolute path contains no directories, only a root, then the root
133 /// is returned. 136 /// is returned.
134 /// 137 ///
135 /// path.dirname('/'); // -> '/' (posix) 138 /// path.dirname('/'); // -> '/' (posix)
136 /// path.dirname('c:\'); // -> 'c:\' (windows) 139 /// path.dirname('c:\'); // -> 'c:\' (windows)
137 /// 140 ///
138 /// If a relative path has no directories, then '.' is returned. 141 /// If a relative path has no directories, then '.' is returned.
139 /// 142 ///
140 /// path.dirname('foo'); // -> '.' 143 /// path.dirname('foo'); // -> '.'
141 /// path.dirname(''); // -> '.' 144 /// path.dirname(''); // -> '.'
142 String dirname(String path) => _context.dirname(path); 145 String dirname(String path) => context.dirname(path);
143 146
144 /// Gets the file extension of [path]: the portion of [basename] from the last 147 /// Gets the file extension of [path]: the portion of [basename] from the last
145 /// `.` to the end (including the `.` itself). 148 /// `.` to the end (including the `.` itself).
146 /// 149 ///
147 /// path.extension('path/to/foo.dart'); // -> '.dart' 150 /// path.extension('path/to/foo.dart'); // -> '.dart'
148 /// path.extension('path/to/foo'); // -> '' 151 /// path.extension('path/to/foo'); // -> ''
149 /// path.extension('path.to/foo'); // -> '' 152 /// path.extension('path.to/foo'); // -> ''
150 /// path.extension('path/to/foo.dart.js'); // -> '.js' 153 /// path.extension('path/to/foo.dart.js'); // -> '.js'
151 /// 154 ///
152 /// If the file name starts with a `.`, then that is not considered the 155 /// If the file name starts with a `.`, then that is not considered the
153 /// extension: 156 /// extension:
154 /// 157 ///
155 /// path.extension('~/.bashrc'); // -> '' 158 /// path.extension('~/.bashrc'); // -> ''
156 /// path.extension('~/.notes.txt'); // -> '.txt' 159 /// path.extension('~/.notes.txt'); // -> '.txt'
157 String extension(String path) => _context.extension(path); 160 String extension(String path) => context.extension(path);
158 161
159 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. 162 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed.
160 /// Returns the root of [path], if it's absolute, or the empty string if it's 163 /// Returns the root of [path], if it's absolute, or the empty string if it's
161 /// relative. 164 /// relative.
162 /// 165 ///
163 /// // Unix 166 /// // Unix
164 /// path.rootPrefix('path/to/foo'); // -> '' 167 /// path.rootPrefix('path/to/foo'); // -> ''
165 /// path.rootPrefix('/path/to/foo'); // -> '/' 168 /// path.rootPrefix('/path/to/foo'); // -> '/'
166 /// 169 ///
167 /// // Windows 170 /// // Windows
168 /// path.rootPrefix(r'path\to\foo'); // -> '' 171 /// path.rootPrefix(r'path\to\foo'); // -> ''
169 /// path.rootPrefix(r'C:\path\to\foo'); // -> r'C:\' 172 /// path.rootPrefix(r'C:\path\to\foo'); // -> r'C:\'
170 /// 173 ///
171 /// // URL 174 /// // URL
172 /// path.rootPrefix('path/to/foo'); // -> '' 175 /// path.rootPrefix('path/to/foo'); // -> ''
173 /// path.rootPrefix('http://dartlang.org/path/to/foo'); 176 /// path.rootPrefix('http://dartlang.org/path/to/foo');
174 /// // -> 'http://dartlang.org' 177 /// // -> 'http://dartlang.org'
175 String rootPrefix(String path) => _context.rootPrefix(path); 178 String rootPrefix(String path) => context.rootPrefix(path);
176 179
177 /// Returns `true` if [path] is an absolute path and `false` if it is a 180 /// Returns `true` if [path] is an absolute path and `false` if it is a
178 /// relative path. 181 /// relative path.
179 /// 182 ///
180 /// On POSIX systems, absolute paths start with a `/` (forward slash). On 183 /// On POSIX systems, absolute paths start with a `/` (forward slash). On
181 /// Windows, an absolute path starts with `\\`, or a drive letter followed by 184 /// Windows, an absolute path starts with `\\`, or a drive letter followed by
182 /// `:/` or `:\`. For URLs, absolute paths either start with a protocol and 185 /// `:/` or `:\`. For URLs, absolute paths either start with a protocol and
183 /// optional hostname (e.g. `http://dartlang.org`, `file://`) or with a `/`. 186 /// optional hostname (e.g. `http://dartlang.org`, `file://`) or with a `/`.
184 /// 187 ///
185 /// URLs that start with `/` are known as "root-relative", since they're 188 /// URLs that start with `/` are known as "root-relative", since they're
186 /// relative to the root of the current URL. Since root-relative paths are still 189 /// relative to the root of the current URL. Since root-relative paths are still
187 /// absolute in every other sense, [isAbsolute] will return true for them. They 190 /// absolute in every other sense, [isAbsolute] will return true for them. They
188 /// can be detected using [isRootRelative]. 191 /// can be detected using [isRootRelative].
189 bool isAbsolute(String path) => _context.isAbsolute(path); 192 bool isAbsolute(String path) => context.isAbsolute(path);
190 193
191 /// Returns `true` if [path] is a relative path and `false` if it is absolute. 194 /// Returns `true` if [path] is a relative path and `false` if it is absolute.
192 /// On POSIX systems, absolute paths start with a `/` (forward slash). On 195 /// On POSIX systems, absolute paths start with a `/` (forward slash). On
193 /// Windows, an absolute path starts with `\\`, or a drive letter followed by 196 /// Windows, an absolute path starts with `\\`, or a drive letter followed by
194 /// `:/` or `:\`. 197 /// `:/` or `:\`.
195 bool isRelative(String path) => _context.isRelative(path); 198 bool isRelative(String path) => context.isRelative(path);
196 199
197 /// Returns `true` if [path] is a root-relative path and `false` if it's not. 200 /// Returns `true` if [path] is a root-relative path and `false` if it's not.
198 /// 201 ///
199 /// URLs that start with `/` are known as "root-relative", since they're 202 /// URLs that start with `/` are known as "root-relative", since they're
200 /// relative to the root of the current URL. Since root-relative paths are still 203 /// relative to the root of the current URL. Since root-relative paths are still
201 /// absolute in every other sense, [isAbsolute] will return true for them. They 204 /// absolute in every other sense, [isAbsolute] will return true for them. They
202 /// can be detected using [isRootRelative]. 205 /// can be detected using [isRootRelative].
203 /// 206 ///
204 /// No POSIX and Windows paths are root-relative. 207 /// No POSIX and Windows paths are root-relative.
205 bool isRootRelative(String path) => _context.isRootRelative(path); 208 bool isRootRelative(String path) => context.isRootRelative(path);
206 209
207 /// Joins the given path parts into a single path using the current platform's 210 /// Joins the given path parts into a single path using the current platform's
208 /// [separator]. Example: 211 /// [separator]. Example:
209 /// 212 ///
210 /// path.join('path', 'to', 'foo'); // -> 'path/to/foo' 213 /// path.join('path', 'to', 'foo'); // -> 'path/to/foo'
211 /// 214 ///
212 /// If any part ends in a path separator, then a redundant separator will not 215 /// If any part ends in a path separator, then a redundant separator will not
213 /// be added: 216 /// be added:
214 /// 217 ///
215 /// path.join('path/', 'to', 'foo'); // -> 'path/to/foo 218 /// path.join('path/', 'to', 'foo'); // -> 'path/to/foo
216 /// 219 ///
217 /// If a part is an absolute path, then anything before that will be ignored: 220 /// If a part is an absolute path, then anything before that will be ignored:
218 /// 221 ///
219 /// path.join('path', '/to', 'foo'); // -> '/to/foo' 222 /// path.join('path', '/to', 'foo'); // -> '/to/foo'
220 String join(String part1, [String part2, String part3, String part4, 223 String join(String part1, [String part2, String part3, String part4,
221 String part5, String part6, String part7, String part8]) => 224 String part5, String part6, String part7, String part8]) =>
222 _context.join(part1, part2, part3, part4, part5, part6, part7, part8); 225 context.join(part1, part2, part3, part4, part5, part6, part7, part8);
223 226
224 /// Joins the given path parts into a single path using the current platform's 227 /// Joins the given path parts into a single path using the current platform's
225 /// [separator]. Example: 228 /// [separator]. Example:
226 /// 229 ///
227 /// path.joinAll(['path', 'to', 'foo']); // -> 'path/to/foo' 230 /// path.joinAll(['path', 'to', 'foo']); // -> 'path/to/foo'
228 /// 231 ///
229 /// If any part ends in a path separator, then a redundant separator will not 232 /// If any part ends in a path separator, then a redundant separator will not
230 /// be added: 233 /// be added:
231 /// 234 ///
232 /// path.joinAll(['path/', 'to', 'foo']); // -> 'path/to/foo 235 /// path.joinAll(['path/', 'to', 'foo']); // -> 'path/to/foo
233 /// 236 ///
234 /// If a part is an absolute path, then anything before that will be ignored: 237 /// If a part is an absolute path, then anything before that will be ignored:
235 /// 238 ///
236 /// path.joinAll(['path', '/to', 'foo']); // -> '/to/foo' 239 /// path.joinAll(['path', '/to', 'foo']); // -> '/to/foo'
237 /// 240 ///
238 /// For a fixed number of parts, [join] is usually terser. 241 /// For a fixed number of parts, [join] is usually terser.
239 String joinAll(Iterable<String> parts) => _context.joinAll(parts); 242 String joinAll(Iterable<String> parts) => context.joinAll(parts);
240 243
241 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. 244 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed.
242 /// Splits [path] into its components using the current platform's [separator]. 245 /// Splits [path] into its components using the current platform's [separator].
243 /// 246 ///
244 /// path.split('path/to/foo'); // -> ['path', 'to', 'foo'] 247 /// path.split('path/to/foo'); // -> ['path', 'to', 'foo']
245 /// 248 ///
246 /// The path will *not* be normalized before splitting. 249 /// The path will *not* be normalized before splitting.
247 /// 250 ///
248 /// path.split('path/../foo'); // -> ['path', '..', 'foo'] 251 /// path.split('path/../foo'); // -> ['path', '..', 'foo']
249 /// 252 ///
250 /// If [path] is absolute, the root directory will be the first element in the 253 /// If [path] is absolute, the root directory will be the first element in the
251 /// array. Example: 254 /// array. Example:
252 /// 255 ///
253 /// // Unix 256 /// // Unix
254 /// path.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo'] 257 /// path.split('/path/to/foo'); // -> ['/', 'path', 'to', 'foo']
255 /// 258 ///
256 /// // Windows 259 /// // Windows
257 /// path.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo'] 260 /// path.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo']
258 /// 261 ///
259 /// // Browser 262 /// // Browser
260 /// path.split('http://dartlang.org/path/to/foo'); 263 /// path.split('http://dartlang.org/path/to/foo');
261 /// // -> ['http://dartlang.org', 'path', 'to', 'foo'] 264 /// // -> ['http://dartlang.org', 'path', 'to', 'foo']
262 List<String> split(String path) => _context.split(path); 265 List<String> split(String path) => context.split(path);
263 266
264 /// Normalizes [path], simplifying it by handling `..`, and `.`, and 267 /// Normalizes [path], simplifying it by handling `..`, and `.`, and
265 /// removing redundant path separators whenever possible. 268 /// removing redundant path separators whenever possible.
266 /// 269 ///
267 /// path.normalize('path/./to/..//file.text'); // -> 'path/file.txt' 270 /// path.normalize('path/./to/..//file.text'); // -> 'path/file.txt'
268 String normalize(String path) => _context.normalize(path); 271 String normalize(String path) => context.normalize(path);
269 272
270 /// Attempts to convert [path] to an equivalent relative path from the current 273 /// Attempts to convert [path] to an equivalent relative path from the current
271 /// directory. 274 /// directory.
272 /// 275 ///
273 /// // Given current directory is /root/path: 276 /// // Given current directory is /root/path:
274 /// path.relative('/root/path/a/b.dart'); // -> 'a/b.dart' 277 /// path.relative('/root/path/a/b.dart'); // -> 'a/b.dart'
275 /// path.relative('/root/other.dart'); // -> '../other.dart' 278 /// path.relative('/root/other.dart'); // -> '../other.dart'
276 /// 279 ///
277 /// If the [from] argument is passed, [path] is made relative to that instead. 280 /// If the [from] argument is passed, [path] is made relative to that instead.
278 /// 281 ///
279 /// path.relative('/root/path/a/b.dart', 282 /// path.relative('/root/path/a/b.dart',
280 /// from: '/root/path'); // -> 'a/b.dart' 283 /// from: '/root/path'); // -> 'a/b.dart'
281 /// path.relative('/root/other.dart', 284 /// path.relative('/root/other.dart',
282 /// from: '/root/path'); // -> '../other.dart' 285 /// from: '/root/path'); // -> '../other.dart'
283 /// 286 ///
284 /// If [path] and/or [from] are relative paths, they are assumed to be relative 287 /// If [path] and/or [from] are relative paths, they are assumed to be relative
285 /// to the current directory. 288 /// to the current directory.
286 /// 289 ///
287 /// Since there is no relative path from one drive letter to another on Windows, 290 /// Since there is no relative path from one drive letter to another on Windows,
288 /// or from one hostname to another for URLs, this will return an absolute path 291 /// or from one hostname to another for URLs, this will return an absolute path
289 /// in those cases. 292 /// in those cases.
290 /// 293 ///
291 /// // Windows 294 /// // Windows
292 /// path.relative(r'D:\other', from: r'C:\home'); // -> 'D:\other' 295 /// path.relative(r'D:\other', from: r'C:\home'); // -> 'D:\other'
293 /// 296 ///
294 /// // URL 297 /// // URL
295 /// path.relative('http://dartlang.org', from: 'http://pub.dartlang.org'); 298 /// path.relative('http://dartlang.org', from: 'http://pub.dartlang.org');
296 /// // -> 'http://dartlang.org' 299 /// // -> 'http://dartlang.org'
297 String relative(String path, {String from}) => 300 String relative(String path, {String from}) =>
298 _context.relative(path, from: from); 301 context.relative(path, from: from);
299 302
300 /// Returns `true` if [child] is a path beneath `parent`, and `false` otherwise. 303 /// Returns `true` if [child] is a path beneath `parent`, and `false` otherwise.
301 /// 304 ///
302 /// path.isWithin('/root/path', '/root/path/a'); // -> true 305 /// path.isWithin('/root/path', '/root/path/a'); // -> true
303 /// path.isWithin('/root/path', '/root/other'); // -> false 306 /// path.isWithin('/root/path', '/root/other'); // -> false
304 /// path.isWithin('/root/path', '/root/path') // -> false 307 /// path.isWithin('/root/path', '/root/path') // -> false
305 bool isWithin(String parent, String child) => _context.isWithin(parent, child); 308 bool isWithin(String parent, String child) => context.isWithin(parent, child);
306 309
307 /// Removes a trailing extension from the last part of [path]. 310 /// Removes a trailing extension from the last part of [path].
308 /// 311 ///
309 /// withoutExtension('path/to/foo.dart'); // -> 'path/to/foo' 312 /// withoutExtension('path/to/foo.dart'); // -> 'path/to/foo'
310 String withoutExtension(String path) => _context.withoutExtension(path); 313 String withoutExtension(String path) => context.withoutExtension(path);
311 314
312 /// Returns the path represented by [uri], which may be a [String] or a [Uri]. 315 /// Returns the path represented by [uri], which may be a [String] or a [Uri].
313 /// 316 ///
314 /// For POSIX and Windows styles, [uri] must be a `file:` URI. For the URL 317 /// For POSIX and Windows styles, [uri] must be a `file:` URI. For the URL
315 /// style, this will just convert [uri] to a string. 318 /// style, this will just convert [uri] to a string.
316 /// 319 ///
317 /// // POSIX 320 /// // POSIX
318 /// context.fromUri('file:///path/to/foo') 321 /// context.fromUri('file:///path/to/foo')
319 /// // -> '/path/to/foo' 322 /// // -> '/path/to/foo'
320 /// 323 ///
321 /// // Windows 324 /// // Windows
322 /// context.fromUri('file:///C:/path/to/foo') 325 /// context.fromUri('file:///C:/path/to/foo')
323 /// // -> r'C:\path\to\foo' 326 /// // -> r'C:\path\to\foo'
324 /// 327 ///
325 /// // URL 328 /// // URL
326 /// context.fromUri('http://dartlang.org/path/to/foo') 329 /// context.fromUri('http://dartlang.org/path/to/foo')
327 /// // -> 'http://dartlang.org/path/to/foo' 330 /// // -> 'http://dartlang.org/path/to/foo'
328 /// 331 ///
329 /// If [uri] is relative, a relative path will be returned. 332 /// If [uri] is relative, a relative path will be returned.
330 /// 333 ///
331 /// path.fromUri('path/to/foo'); // -> 'path/to/foo' 334 /// path.fromUri('path/to/foo'); // -> 'path/to/foo'
332 String fromUri(uri) => _context.fromUri(uri); 335 String fromUri(uri) => context.fromUri(uri);
333 336
334 /// Returns the URI that represents [path]. 337 /// Returns the URI that represents [path].
335 /// 338 ///
336 /// For POSIX and Windows styles, this will return a `file:` URI. For the URL 339 /// For POSIX and Windows styles, this will return a `file:` URI. For the URL
337 /// style, this will just convert [path] to a [Uri]. 340 /// style, this will just convert [path] to a [Uri].
338 /// 341 ///
339 /// // POSIX 342 /// // POSIX
340 /// path.toUri('/path/to/foo') 343 /// path.toUri('/path/to/foo')
341 /// // -> Uri.parse('file:///path/to/foo') 344 /// // -> Uri.parse('file:///path/to/foo')
342 /// 345 ///
343 /// // Windows 346 /// // Windows
344 /// path.toUri(r'C:\path\to\foo') 347 /// path.toUri(r'C:\path\to\foo')
345 /// // -> Uri.parse('file:///C:/path/to/foo') 348 /// // -> Uri.parse('file:///C:/path/to/foo')
346 /// 349 ///
347 /// // URL 350 /// // URL
348 /// path.toUri('http://dartlang.org/path/to/foo') 351 /// path.toUri('http://dartlang.org/path/to/foo')
349 /// // -> Uri.parse('http://dartlang.org/path/to/foo') 352 /// // -> Uri.parse('http://dartlang.org/path/to/foo')
350 /// 353 ///
351 /// If [path] is relative, a relative URI will be returned. 354 /// If [path] is relative, a relative URI will be returned.
352 /// 355 ///
353 /// path.toUri('path/to/foo') 356 /// path.toUri('path/to/foo')
354 /// // -> Uri.parse('path/to/foo') 357 /// // -> Uri.parse('path/to/foo')
355 Uri toUri(String path) => _context.toUri(path); 358 Uri toUri(String path) => context.toUri(path);
356 359
357 /// Returns a terse, human-readable representation of [uri]. 360 /// Returns a terse, human-readable representation of [uri].
358 /// 361 ///
359 /// [uri] can be a [String] or a [Uri]. If it can be made relative to the 362 /// [uri] can be a [String] or a [Uri]. If it can be made relative to the
360 /// current working directory, that's done. Otherwise, it's returned as-is. This 363 /// current working directory, that's done. Otherwise, it's returned as-is. This
361 /// gracefully handles non-`file:` URIs for [Style.posix] and [Style.windows]. 364 /// gracefully handles non-`file:` URIs for [Style.posix] and [Style.windows].
362 /// 365 ///
363 /// The returned value is meant for human consumption, and may be either URI- 366 /// The returned value is meant for human consumption, and may be either URI-
364 /// or path-formatted. 367 /// or path-formatted.
365 /// 368 ///
366 /// // POSIX at "/root/path" 369 /// // POSIX at "/root/path"
367 /// path.prettyUri('file:///root/path/a/b.dart'); // -> 'a/b.dart' 370 /// path.prettyUri('file:///root/path/a/b.dart'); // -> 'a/b.dart'
368 /// path.prettyUri('http://dartlang.org/'); // -> 'http://dartlang.org' 371 /// path.prettyUri('http://dartlang.org/'); // -> 'http://dartlang.org'
369 /// 372 ///
370 /// // Windows at "C:\root\path" 373 /// // Windows at "C:\root\path"
371 /// path.prettyUri('file:///C:/root/path/a/b.dart'); // -> r'a\b.dart' 374 /// path.prettyUri('file:///C:/root/path/a/b.dart'); // -> r'a\b.dart'
372 /// path.prettyUri('http://dartlang.org/'); // -> 'http://dartlang.org' 375 /// path.prettyUri('http://dartlang.org/'); // -> 'http://dartlang.org'
373 /// 376 ///
374 /// // URL at "http://dartlang.org/root/path" 377 /// // URL at "http://dartlang.org/root/path"
375 /// path.prettyUri('http://dartlang.org/root/path/a/b.dart'); 378 /// path.prettyUri('http://dartlang.org/root/path/a/b.dart');
376 /// // -> r'a/b.dart' 379 /// // -> r'a/b.dart'
377 /// path.prettyUri('file:///root/path'); // -> 'file:///root/path' 380 /// path.prettyUri('file:///root/path'); // -> 'file:///root/path'
378 String prettyUri(uri) => _context.prettyUri(uri); 381 String prettyUri(uri) => context.prettyUri(uri);
OLDNEW
« no previous file with comments | « pkg/path/CHANGELOG.md ('k') | pkg/path/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698