OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #library('filenames'); | 5 #library('filenames'); |
6 | 6 |
7 #import('dart:io'); | 7 #import('dart:io'); |
8 #import('dart:uri'); | 8 #import('dart:uri'); |
9 | 9 |
10 // TODO(ahe): This library should be replaced by a general | 10 // TODO(ahe): This library should be replaced by a general |
11 // path-munging library. | 11 // path-munging library. |
12 // | 12 // |
13 // See also: | 13 // See also: |
14 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx | 14 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx |
15 | 15 |
16 String nativeToUriPath(String filename) { | 16 String nativeToUriPath(String filename) { |
17 if (Platform.operatingSystem() != 'windows') return filename; | 17 if (Platform.operatingSystem != 'windows') return filename; |
18 filename = filename.toLowerCase(); | 18 filename = filename.toLowerCase(); |
19 filename = filename.replaceAll('\\', '/'); | 19 filename = filename.replaceAll('\\', '/'); |
20 if (filename.length > 2 && filename[1] == ':') { | 20 if (filename.length > 2 && filename[1] == ':') { |
21 filename = "/$filename"; | 21 filename = "/$filename"; |
22 } | 22 } |
23 return filename; | 23 return filename; |
24 } | 24 } |
25 | 25 |
26 String uriPathToNative(String path) { | 26 String uriPathToNative(String path) { |
27 if (Platform.operatingSystem() != 'windows') return path; | 27 if (Platform.operatingSystem != 'windows') return path; |
28 path = path.toLowerCase(); | 28 path = path.toLowerCase(); |
29 if (path.length > 3 && path[0] == '/' && path[2] == ':') { | 29 if (path.length > 3 && path[0] == '/' && path[2] == ':') { |
30 return path.substring(1).replaceAll('/', '\\'); | 30 return path.substring(1).replaceAll('/', '\\'); |
31 } else { | 31 } else { |
32 return path.replaceAll('/', '\\'); | 32 return path.replaceAll('/', '\\'); |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 Uri getCurrentDirectory() { | 36 Uri getCurrentDirectory() { |
37 final String dir = nativeToUriPath(new File('.').fullPathSync()); | 37 final String dir = nativeToUriPath(new File('.').fullPathSync()); |
38 return new Uri(scheme: 'file', path: appendSlash(dir)); | 38 return new Uri(scheme: 'file', path: appendSlash(dir)); |
39 } | 39 } |
40 | 40 |
41 String appendSlash(String path) => path.endsWith('/') ? path : '$path/'; | 41 String appendSlash(String path) => path.endsWith('/') ? path : '$path/'; |
OLD | NEW |