Skip to content
Snippets Groups Projects
Commit 871b460e authored by nweiz@google.com's avatar nweiz@google.com Committed by Natalie Weizenbaum
Browse files

Add toUri and fromUri functions to pathos.

This also replaces the ubiqutous pathToFileUri/fileUriToPath functions.

R=rnystrom@google.com

Review URL: https://codereview.chromium.org//16848002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@24196 260f80e4-7a28-3924-810f-c04153c831b5
parent 3386bf17
No related branches found
No related tags found
No related merge requests found
......@@ -41,9 +41,9 @@ Future<String> compile(String entrypoint, {String packageRoot,
}
return compiler.compile(
pathToFileUri(entrypoint),
pathToFileUri(appendSlash(_libPath)),
pathToFileUri(appendSlash(packageRoot)),
path.toUri(entrypoint),
path.toUri(appendSlash(_libPath)),
path.toUri(appendSlash(packageRoot)),
provider.readStringFromUri,
new FormattingDiagnosticHandler(provider).diagnosticHandler,
options);
......
......@@ -376,37 +376,7 @@ Future awaitObject(object) {
/// be globally unique, or the wrong library path may be returned.
String libraryPath(String libraryName) {
var libraries = currentMirrorSystem().findLibrary(new Symbol(libraryName));
return fileUriToPath(libraries.single.uri);
}
/// Converts a `file:` [Uri] to a local path string.
String fileUriToPath(Uri uri) {
if (uri.scheme != 'file') {
throw new ArgumentError("Uri $uri must have scheme 'file:'.");
}
if (Platform.operatingSystem != 'windows') return uri.path;
if (uri.path.startsWith("/")) {
// Drive-letter paths look like "file:///C:/path/to/file". The replaceFirst
// removes the extra initial slash.
return uri.path.replaceFirst("/", "").replaceAll("/", "\\");
} else {
// Network paths look like "file://hostname/path/to/file".
return "\\\\${uri.path.replaceAll("/", "\\")}";
}
}
/// Converts a local path string to a `file:` [Uri].
Uri pathToFileUri(String pathString) {
pathString = path.absolute(pathString);
if (Platform.operatingSystem != 'windows') {
return Uri.parse('file://$pathString');
} else if (path.rootPrefix(pathString).startsWith('\\\\')) {
// Network paths become "file://hostname/path/to/file".
return Uri.parse('file:${pathString.replaceAll("\\", "/")}');
} else {
// Drive-letter paths become "file:///C:/path/to/file".
return Uri.parse('file:///${pathString.replaceAll("\\", "/")}');
}
return path.fromUri(libraries.single.uri);
}
/// Gets a "special" string (ANSI escape or Unicode). On Windows, returns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment