Chromium Code Reviews| Index: sdk/lib/io/file_system_entity.dart |
| diff --git a/sdk/lib/io/file_system_entity.dart b/sdk/lib/io/file_system_entity.dart |
| index 0887175e859713a681c37ffc5c57d96c66a0cc3a..ebf00575dd1081d3ce1f00a008336c18f5ca47b2 100644 |
| --- a/sdk/lib/io/file_system_entity.dart |
| +++ b/sdk/lib/io/file_system_entity.dart |
| @@ -343,6 +343,40 @@ abstract class FileSystemEntity { |
| }); |
| } |
| + static final RegExp _absoluteWindowsPathPattern = |
| + new RegExp(r'^(\\\\|[a-zA-Z]:[/\\])'); |
| + |
| + /** |
| + * Returns a [bool] indicating whether this object's path is absolute. |
| + * |
| + * On Windows, a path is absolute if it starts with \\ or a drive letter |
| + * between a and z (upper or lower case) followed by :\ or :/. |
| + * On non-Windows, a path is absolute if it starts with /. |
| + */ |
| + bool get isAbsolute { |
| + if (Platform.isWindows) { |
| + return path.startsWith(_absoluteWindowsPathPattern); |
| + } else { |
| + return path.startsWith('/'); |
| + } |
| + } |
| + |
| + /** |
| + * Returns the absolute path to this file system entity, by prefixing |
| + * a relative path with the current working directory, and returning |
| + * an absolute path unchanged. |
| + */ |
| + String get absolutePath { |
|
Søren Gjesse
2013/09/13 06:56:08
Thinking about this once more. Shouldn't this retu
|
| + if (isAbsolute) return path; |
| + String current = Directory.current.path; |
| + if (current.endsWith('/') || |
| + (Platform.isWindows && current.endsWith('\\'))) { |
| + return '$current$path'; |
| + } else { |
| + return '$current${Platform.pathSeparator}$path'; |
| + } |
| + } |
| + |
| /** |
| * Synchronously checks whether two paths refer to the same object in the |