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

dString
inout(char_t)[] dString()

Return the complete text of this filepath.

equals
bool equals(const(char)[] s)

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

parse
PathParser parse(char_t[] path)

Parse the path spec.

parse
PathParser parse(char_t[] 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.)

pop
inout(char_t)[] 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
toString
immutable(char)[] toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

dup
PathParser dup [@property getter]

Duplicate this path.

ext
char_t[] ext [@property getter]

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
inout(char_t)[] file [@property getter]

Return the name + suffix combination.

folder
inout(char_t)[] folder [@property getter]

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 [@property getter]

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

isChild
bool isChild [@property getter]

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 [@property getter]

Returns true if this FilePath is empty.

name
inout(char_t)[] name [@property getter]

Return the name of this file, or directory.

parent
inout(char_t)[] parent [@property getter]

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
path
inout(char_t)[] path [@property getter]

Return the root + folder combination.

root
inout(char_t)[] root [@property getter]

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

suffix
inout(char_t)[] suffix [@property getter]

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

Variables

end_
int end_;
ext_
int ext_;
folder_
int folder_;
Undocumented in source.
fp
char_t[] fp;
name_
int name_;
suffix_
int suffix_;
Undocumented in source.

Meta