de-cycle conduit_macros from conduit_core.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
d7d874f88d
commit
7d487d53d8
5 changed files with 28 additions and 3 deletions
25
src/macros/utils.rs
Normal file
25
src/macros/utils.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#[must_use]
|
||||
pub(crate) fn camel_to_snake_string(s: &str) -> String {
|
||||
let mut output = String::with_capacity(
|
||||
s.chars()
|
||||
.fold(s.len(), |a, ch| a.saturating_add(usize::from(ch.is_ascii_uppercase()))),
|
||||
);
|
||||
|
||||
let mut state = false;
|
||||
s.chars().for_each(|ch| {
|
||||
let m = ch.is_ascii_uppercase();
|
||||
let s = exchange(&mut state, !m);
|
||||
if m && s {
|
||||
output.push('_');
|
||||
}
|
||||
output.push(ch.to_ascii_lowercase());
|
||||
});
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
pub(crate) fn exchange<T: Clone>(state: &mut T, source: T) -> T {
|
||||
let ret = state.clone();
|
||||
*state = source;
|
||||
ret
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue