PathParser

Parses a file path.

File paths containing non-ansi characters should be UTF-8 encoded. Supporting Unicode in this manner was deemed to be more suitable than providing a wchar version of PathParser, and is both consistent & compatible with the approach taken with the Uri class.

Note that patterns of adjacent '.' separators are treated specially in that they will be assigned to the name where there is no distinct suffix. In addition, a '.' at the start of a name signifies it does not belong to the suffix i.e. ".file" is a name rather than a suffix. Patterns of intermediate '.' characters will otherwise be assigned to the suffix, such that "file....suffix" includes the dots within the suffix itself. See method ext() for a suffix without dots.

Note also that normalization of path-separators does *not* occur by default. This means that usage of '\' characters should be explicitly converted beforehand into '/' instead (an exception is thrown in those cases where '\' is present). On-the-fly conversion is avoided because (a) the provided path is considered immutable and (b) we avoid taking a copy of the original path. Module FilePath exists at a higher level, without such contraints.

Members

Functions

dup
PathParser dup()

Duplicate this path.

ext
mstring ext()

Ext is the tail of the filename, rightward of the rightmost '.' separator e.g. path "foo.bar" has ext "bar". Note that patterns of adjacent separators are treated specially - for example, ".." will wind up with no ext at all.

file
mstring file()

Return the name + suffix combination.

folder
mstring folder()

Return the file path. Paths may start and end with a "/". The root path is "/" and an unspecified path is returned as an empty string. Directory paths may be split such that the directory name is placed into the 'name' member; directory paths are treated no differently than file paths.

isAbsolute
bool isAbsolute()

Returns true if this path is *not* relative to the current working directory.

isChild
bool isChild()

Returns true if this path has a parent. Note that a parent is defined by the presence of a path-separator in the path. This means 'foo' within "/foo" is considered a child of the root.

isEmpty
bool isEmpty()

Returns true if this FilePath is empty.

name
mstring name()

Return the name of this file, or directory.

opEquals
equals_t opEquals(cstring s)

Does this path equate to the given text? We ignore trailing path-separators when testing equivalence.

opEquals
equals_t opEquals(PathParser rhs)

Comparison to another PathParser, to avoid falling back to auto-generated one

parent
cstring parent()

Returns a path representing the parent of this one. This will typically return the current path component, though with a special case where the name component is empty. In such cases, the path is scanned for a prior segment:

  • normal: /x/y/z => /x/y
  • special: /x/y/ => /x
  • normal: /x => /
  • normal: / => empty
parse
PathParser parse(mstring path)

Parse the path spec.

parse
PathParser parse(mstring path, size_t end)

Parse the path spec with explicit end point. A '\' is considered illegal in the path and should be normalized out before this is invoked (the content managed here is considered immutable, and thus cannot be changed by this function.)

path
mstring path()

Return the root + folder combination.

pop
cstring pop()

Pop the rightmost element off this path, stripping off a trailing '/' as appropriate:

  • /x/y/z => /x/y
  • /x/y/ => /x/y (note trailing '/' in the original)
  • /x/y => /x
  • /x => /
  • / => empty
root
mstring root()

Return the root of this path. Roots are constructs such as "C:".

suffix
mstring suffix()

Suffix is like ext, but includes the separator e.g. path "foo.bar" has suffix ".bar".

toString
istring toString()

Return the complete text of this filepath.

Variables

end_
int end_;
ext_
int ext_;
folder_
int folder_;
Undocumented in source.
fp
mstring fp;
name_
int name_;
suffix_
int suffix_;
Undocumented in source.

Meta