scolapasta_path

Function is_explicit_relative

Source
pub fn is_explicit_relative<P: AsRef<Path>>(path: P) -> bool
Expand description

Return whether the given path starts with an explicit relative path.

Explicit relative paths start with . or .. followed immediately by a directory separator.

Some Ruby source loaders have special handling for explicit relative paths where explicit relative paths are resolved relative to the process’s current working directory rather than the load path.

§Compatibility

On Windows, if the given path contains invalid Unicode code points and cannot be converted to &str, this function will correctly identify these paths as explicit relative if their prefixes allow.

On platforms that are neither Windows nor Unix, this function may return incorrect results for paths that do not contain valid UTF-8. See Path::to_str.

§Examples

assert!(is_explicit_relative("./test/loader"));
assert!(is_explicit_relative("../rake/test_task"));

assert!(!is_explicit_relative("json/pure"));
assert!(!is_explicit_relative("/artichoke/src/json/pure"));

§MRI C Declaration

This routine is derived from the reference implementation in MRI Ruby:

static int
is_explicit_relative(const char *path)
{
    if (*path++ != '.') return 0;
    if (*path == '.') path++;
    return isdirsep(*path);
}