Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Casey

[![Build](https://github.com/holygits/casey/actions/workflows/build.yml/badge.svg)](https://github.com/holygits/casey/actions/workflows/build.yml)
[![Build](https://github.com/jordy25519/casey/actions/workflows/build.yml/badge.svg)](https://github.com/jordy25519/casey/actions/workflows/build.yml)

Case transforming macros

Expand Down
25 changes: 15 additions & 10 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ impl PascalCaseExt for String {

let mut char_stream = self.chars().peekable();
while let Some(current_char) = char_stream.next() {
if SEPARATORS.contains(current_char) | current_char.is_numeric() {
let next_char = char_stream.peek();
if next_char.is_none() {
// `current_char` is last in the stream
s.push(current_char.to_lowercase().next().unwrap());
break;
}

if SEPARATORS.contains(current_char) {
capitalise_next = true;
continue;
}
if current_char.is_numeric() {
capitalise_next = true;
s.push(current_char);
continue;
}

Expand All @@ -27,19 +39,12 @@ impl PascalCaseExt for String {
continue;
}

let next_char = char_stream.peek();
if next_char.is_none() {
// `current_char` is last in the stream
s.push(current_char.to_lowercase().next().unwrap());
break;
}

// lowercase this char if followed by another uppercase or punctuation
// e.g. AA => aA, A- => a-
// has the affect of transforming: 'ABCDe' into 'AbcDe'
if current_char.is_ascii_uppercase()
&& (next_char.unwrap().is_ascii_uppercase()
|| next_char.unwrap().is_ascii_punctuation())
&& next_char
.is_some_and(|x| x.is_numeric() || x.is_uppercase() || x.is_ascii_punctuation())
{
s.push(current_char.to_lowercase().next().unwrap());
} else {
Expand Down
14 changes: 14 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ fn it_works_to_pascalcase() {
assert!(pascal!(helloWorld)());
assert!(pascal!(hello_world)());
assert!(pascal!(HELLO_WORLD)());

#[allow(non_snake_case)]
fn Test2() -> bool {
true
}
assert!(pascal!(TEST2)());

#[allow(non_snake_case)]
fn One2Three() -> bool {
true
}
assert!(pascal!(ONE2THREE)());
assert!(pascal!(ONE_2_THREE)());
assert!(pascal!(onE_2_tHREE)());
}

#[test]
Expand Down