1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0
/// Converts a camel-case string to snake-case
pub fn camel_to_snake(text: &str) -> String {
let mut out = String::with_capacity(text.len());
let mut first = true;
text.chars().for_each(|c| {
if !first && c.is_uppercase() {
out.push('_');
out.extend(c.to_lowercase());
} else if first {
first = false;
out.extend(c.to_lowercase());
} else {
out.push(c);
}
});
out
}