proxmox/proxmox-api-macro/src/util.rs
Wolfgang Bumiller 7f704d12df macro: started basic enum support
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:14:58 +02:00

39 lines
847 B
Rust

/// Convert `this_kind_of_text` to `ThisKindOfText`.
pub fn to_camel_case(text: &str) -> String {
let mut out = String::new();
let mut capitalize = true;
for c in text.chars() {
if c == '_' {
capitalize = true;
} else {
if capitalize {
out.extend(c.to_uppercase());
capitalize = false;
} else {
out.push(c);
}
}
}
out
}
/// Convert `ThisKindOfText` to `this_kind_of_text`.
pub fn to_underscore_case(text: &str) -> String {
let mut out = String::new();
for c in text.chars() {
if c.is_uppercase() {
if !out.is_empty() {
out.push('_');
}
out.extend(c.to_lowercase());
} else {
out.push(c);
}
}
out
}