scolapasta_path

Function is_explicit_relative_bytes

Source
pub fn is_explicit_relative_bytes<P: AsRef<[u8]>>(path: P) -> bool
Expand description

Return whether the given byte string to treat as a 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.

§Usage

This function can be used instead of is_explicit_relative if callers already have a byte string, as they likely do when manipulating a Ruby String.

§Compatibility

Since this function operates on bytes, it is guaranteed to give a correct Boolean answer to whether a path is explicit relative on all platforms.

§Examples

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

assert!(!is_explicit_relative_bytes(b"json/pure"));
assert!(!is_explicit_relative_bytes(b"/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);
}