Introduce pmp-core crate: provide shared proc-macro utilities, strict attribute parsing, and reusable helpers for pmp-* crates.
This commit is contained in:
26
crates/pmp-core/src/functions.rs
Normal file
26
crates/pmp-core/src/functions.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
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(" ")
|
||||
}
|
||||
Reference in New Issue
Block a user