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

Unified Diff: utils/pub/path.dart

Issue 11557008: Make pub publish more user friendly: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Blacklist '.DS_Store' files from publish. Created 8 years 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: utils/pub/path.dart
diff --git a/utils/pub/path.dart b/utils/pub/path.dart
index d803fd17075726750cd3c559d4731ff6478af52b..8f9f9a49b89afa9d5e879ec796ced39ff738d5b9 100644
--- a/utils/pub/path.dart
+++ b/utils/pub/path.dart
@@ -110,6 +110,19 @@ String normalize(String path) => _builder.normalize(path);
/// path.relative(r'D:\other'); // -> 'D:\other'
String relative(String path) => _builder.relative(path);
+/// Splits [path] along separators and returns a [List] of the parts. The
+/// path will *not* be normalized before splitting.
+///
+/// path.split('a/b/c.txt'); // -> ['a', 'b', 'c.txt']
+/// path.split('a/../c'); // -> ['a', '..', 'c']
+///
+/// If [path] is absolute, the root prefix will be included in the first
+/// part.
+///
+/// path.split('/a/b/c.txt'); // -> ['/a', 'b', 'c.txt']
+/// path.split(r'C:\a\b\c.txt'); // -> [r'C:\a', 'b', 'c.txt']
+List<String> split(String path) => _builder.split(path);
nweiz 2012/12/12 21:21:21 I assume this'll be replaced by my implementation.
Bob Nystrom 2012/12/12 21:45:36 Yup.
+
/// Removes a trailing extension from the last part of [path].
///
/// withoutExtension('path/to/foo.dart'); // -> 'path/to/foo'
@@ -329,6 +342,29 @@ class Builder {
return pathParsed.toString();
}
+ /// Splits [path] along separators and returns a [List] of the parts. The
+ /// path will *not* be normalized before splitting.
+ ///
+ /// builder.split('a/b/c.txt'); // -> ['a', 'b', 'c.txt']
+ /// builder.split('a/../c'); // -> ['a', '..', 'c']
+ ///
+ /// If [path] is absolute, the root prefix will be included in the first
+ /// part.
+ ///
+ /// builder.split('/a/b/c.txt'); // -> ['/a', 'b', 'c.txt']
+ /// builder.split(r'C:\a\b\c.txt'); // -> [r'C:\a', 'b', 'c.txt']
+ List<String> split(String path) {
+ var parsed = _parse(path);
+
+ // Include the root prefix in the first part.
+ if (parsed.root != null) {
+ if (parsed.parts.isEmpty) return [parsed.root];
+ parsed.parts[0] = '${parsed.root}${parsed.parts[0]}';
+ }
+
+ return parsed.parts.filter(((part) => part != ''));
+ }
+
/// Removes a trailing extension from the last part of [path].
///
/// builder.withoutExtension('path/to/foo.dart'); // -> 'path/to/foo'

Powered by Google App Engine
This is Rietveld 408576698