base/utils/paths.bro
Functions to parse and manipulate UNIX style paths and directories.
Summary
Functions
build_path : function |
Constructs a path to a file given a directory and a file name. |
build_path_compressed : function |
Returns a compressed path to a file given a directory and file name. |
compress_path : function |
Compresses a given path by removing ‘..’s and the parent directory it
references and also removing dual ‘/’s and extraneous ‘/./’s. |
extract_path : function |
Given an arbitrary string, extracts a single, absolute path (directory
with filename). |
Detailed Interface
Constants
-
absolute_path_pat
-
/^?((\/|[A-Za-z]:[\\\/]).*)$?/
Functions
-
build_path
-
Constructs a path to a file given a directory and a file name.
Dir: | the directory in which the file lives. |
File_name: | the name of the file. |
Returns: | the concatenation of the directory path and file name, or just
the file name if it’s already an absolute path. |
-
build_path_compressed
-
Returns a compressed path to a file given a directory and file name.
See build_path
and compress_path
.
-
compress_path
-
Compresses a given path by removing ‘..’s and the parent directory it
references and also removing dual ‘/’s and extraneous ‘/./’s.
Dir: | a path string, either relative or absolute. |
Returns: | a compressed version of the input path. |
-
Given an arbitrary string, extracts a single, absolute path (directory
with filename).
Todo
Make this work on Window’s style directories.
Input: | a string that may contain an absolute path. |
Returns: | the first absolute path found in input string, else an empty string. |