Chromium Code Reviews| Index: runtime/bin/path.dart |
| diff --git a/runtime/bin/path.dart b/runtime/bin/path.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..292a39e3ab02536e54cfe1d5dd07b8676aa796d0 |
| --- /dev/null |
| +++ b/runtime/bin/path.dart |
| @@ -0,0 +1,109 @@ |
| +// Copyright (c) 2012, 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. |
| + |
| +/** |
| + * A Path, interpreted as a sequence of strings separated by forward slashes. |
| + * Paths are immutable wrappers of a String, that offer member functions for |
| + * useful path manipulations and queries. |
| + */ |
| +interface Path default _PathImpl { |
| + const Path(String source); |
|
Mads Ager (google)
2012/06/01 08:11:31
Please document the constructor. Maybe with a comm
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + |
| + /** |
| + * Creates a Path from a String that uses the native filesystem's conventions. |
| + * On Windows, this converts '\' to '/', and adds a '/' before a drive letter. |
| + */ |
| + Path.fromNative(String source); |
| + |
| + /** |
| + * Is this path the empty string? |
| + */ |
| + bool get isEmpty(); |
| + |
| + /** |
| + * Does this path begin with '/'? |
|
Mads Ager (google)
2012/06/01 08:11:31
It seems strange that the getter name is 'isAbsolu
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + */ |
| + bool get isAbsolute(); |
| + |
| + /** |
| + * Does this path end with '/'? |
| + */ |
| + bool get hasTrailingSlash(); |
|
Mads Ager (google)
2012/06/01 08:11:31
I think I would prefer 'path separator' instead of
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + |
| + /** |
| + * Does this path contain no segments . or .., except leading .. segments, |
|
Mads Ager (google)
2012/06/01 08:11:31
If you use the term segments here, maybe the initi
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + * and contain no consecutive path separators? |
| + */ |
| + bool get isCanonical(); |
| + |
| + /** |
| + * Make a path canonical by dropping . segments, canceling .. segments with |
|
Mads Ager (google)
2012/06/01 08:11:31
Ditto.
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + * preceding segments, if possible, and combining consecutive path separators. |
| + */ |
| + Path canonicalize(); |
| + |
| + /** |
| + * Joins the relative path [further] to this path, which may be absolute |
| + * or relative. Canonicalizes the path, to remove ., .., and //. |
|
Mads Ager (google)
2012/06/01 08:11:31
Examples or a more thorough explanation would be g
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + */ |
| + Path join(Path further); |
| + |
| + /** |
| + * Joins the relative path [further] to this path, which may be absolute |
| + * or relative. Canonicalizes the path, to remove ., .., and //. |
| + * [further] may not contain '..' segments which would traverse into |
| + * this path, so [further.canonicalize()] is checked that it does not |
| + * begin with '..' |
|
Mads Ager (google)
2012/06/01 08:11:31
I think examples would be good here. What happens
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + */ |
| + Path safeJoin(Path further); |
| + |
| + /** |
| + * Converts a path to a string using the native filesystem's conventions. |
| + */ |
| + String toNativePath(); |
| + |
| + /** |
| + * Returns the path as a string. If this path is constructed using |
| + * new Path() or new Path.fromNative() on a non-Windows system, the |
| + * returned value is the original string argument to the constructor. |
| + */ |
| + String toString(); |
| + |
| + /** |
| + * Gets the segments of a Path (the strings separated by /) |
|
Mads Ager (google)
2012/06/01 08:11:31
Instead of the parenthesis you could have an examp
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + */ |
| + List<String> segments(); |
| + |
| + /** |
| + * Drops the final '/' and whatever follows it from this Path, and returns |
|
Mads Ager (google)
2012/06/01 08:11:31
should we write out 'path separator' instead of '/
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + * the resulting Path object. If the only '/' in this Path is the first |
| + * character, returns '/' instead of ''. If there is no '/' in the Path, |
|
Mads Ager (google)
2012/06/01 08:11:31
Text is good. Examples is better. :)
Also in the
Bill Hesse
2012/06/15 14:23:08
Done.
|
| + * returns ''. |
| + */ |
| + Path get directoryPath(); |
| + |
| + /** |
| + * The part of the path after the last '/', or the entire path if it contains |
| + * no '/'. |
| + */ |
| + String get filename(); |
| + |
| + /** |
| + * The part of [filename] before the last '.', or the entire filename if it |
| + * contains no '.'. |
| + */ |
| + String get filenameWithoutExtension(); |
| + |
| + /** |
| + * The part of [filename] after the last '.', or '' if [filename] |
| + * contains no '.'. |
| + */ |
| + String get extension(); |
| +} |
| + |
| +class PathException implements Exception { |
|
Bill Hesse
2012/06/15 14:23:08
Removed.
|
| + const PathException([String this.message]); |
| + String toString() => "PathException: $message"; |
| + final String message; |
| +} |