File_Utilities module

parse_path

procedure · 1 overloadSource

Splits the text _s into a Path, and with reduce (the default) tidies it with reduce_path.

parse_path :: (_s: string, reduce := true) -> Path

The text is not checked against the file system, and an empty string gives a path with no words. See Path for who frees what.

Parameters

_s: string
reduce := true

Returns

ExampleOpen in playground ↗
path := parse_path("..//orchard/./maple/../oak/");
assert(path.number_of_leading_slashes == 0 && path.trailing_slash);
assert(path.words.count == 3 && path.words[0] == ".." && path.words[1] == "orchard" && path.words[2] == "oak");

found, position := path_contains(path, .["orchard", "oak"]);
assert(found && position == 1);
array_free(path.words);

raw := parse_path("a/./b", reduce = false);
assert(raw.words.count == 3);
array_free(raw.words);

See also