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

Unified Diff: pkg/path/lib/src/style/posix.dart

Issue 62753005: Refactor pkg/path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 7 years, 1 month 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/style.dart ('k') | pkg/path/lib/src/style/url.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/path/lib/src/style/posix.dart
diff --git a/pkg/path/lib/src/style/posix.dart b/pkg/path/lib/src/style/posix.dart
new file mode 100644
index 0000000000000000000000000000000000000000..72e70441a7d37746f5b41e7bd7b82d9b96c711be
--- /dev/null
+++ b/pkg/path/lib/src/style/posix.dart
@@ -0,0 +1,42 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library path.style.posix;
+
+import '../parsed_path.dart';
+import '../style.dart';
+
+/// The style for POSIX paths.
+class PosixStyle extends Style {
+ PosixStyle();
+
+ final name = 'posix';
+ final separator = '/';
+ final separatorPattern = new RegExp(r'/');
+ final needsSeparatorPattern = new RegExp(r'[^/]$');
+ final rootPattern = new RegExp(r'^/');
+
+ String pathFromUri(Uri uri) {
+ if (uri.scheme == '' || uri.scheme == 'file') {
+ return Uri.decodeComponent(uri.path);
+ }
+ throw new ArgumentError("Uri $uri must have scheme 'file:'.");
+ }
+
+ Uri absolutePathToUri(String path) {
+ var parsed = new ParsedPath.parse(path, this);
+ if (parsed.parts.isEmpty) {
+ // If the path is a bare root (e.g. "/"), [components] will
+ // currently be empty. We add two empty components so the URL constructor
+ // produces "file:///", with a trailing slash.
+ parsed.parts.addAll(["", ""]);
+ } else if (parsed.hasTrailingSeparator) {
+ // If the path has a trailing slash, add a single empty component so the
+ // URI has a trailing slash as well.
+ parsed.parts.add("");
+ }
+
+ return new Uri(scheme: 'file', pathSegments: parsed.parts);
+ }
+}
« no previous file with comments | « pkg/path/lib/src/style.dart ('k') | pkg/path/lib/src/style/url.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698