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

Unified Diff: pkg/path/lib/src/internal_style.dart

Issue 439223002: Add InternalStyle:rootLength to implement isAbsolute and rootPrefix. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add windows test to 'document' \\server root prefix. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/path/lib/src/context.dart ('k') | pkg/path/lib/src/parsed_path.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/path/lib/src/internal_style.dart
diff --git a/pkg/path/lib/src/internal_style.dart b/pkg/path/lib/src/internal_style.dart
index 67b5d343eb748a40f868c4536df7d27b3262b6df..db2d3462d24afc66bda6ab3209e6a123efe0e86c 100644
--- a/pkg/path/lib/src/internal_style.dart
+++ b/pkg/path/lib/src/internal_style.dart
@@ -33,14 +33,25 @@ abstract class InternalStyle extends Style {
/// "usr", an additional "/" is needed (making "file:///usr").
bool needsSeparator(String path);
+ /// Returns the number of characters of the root part.
+ ///
+ /// Returns 0 if the path is relative.
+ ///
+ /// If the path is root-relative, the root length is 1.
+ int rootLength(String path);
+
/// Gets the root prefix of [path] if path is absolute. If [path] is relative,
/// returns `null`.
- String getRoot(String path);
+ String getRoot(String path) {
+ var length = rootLength(path);
+ if (length > 0) return path.substring(0, length);
+ return isRootRelative(path) ? path[0] : null;
+ }
- /// Gets the root prefix of [path] if it's root-relative.
+ /// Returns whether [path] is root-relative.
///
- /// If [path] is relative or absolute and not root-relative, returns `null`.
- String getRelativeRoot(String path);
+ /// If [path] is relative or absolute and not root-relative, returns `false`.
+ bool isRootRelative(String path);
/// Returns the path represented by [uri] in this style.
String pathFromUri(Uri uri);
« no previous file with comments | « pkg/path/lib/src/context.dart ('k') | pkg/path/lib/src/parsed_path.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698