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/dart/pkg/stack_trace@24196 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pkgs/stack_trace/lib/src/frame.dart b/pkgs/stack_trace/lib/src/frame.dart
index 8f1931b..8d3f042 100644
--- a/pkgs/stack_trace/lib/src/frame.dart
+++ b/pkgs/stack_trace/lib/src/frame.dart
@@ -8,7 +8,6 @@
 import 'package:pathos/path.dart' as path;
 
 import 'trace.dart';
-import 'utils.dart';
 
 final _nativeFrameRegExp = new RegExp(
     r'^#\d+\s+([^\s].*) \((.+):(\d+):(\d+)\)$');
@@ -46,9 +45,8 @@
   /// This will usually be the string form of [uri], but a relative path will be
   /// used if possible.
   String get library {
-    // TODO(nweiz): handle relative URIs here as well once pathos supports that.
     if (uri.scheme != 'file') return uri.toString();
-    return path.relative(fileUriToPath(uri));
+    return path.relative(path.fromUri(uri));
   }
 
   /// Returns the name of the package this stack frame comes from, or `null` if
diff --git a/pkgs/stack_trace/lib/src/utils.dart b/pkgs/stack_trace/lib/src/utils.dart
deleted file mode 100644
index 30a43bc..0000000
--- a/pkgs/stack_trace/lib/src/utils.dart
+++ /dev/null
@@ -1,39 +0,0 @@
-// 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 utils;
-
-import 'dart:io';
-
-import 'package:pathos/path.dart' as path;
-
-/// 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("\\", "/")}');
-  }
-}
diff --git a/pkgs/stack_trace/test/frame_test.dart b/pkgs/stack_trace/test/frame_test.dart
index d1f53f6..de0715a 100644
--- a/pkgs/stack_trace/test/frame_test.dart
+++ b/pkgs/stack_trace/test/frame_test.dart
@@ -7,7 +7,6 @@
 import 'dart:io';
 
 import 'package:pathos/path.dart' as path;
-import 'package:stack_trace/src/utils.dart';
 import 'package:stack_trace/stack_trace.dart';
 import 'package:unittest/unittest.dart';
 
@@ -41,7 +40,7 @@
     // TODO(nweiz): use URL-style paths when such a thing exists.
     var builder = new path.Builder(style: path.Style.posix);
     expect(builder.basename(frame.uri.path), equals('frame_test.dart'));
-    expect(frame.line, equals(16));
+    expect(frame.line, equals(15));
     expect(frame.column, equals(5));
     expect(frame.member, equals('getStackFrame'));
   });
@@ -115,7 +114,7 @@
     });
 
     test('returns the relative path for file URIs', () {
-      var uri = pathToFileUri(path.join('foo', 'bar.dart'));
+      var uri = path.toUri(path.join('foo', 'bar.dart'));
       expect(new Frame.parse('#0 Foo ($uri:0:0)').library,
           equals(path.join('foo', 'bar.dart')));
     });
@@ -127,7 +126,7 @@
       expect(new Frame.parse('#0 Foo '
               '(http://dartlang.org/thing.dart:5:10)').location,
           equals('http://dartlang.org/thing.dart 5:10'));
-      var uri = pathToFileUri(path.join('foo', 'bar.dart'));
+      var uri = path.toUri(path.join('foo', 'bar.dart'));
       expect(new Frame.parse('#0 Foo ($uri:1:2)').location,
           equals('${path.join('foo', 'bar.dart')} 1:2'));
     });
diff --git a/pkgs/stack_trace/test/trace_test.dart b/pkgs/stack_trace/test/trace_test.dart
index 902ae80..9ecebb5 100644
--- a/pkgs/stack_trace/test/trace_test.dart
+++ b/pkgs/stack_trace/test/trace_test.dart
@@ -7,7 +7,6 @@
 import 'dart:io';
 
 import 'package:pathos/path.dart' as path;
-import 'package:stack_trace/src/utils.dart';
 import 'package:stack_trace/stack_trace.dart';
 import 'package:unittest/unittest.dart';
 
@@ -91,7 +90,7 @@
   });
 
   test('.toString() nicely formats the stack trace', () {
-    var uri = pathToFileUri(path.join('foo', 'bar.dart'));
+    var uri = path.toUri(path.join('foo', 'bar.dart'));
     var trace = new Trace.parse('''
 #0      Foo._bar ($uri:42:21)
 #1      zip.<anonymous closure>.zap (dart:async/future.dart:0:2)