tango.util.PathUtil

License:

BSD style: see license.txt

Version:

Dec 2006: Initial release Jan 2009: Replaced normalize

Author:

Max Samukha, Thomas Kühne, Grzegorz Adam Hankiewicz
enum [private] #
Normalizes a path component.
. segments are removed /.. are removed

On Windows, \ will be converted to / prior to normalization.

Multiple consecutive forward slashes are replaced with a single forward slash.

Note that any number of .. segments at the front is ignored, unless it is an absolute path, in which case they are removed.

The input path is copied into either the provided buffer, or a heap allocated array if no buffer was provided. Normalization modifies this copy before returning the relevant slice.

Examples:

1
normalize("/home/foo/./bar/../../john/doe"); // => "/home/john/doe"
bool patternMatch(char[] filename, char[] pattern) [deprecated] #
Matches a pattern against a filename.
Some characters of pattern have special a meaning (they are meta-characters) and can't be escaped. These are:

* Matches 0 or more instances of any character.
? Matches exactly one instances of any character.
[chars] Matches one instance of any character that appears between the brackets.
[!chars] Matches one instance of any character that does not appear between the brackets after the exclamation mark.

Internally individual character comparisons are done calling charMatch(), so its rules apply here too. Note that path separators and dots don't stop a meta-character from matching further portions of the filename.

Returns:

true if pattern matches filename, false otherwise.

See Also:

charMatch().

Throws:

Nothing.

Examples:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
version(Win32)
{
    patternMatch("foo.bar", "*") // => true
    patternMatch(r"foo/foo\bar", "f*b*r") // => true
    patternMatch("foo.bar", "f?bar") // => false
    patternMatch("Goo.bar", "[fg]???bar") // => true
    patternMatch(r"d:\foo\bar", "d*foo?bar") // => true
}
version(Posix)
{
    patternMatch("Go*.bar", "[fg]???bar") // => false
    patternMatch("/foo*home/bar", "?foo*bar") // => true
    patternMatch("foobar", "foo?bar") // => true
}
bool charMatch(char c1, char c2) [private] #
Matches filename characters.
Under Windows, the comparison is done ignoring case. Under Linux an exact match is performed.

Returns:

true if c1 matches c2, false otherwise.

Throws:

Nothing.

Examples:

1
2
3
4
5
6
7
8
9
10
version(Win32)
{
    charMatch('a', 'b') // => false
    charMatch('A', 'a') // => true
}
version(Posix)
{
    charMatch('a', 'b') // => false
    charMatch('A', 'a') // => false
}