Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * A Path, which is a String interpreted as a sequence of path segments, | |
| 7 * which are strings, separated by forward slashes. | |
| 8 * Paths are immutable wrappers of a String, that offer member functions for | |
| 9 * useful path manipulations and queries. Joining of paths and normalization | |
| 10 * interpret '.' and '..' in the usual way. | |
| 11 */ | |
| 12 interface Path default _PathImpl { | |
|
Søren Gjesse
2012/06/18 07:29:35
Following the convention for the rest of dart:io d
Bill Hesse
2012/06/18 15:46:38
Done.
| |
| 13 /** | |
| 14 * Creates a Path from the String [source]. [source] is used as-is, so if | |
| 15 * the string does not consist of segments separated by forward slashes, the | |
| 16 * behavior may not be as expected. Paths are immutable, and constant | |
| 17 * Path objects may be constructed from constant Strings. | |
| 18 */ | |
| 19 const Path(String source); | |
| 20 | |
| 21 /** | |
| 22 * Creates a Path from a String that uses the native filesystem's conventions. | |
| 23 * On Windows, this converts '\' to '/', and adds a '/' before a drive letter. | |
| 24 */ | |
| 25 Path.fromNative(String source); | |
| 26 | |
| 27 /** | |
| 28 * Is this path the empty string? | |
| 29 */ | |
| 30 bool get isEmpty(); | |
| 31 | |
| 32 /** | |
| 33 * Is this path an absolute path, beginning with a path separator? | |
|
Søren Gjesse
2012/06/18 07:29:35
Should there be some additional information on Win
Bill Hesse
2012/06/18 15:46:38
Done.
| |
| 34 */ | |
| 35 bool get isAbsolute(); | |
| 36 | |
| 37 /** | |
| 38 * Does this path end with a path separator? | |
| 39 */ | |
| 40 bool get hasTrailingSeparator(); | |
| 41 | |
| 42 /** | |
| 43 * Does this path contain no consecutive path separators, no segments that | |
| 44 * are '.' unless the path is exactly '.', and segments that are '..' only | |
| 45 * as the leading segments on a relative path? | |
| 46 */ | |
| 47 bool get isCanonical(); | |
| 48 | |
| 49 /** | |
| 50 * Make a path canonical by dropping segments that are '.', cancelling | |
| 51 * segments that are '..' with preceding segments, if possible, | |
| 52 * and combining consecutive path separators. | |
|
Søren Gjesse
2012/06/18 07:29:35
What happens if there are more '..'s that "real" s
Bill Hesse
2012/06/18 15:46:38
Leading '..' segments are kept on relative paths,
| |
| 53 */ | |
| 54 Path canonicalize(); | |
|
Anders Johnsen
2012/06/18 06:27:08
I'm not sure what I like the most, so what does ot
| |
| 55 | |
| 56 /** | |
| 57 * Joins the relative path [further] to this path. Canonicalizes the path, | |
| 58 * interpreting '.' and '..' as directory traversal commands, and removing | |
|
Søren Gjesse
2012/06/18 07:29:35
The explanation of '.' and '..' here is slightly
Bill Hesse
2012/06/18 15:46:38
Done.
| |
| 59 * consecutive path separators. | |
| 60 * | |
| 61 * If [further] is an absolute path, an IllegalArgument exception is thrown. | |
| 62 * | |
| 63 * Examples: | |
| 64 * `new Path('/a/b/c').join(new Path('d/e'))` returns the Path object | |
| 65 * containing `'a/b/c/d/e'`. | |
| 66 * | |
| 67 * `new Path('a/b/../c/').join(new Path('d/./e//')` returns the Path | |
| 68 * containing `'a/c/d/e/'`. | |
| 69 * | |
| 70 * `new Path('a/b/c').join(new Path('d/../../e')` returns the Path | |
| 71 * containing `'a/b/e'`. | |
| 72 * | |
| 73 * Note that the join operation does not drop the last segment of the | |
| 74 * base path, the way URL joining does. That would be accomplished with | |
| 75 * basepath.directoryPath.join(further). | |
| 76 * | |
| 77 * If you want to avoid joins that traverse | |
| 78 * parent directories in the base, you can check whether | |
| 79 * `further.canonicalize()` starts with '../' or equals '..'. | |
|
Søren Gjesse
2012/06/18 07:29:35
Is that sufficient? What about a [further] of 'x/.
Bill Hesse
2012/06/18 15:46:38
'x/../..'.canonicalize() is '..'.
| |
| 80 */ | |
| 81 Path join(Path further); | |
| 82 | |
| 83 | |
| 84 /** | |
| 85 * Returns a path [:relative:] such that | |
| 86 * [:base.join(relative) == this.canonicalize():]. | |
| 87 * Throws an exception if no such path exists, or if this | |
| 88 * case is not implemented yet. | |
|
Anders Johnsen
2012/06/18 06:27:08
A few comments here.
1) Do you really mean "if no
Bill Hesse
2012/06/18 15:46:38
Done.
| |
| 89 */ | |
| 90 Path relativeTo(Path base); | |
| 91 | |
| 92 /** | |
| 93 * Converts a path to a string using the native filesystem's conventions. | |
| 94 * | |
| 95 * On Windows, converts path separators to backwards slashes, and removes | |
| 96 * the leading path separator if the path starts with a drive specification. | |
|
Søren Gjesse
2012/06/18 07:29:35
Should the invariant here be that is the fromNativ
Bill Hesse
2012/06/18 15:46:38
There are some corner cases, with mixed backward a
| |
| 97 */ | |
| 98 String toNativePath(); | |
|
Søren Gjesse
2012/06/18 07:29:35
The name toNativePath indicate that a Path not a S
Bill Hesse
2012/06/18 15:46:38
Could we say toNativeFilepath? toNativepath? toN
| |
| 99 | |
| 100 /** | |
| 101 * Returns the path as a string. If this path is constructed using | |
| 102 * new Path() or new Path.fromNative() on a non-Windows system, the | |
| 103 * returned value is the original string argument to the constructor. | |
| 104 */ | |
| 105 String toString(); | |
| 106 | |
| 107 /** | |
| 108 * Gets the segments of a Path. Paths beginning or ending with the | |
| 109 * path separator do not have leading or terminating empty segments. | |
| 110 * Other than that, the segments are just the result of splitting the | |
| 111 * path on the path separator. | |
| 112 * | |
| 113 * new Path('/a/b/c/d').segments() == ['a', 'b', 'c', d']; | |
| 114 * new Path(' foo bar //../') == [' foo bar ', '', '..']; | |
| 115 */ | |
| 116 List<String> segments(); | |
| 117 | |
| 118 /** | |
| 119 * Drops the final path separator and whatever follows it from this Path, | |
| 120 * and returns the resulting Path object. If the only path separator in | |
| 121 * this Path is the first character, returns '/' instead of the empty string. | |
| 122 * If there is no path separator in the Path, returns the empty string. | |
| 123 * | |
| 124 * new Path('../images/dot.gif').directoryPath == '../images' | |
| 125 * new Path('/usr/geoffrey/www/').directoryPath == '/usr/geoffrey/www' | |
| 126 * new Path('lost_file_old').directoryPath == '' | |
| 127 * new Path('/src').directoryPath == '/' | |
| 128 * Note: new Path('/D:/src').directoryPath == '/D:' | |
| 129 */ | |
| 130 Path get directoryPath(); | |
|
Anders Johnsen
2012/06/18 06:27:08
I really like this one! Thanks!
| |
| 131 | |
| 132 /** | |
| 133 * The part of the path after the last path separator, or the entire path if | |
| 134 * it contains no path separator. | |
| 135 * | |
| 136 * new Path('images/DSC_0027.jpg).filename == 'DSC_0027.jpg' | |
| 137 * new Path('users/fred/').filename == '' | |
| 138 */ | |
| 139 String get filename(); | |
|
Søren Gjesse
2012/06/18 07:29:35
fileName (uppercase N)?
Bill Hesse
2012/06/18 15:46:38
I think filename is a common noun, and not the sam
| |
| 140 | |
| 141 /** | |
| 142 * The part of [filename] before the last '.', or the entire filename if it | |
| 143 * contains no '.'. | |
| 144 * | |
| 145 * new Path('/c:/My Documents/Heidi.txt').filenameWithoutExtension | |
| 146 * would return 'Heidi'. | |
| 147 * new Path('not what I would call a path').filenameWithoutExtension | |
| 148 * would return 'not what I would call a path'. | |
| 149 */ | |
| 150 String get filenameWithoutExtension(); | |
|
Anders Johnsen
2012/06/18 06:27:08
I see you went for this, and not basename. Given t
Søren Gjesse
2012/06/18 07:29:35
fileNameWithoutExtension (uppercase N)?
| |
| 151 | |
| 152 /** | |
| 153 * The part of [filename] after the last '.', or '' if [filename] | |
| 154 * contains no '.'. | |
| 155 * | |
| 156 * new Path('tiger.svg').extension == 'svg' | |
| 157 * new Path('/src/dart/dart_secrets').extension == '' | |
| 158 */ | |
| 159 String get extension(); | |
|
Anders Johnsen
2012/06/18 06:27:08
With the classic case of .tar.gz, should we have a
Bill Hesse
2012/06/18 15:46:38
We could add that. or get extensions?
multipleExt
| |
| 160 } | |
| OLD | NEW |