diff --git a/README.md b/README.md index 1dea27b..ed6a398 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/traits.rs b/src/traits.rs index 2efb62a..e61bc51 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -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; } @@ -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 { diff --git a/tests/integration.rs b/tests/integration.rs index db3209f..bf0aca1 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -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]