| 1 |
use crate::Tendril; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
pub fn to_pascal_case(text: impl Iterator<Item = char>) -> Tendril { |
| 6 |
let mut res = Tendril::new(); |
| 7 |
to_pascal_case_with(text, &mut res); |
| 8 |
res |
| 9 |
} |
| 10 |
|
| 11 |
pub fn to_pascal_case_with(text: impl Iterator<Item = char>, buf: &mut Tendril) { |
| 12 |
let mut at_word_start = true; |
| 13 |
for c in text { |
| 14 |
|
| 15 |
if !c.is_alphanumeric() { |
| 16 |
at_word_start = true; |
| 17 |
continue; |
| 18 |
} |
| 19 |
if at_word_start { |
| 20 |
at_word_start = false; |
| 21 |
buf.extend(c.to_uppercase()); |
| 22 |
} else { |
| 23 |
buf.push(c) |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
pub fn to_upper_case_with(text: impl Iterator<Item = char>, buf: &mut Tendril) { |
| 29 |
for c in text { |
| 30 |
for c in c.to_uppercase() { |
| 31 |
buf.push(c) |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
pub fn to_lower_case_with(text: impl Iterator<Item = char>, buf: &mut Tendril) { |
| 37 |
for c in text { |
| 38 |
for c in c.to_lowercase() { |
| 39 |
buf.push(c) |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
pub fn to_camel_case(text: impl Iterator<Item = char>) -> Tendril { |
| 45 |
let mut res = Tendril::new(); |
| 46 |
to_camel_case_with(text, &mut res); |
| 47 |
res |
| 48 |
} |
| 49 |
pub fn to_camel_case_with(mut text: impl Iterator<Item = char>, buf: &mut Tendril) { |
| 50 |
for c in &mut text { |
| 51 |
if c.is_alphanumeric() { |
| 52 |
buf.extend(c.to_lowercase()) |
| 53 |
} |
| 54 |
} |
| 55 |
let mut at_word_start = false; |
| 56 |
for c in text { |
| 57 |
|
| 58 |
if !c.is_alphanumeric() { |
| 59 |
at_word_start = true; |
| 60 |
continue; |
| 61 |
} |
| 62 |
if at_word_start { |
| 63 |
at_word_start = false; |
| 64 |
buf.extend(c.to_uppercase()); |
| 65 |
} else { |
| 66 |
buf.push(c) |
| 67 |
} |
| 68 |
} |
| 69 |
} |