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

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

Issue 296233002: Add a path.formatUri method and release path 1.2.0. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 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/CHANGELOG.md ('k') | pkg/path/lib/src/context.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/path/lib/path.dart
diff --git a/pkg/path/lib/path.dart b/pkg/path/lib/path.dart
index 524f16dc0115fdcd36f6e820265415df6d800602..599a351507326afcb6a34b2cfc2bdae5061d3c27 100644
--- a/pkg/path/lib/path.dart
+++ b/pkg/path/lib/path.dart
@@ -366,3 +366,26 @@ String fromUri(uri) => _context.fromUri(uri);
/// path.toUri('path/to/foo')
/// // -> Uri.parse('path/to/foo')
Uri toUri(String path) => _context.toUri(path);
+
+/// Returns a terse, human-readable representation of [uri].
+///
+/// [uri] can be a [String] or a [Uri]. If it can be made relative to the
+/// current working directory, that's done. Otherwise, it's returned as-is. This
+/// gracefully handles non-`file:` URIs for [Style.posix] and [Style.windows].
+///
+/// The returned value is meant for human consumption, and may be either URI-
+/// or path-formatted.
+///
+/// // POSIX at "/root/path"
+/// path.prettyUri('file:///root/path/a/b.dart'); // -> 'a/b.dart'
+/// path.prettyUri('http://dartlang.org/'); // -> 'http://dartlang.org'
+///
+/// // Windows at "C:\root\path"
+/// path.prettyUri('file:///C:/root/path/a/b.dart'); // -> r'a\b.dart'
+/// path.prettyUri('http://dartlang.org/'); // -> 'http://dartlang.org'
+///
+/// // URL at "http://dartlang.org/root/path"
+/// path.prettyUri('http://dartlang.org/root/path/a/b.dart');
+/// // -> r'a/b.dart'
+/// path.prettyUri('file:///root/path'); // -> 'file:///root/path'
+String prettyUri(uri) => _context.prettyUri(uri);
« no previous file with comments | « pkg/path/CHANGELOG.md ('k') | pkg/path/lib/src/context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698