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

Unified Diff: pkg/fasta/lib/src/translate_uri.dart

Issue 2634453004: Fasta infrastructure. (Closed)
Patch Set: Address review comments. Created 3 years, 11 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/fasta/lib/src/ticker.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/fasta/lib/src/translate_uri.dart
diff --git a/pkg/fasta/lib/src/translate_uri.dart b/pkg/fasta/lib/src/translate_uri.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6af35a9b7cc804f3ab817755e9330b41f262a38d
--- /dev/null
+++ b/pkg/fasta/lib/src/translate_uri.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2016, 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 fasta.translate_uri;
+
+import 'dart:async' show
+ Future;
+
+import 'dart:io' show
+ File;
+
+import 'package:package_config/packages_file.dart' as packages_file show
+ parse;
+
+import 'errors.dart' show
+ internalError;
+
+class TranslateUri {
+ final Map<String, Uri> packages;
+
+ TranslateUri(this.packages);
+
+ Uri translate(Uri uri) {
+ if (uri.scheme == "dart") return translateDartUri(uri);
+ if (uri.scheme == "package") return translatePackageUri(uri);
+ return null;
+ }
+
+ Uri translateDartUri(Uri uri) {
+ throw internalError("dart: URIs not implemented yet.");
+ }
+
+ Uri translatePackageUri(Uri uri) {
+ int index = uri.path.indexOf("/");
+ if (index == -1) return null;
+ String name = uri.path.substring(0, index);
+ String path = uri.path.substring(index + 1);
+ Uri root = packages[name];
+ if (root == null) return null;
+ return root.resolve(path);
+ }
+
+ static Future<TranslateUri> parse([Uri uri]) async {
+ uri ??= Uri.base.resolve(".packages");
+ File file = new File.fromUri(uri);
+ List<int> bytes = await file.readAsBytes();
+ Map<String, Uri> packages = packages_file.parse(bytes, uri);
+ return new TranslateUri(packages);
+ }
+}
« no previous file with comments | « pkg/fasta/lib/src/ticker.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698