Skip to main content

luaur_require/functions/
extract_alias.rs

1extern crate alloc;
2
3use alloc::string::String;
4
5pub(crate) fn extract_alias(path: &str) -> String {
6    // To ignore the '@' alias prefix when processing the alias
7    const ALIAS_START_POS: usize = 1;
8
9    // If a directory separator was found, the length of the alias is the
10    // distance between the start of the alias and the separator. Otherwise,
11    // the whole string after the alias symbol is the alias.
12    let alias_len = if let Some(separator_pos) = path.find('/') {
13        separator_pos - ALIAS_START_POS
14    } else {
15        path.len() - ALIAS_START_POS
16    };
17
18    let start = ALIAS_START_POS;
19    let end = ALIAS_START_POS + alias_len;
20
21    String::from(&path[start..end])
22}