From 080cc42bb1da09059dbc35049a7ded0649961e0c Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 29 Aug 2022 20:52:56 +0200 Subject: feat: implement async functionality --- macros/src/util/mod.rs | 1 + macros/src/util/string.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 macros/src/util/string.rs (limited to 'macros/src/util') 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 = 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() +} -- cgit v1.2.3-18-g5258