50 lines
1021 B
Rust
50 lines
1021 B
Rust
|
|
pub fn pascal_to_title(s: &str) -> String
|
|
{
|
|
let mut out = String::new();
|
|
|
|
for (i, ch) in s.chars().enumerate() {
|
|
if ch.is_uppercase() && i > 0 { out.push(' '); }
|
|
out.push(ch);
|
|
}
|
|
|
|
out
|
|
}
|
|
|
|
pub fn snake_to_title(s: &str) -> String
|
|
{
|
|
s.split('_')
|
|
.map(|word| {
|
|
let mut c = word.chars();
|
|
match c.next() {
|
|
None => String::new(),
|
|
Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
|
|
}
|
|
})
|
|
.collect::<Vec<_>>()
|
|
.join(" ")
|
|
}
|
|
|
|
pub fn pascal_to_snake(s: &str) -> String
|
|
{
|
|
let mut out = String::with_capacity(s.len());
|
|
let mut prev_lower = false;
|
|
|
|
for c in s.chars()
|
|
{
|
|
if c.is_uppercase()
|
|
{
|
|
if prev_lower { out.push('_'); }
|
|
for lc in c.to_lowercase() { out.push(lc); }
|
|
prev_lower = false;
|
|
}
|
|
else
|
|
{
|
|
prev_lower = true;
|
|
out.push(c);
|
|
}
|
|
}
|
|
|
|
out
|
|
}
|