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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/pathos/lib/path.dart
diff --git a/pkg/pathos/lib/path.dart b/pkg/pathos/lib/path.dart
index 80ffe72a57da05881db73e521e0753a0788d560b..b9c2936ecc2efb73a8d7188f4330cff5eee79768 100644
--- a/pkg/pathos/lib/path.dart
+++ b/pkg/pathos/lib/path.dart
@@ -203,6 +203,12 @@ String normalize(String path) => _builder.normalize(path);
String relative(String path, {String from}) =>
_builder.relative(path, from: from);
+/// Returns whether or not [path] is nested somewhere within [dir].
+///
+/// path.isWithin('a/b/c.dart', 'a/b') // -> true
+/// path.isWithin('a/b/c.dart', 'd/b') // -> false
+bool isWithin(String path, String dir) => _builder.isWithin(path, dir);
+
/// Removes a trailing extension from the last part of [path].
///
/// withoutExtension('path/to/foo.dart'); // -> 'path/to/foo'
@@ -349,7 +355,16 @@ class Builder {
/// On POSIX systems, absolute paths start with a `/` (forward slash). On
/// Windows, an absolute path starts with `\\`, or a drive letter followed by
/// `:/` or `:\`.
- bool isRelative(String path) => !isAbsolute(path);
+ bool isRelative(String path) => !this.isAbsolute(path);
+
+ /// Returns whether or not [path] is nested somewhere within [dir].
+ ///
+ /// path.isWithin('a/b/c.dart', 'a/b') // -> true
+ /// path.isWithin('a/b/c.dart', 'd/b') // -> false
+ bool isWithin(String path, String dir) {
+ var relative = this.relative(path, from: dir);
+ return !this.isAbsolute(relative) && this.split(relative)[0] != '..';
+ }
/// Joins the given path parts into a single path. Example:
///

Powered by Google App Engine
This is Rietveld 408576698