Skip to content

Commit 59aa45a

Browse files
committed
try fix _0pascal
1 parent e6ec471 commit 59aa45a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/util.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,24 @@ impl Case {
2828
Cow::Borrowed(s) if s.is_constant_case() => cow,
2929
_ => cow.to_constant_case().into(),
3030
},
31-
Self::Pascal => match cow {
32-
Cow::Borrowed(s) if s.is_pascal_case() => cow,
33-
_ => cow.to_pascal_case().into(),
34-
},
31+
Self::Pascal => {
32+
if let Some((first, _)) = cow
33+
.char_indices()
34+
.find(|(_, c)| c != &'_' && !c.is_ascii_digit())
35+
{
36+
if first != 0 {
37+
let (prefix, s) = cow.split_at(first);
38+
format!("{prefix}{}", s.to_pascal_case()).into()
39+
} else {
40+
match cow {
41+
Cow::Borrowed(s) if s.is_pascal_case() => cow,
42+
_ => cow.to_pascal_case().into(),
43+
}
44+
}
45+
} else {
46+
cow
47+
}
48+
}
3549
Self::Snake => match cow {
3650
Cow::Borrowed(s) if s.is_snake_case() => cow,
3751
_ => cow.to_snake_case().into(),

0 commit comments

Comments
 (0)