aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util/string.rs
blob: 90cccee265c3250683258259f97ecb7487a72736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
use once_cell::sync::Lazy;
use regex::Regex;

static CAMELCASE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"([a-z])([A-Z])").unwrap());

pub fn camelcase_to_snakecase(camelcased: &str) -> String
{
    CAMELCASE_RE
        .replace(camelcased, "${1}_$2")
        .to_string()
        .to_lowercase()
}