splitby 1.2.5

Split text by a regex delimiter — a powerful, multi-threaded alternative to cut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::types::Delimiter;

pub fn trim_quotes(value: &str) -> String {
    if value.starts_with("\"") && value.ends_with("\"") {
        return value[1..value.len() - 1].to_string();
    } else if value.starts_with("\'") && value.ends_with("\'") {
        return value[1..value.len() - 1].to_string();
    }
    return value.to_string();
}

pub fn parse_delimiter_token(value: &str) -> Delimiter {
    let trimmed = trim_quotes(value);
    if trimmed.len() > 1 && trimmed.starts_with('/') && trimmed.ends_with('/') {
        return Delimiter::Regex(trimmed[1..trimmed.len() - 1].to_string());
    }
    Delimiter::Literal(trimmed)
}