diff options
Diffstat (limited to 'macros/src/util')
-rw-r--r-- | macros/src/util/mod.rs | 1 | ||||
-rw-r--r-- | macros/src/util/string.rs | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/macros/src/util/mod.rs b/macros/src/util/mod.rs index 4f2a594..0705853 100644 --- a/macros/src/util/mod.rs +++ b/macros/src/util/mod.rs @@ -1,3 +1,4 @@ pub mod item_impl; pub mod iterator_ext; +pub mod string; pub mod syn_path; diff --git a/macros/src/util/string.rs b/macros/src/util/string.rs new file mode 100644 index 0000000..90cccee --- /dev/null +++ b/macros/src/util/string.rs @@ -0,0 +1,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() +} |