aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util/string.rs
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/util/string.rs')
-rw-r--r--macros/src/util/string.rs12
1 files changed, 12 insertions, 0 deletions
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()
+}