Skip to content

Commit

Permalink
try fix _0pascal
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Feb 3, 2024
1 parent e6ec471 commit 59aa45a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,24 @@ impl Case {
Cow::Borrowed(s) if s.is_constant_case() => cow,
_ => cow.to_constant_case().into(),
},
Self::Pascal => match cow {
Cow::Borrowed(s) if s.is_pascal_case() => cow,
_ => cow.to_pascal_case().into(),
},
Self::Pascal => {
if let Some((first, _)) = cow
.char_indices()
.find(|(_, c)| c != &'_' && !c.is_ascii_digit())
{
if first != 0 {
let (prefix, s) = cow.split_at(first);
format!("{prefix}{}", s.to_pascal_case()).into()
} else {
match cow {
Cow::Borrowed(s) if s.is_pascal_case() => cow,
_ => cow.to_pascal_case().into(),
}
}
} else {
cow
}
}
Self::Snake => match cow {
Cow::Borrowed(s) if s.is_snake_case() => cow,
_ => cow.to_snake_case().into(),
Expand Down

0 comments on commit 59aa45a

Please sign in to comment.