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

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

Issue 16854005: First pass at build dependency graph for barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 /// path.relative('/root/other.dart', 196 /// path.relative('/root/other.dart',
197 /// from: '/root/path'); // -> '../other.dart' 197 /// from: '/root/path'); // -> '../other.dart'
198 /// 198 ///
199 /// Since there is no relative path from one drive letter to another on Windows, 199 /// Since there is no relative path from one drive letter to another on Windows,
200 /// this will return an absolute path in that case. 200 /// this will return an absolute path in that case.
201 /// 201 ///
202 /// path.relative(r'D:\other', from: r'C:\home'); // -> 'D:\other' 202 /// path.relative(r'D:\other', from: r'C:\home'); // -> 'D:\other'
203 String relative(String path, {String from}) => 203 String relative(String path, {String from}) =>
204 _builder.relative(path, from: from); 204 _builder.relative(path, from: from);
205 205
206 /// Returns whether or not [path] is nested somewhere within [dir].
207 ///
208 /// path.isWithin('a/b/c.dart', 'a/b') // -> true
209 /// path.isWithin('a/b/c.dart', 'd/b') // -> false
210 bool isWithin(String path, String dir) => _builder.isWithin(path, dir);
211
206 /// Removes a trailing extension from the last part of [path]. 212 /// Removes a trailing extension from the last part of [path].
207 /// 213 ///
208 /// withoutExtension('path/to/foo.dart'); // -> 'path/to/foo' 214 /// withoutExtension('path/to/foo.dart'); // -> 'path/to/foo'
209 String withoutExtension(String path) => _builder.withoutExtension(path); 215 String withoutExtension(String path) => _builder.withoutExtension(path);
210 216
211 /// Validates that there are no non-null arguments following a null one and 217 /// Validates that there are no non-null arguments following a null one and
212 /// throws an appropriate [ArgumentError] on failure. 218 /// throws an appropriate [ArgumentError] on failure.
213 _validateArgList(String method, List<String> args) { 219 _validateArgList(String method, List<String> args) {
214 for (var i = 1; i < args.length; i++) { 220 for (var i = 1; i < args.length; i++) {
215 // Ignore nulls hanging off the end. 221 // Ignore nulls hanging off the end.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 /// Returns `true` if [path] is an absolute path and `false` if it is a 348 /// Returns `true` if [path] is an absolute path and `false` if it is a
343 /// relative path. On POSIX systems, absolute paths start with a `/` (forward 349 /// relative path. On POSIX systems, absolute paths start with a `/` (forward
344 /// slash). On Windows, an absolute path starts with `\\`, or a drive letter 350 /// slash). On Windows, an absolute path starts with `\\`, or a drive letter
345 /// followed by `:/` or `:\`. 351 /// followed by `:/` or `:\`.
346 bool isAbsolute(String path) => _parse(path).isAbsolute; 352 bool isAbsolute(String path) => _parse(path).isAbsolute;
347 353
348 /// Returns `true` if [path] is a relative path and `false` if it is absolute. 354 /// Returns `true` if [path] is a relative path and `false` if it is absolute.
349 /// On POSIX systems, absolute paths start with a `/` (forward slash). On 355 /// On POSIX systems, absolute paths start with a `/` (forward slash). On
350 /// Windows, an absolute path starts with `\\`, or a drive letter followed by 356 /// Windows, an absolute path starts with `\\`, or a drive letter followed by
351 /// `:/` or `:\`. 357 /// `:/` or `:\`.
352 bool isRelative(String path) => !isAbsolute(path); 358 bool isRelative(String path) => !this.isAbsolute(path);
359
360 /// Returns whether or not [path] is nested somewhere within [dir].
361 ///
362 /// path.isWithin('a/b/c.dart', 'a/b') // -> true
363 /// path.isWithin('a/b/c.dart', 'd/b') // -> false
364 bool isWithin(String path, String dir) {
365 var relative = this.relative(path, from: dir);
366 return !this.isAbsolute(relative) && this.split(relative)[0] != '..';
367 }
353 368
354 /// Joins the given path parts into a single path. Example: 369 /// Joins the given path parts into a single path. Example:
355 /// 370 ///
356 /// builder.join('path', 'to', 'foo'); // -> 'path/to/foo' 371 /// builder.join('path', 'to', 'foo'); // -> 'path/to/foo'
357 /// 372 ///
358 /// If any part ends in a path separator, then a redundant separator will not 373 /// If any part ends in a path separator, then a redundant separator will not
359 /// be added: 374 /// be added:
360 /// 375 ///
361 /// builder.join('path/', 'to', 'foo'); // -> 'path/to/foo 376 /// builder.join('path/', 'to', 'foo'); // -> 'path/to/foo
362 /// 377 ///
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 // If there is no dot, or it's the first character, like '.bashrc', it 768 // If there is no dot, or it's the first character, like '.bashrc', it
754 // doesn't count. 769 // doesn't count.
755 if (lastDot <= 0) return [file, '']; 770 if (lastDot <= 0) return [file, ''];
756 771
757 return [file.substring(0, lastDot), file.substring(lastDot)]; 772 return [file.substring(0, lastDot), file.substring(lastDot)];
758 } 773 }
759 774
760 _ParsedPath clone() => new _ParsedPath( 775 _ParsedPath clone() => new _ParsedPath(
761 style, root, new List.from(parts), new List.from(separators)); 776 style, root, new List.from(parts), new List.from(separators));
762 } 777 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698