| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library utils; |
| 4 | 5 |
| 5 import 'dart:io'; | 6 import 'dart:io'; |
| 6 import 'dart:uri'; | 7 import 'dart:uri'; |
| 7 | 8 |
| 8 import 'package:pathos/path.dart' as pathos; | 9 import 'package:pathos/path.dart' as pathos; |
| 9 | 10 |
| 10 /// Converts a local path string to a `file:` [Uri]. | 11 /// Converts a local path string to a `file:` [Uri]. |
| 11 Uri pathToFileUri(String pathString) { | 12 Uri pathToFileUri(String pathString) { |
| 12 pathString = pathos.absolute(pathString); | 13 pathString = pathos.absolute(pathString); |
| 13 if (Platform.operatingSystem != 'windows') { | 14 if (Platform.operatingSystem != 'windows') { |
| 14 return Uri.parse('file://$pathString'); | 15 return Uri.parse('file://$pathString'); |
| 15 } else if (pathos.rootPrefix(pathString).startsWith('\\\\')) { | 16 } else if (pathos.rootPrefix(pathString).startsWith('\\\\')) { |
| 16 // Network paths become "file://hostname/path/to/file". | 17 // Network paths become "file://hostname/path/to/file". |
| 17 return Uri.parse('file:${pathString.replaceAll("\\", "/")}'); | 18 return Uri.parse('file:${pathString.replaceAll("\\", "/")}'); |
| 18 } else { | 19 } else { |
| 19 // Drive-letter paths become "file:///C:/path/to/file". | 20 // Drive-letter paths become "file:///C:/path/to/file". |
| 20 return Uri.parse('file:///${pathString.replaceAll("\\", "/")}'); | 21 return Uri.parse('file:///${pathString.replaceAll("\\", "/")}'); |
| 21 } | 22 } |
| 22 } | 23 } |
| OLD | NEW |