Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the inflector extension methods by adding optional acronym preservation to Pascalize and introducing a new CamelizeV2 for Google-style camel casing that properly handles acronyms.
- Adds a
preserveAcronymparameter and two private implementations (WithAcronymPreservation,WithoutAcronymPreservation) forPascalize - Introduces
CamelizeV2leveraging the new Pascalize behavior - Updates unit tests, public API approvals, and README documentation
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Humanizer/InflectorExtensions.cs | Added preserveAcronym parameter to Pascalize, new internal methods, and CamelizeV2 |
| src/Humanizer.Tests/InflectorTests.cs | Added tests for acronym-preserving/non-preserving Pascalize and for CamelizeV2 |
| src/Humanizer.Tests/ApiApprover/*.verified.txt | Updated public API approval files to include new overloads and CamelizeV2 |
| readme.md | Documented the acronym option in Pascalize and introduced a CamelizeV2 section |
Comments suppressed due to low confidence (3)
readme.md:654
- The README description refers to
Camelizebut this is in theCamelizeV2section; update the reference toCamelizeV2for clarity.
`Camelize` camelizes acronyms correctly, it is backwards incompatible with the way current Camelize works which is why introducing a new version
src/Humanizer/InflectorExtensions.cs:130
- [nitpick] Consider renaming
CamelizeV2to a more descriptive name likeCamelizeWithAcronymPreservationto avoid versioned API names and improve readability.
public static string CamelizeV2(this string input)
src/Humanizer.Tests/InflectorTests.cs:115
- Test name
PascalizeWithAcronymPreserveddoesn’t match the method namePascalizeWithAcronymPreservation; consider aligning the naming for consistency.
public void PascalizeWithAcronymPreserved(string input, string expectedOutput) =>
|
|
||
| /// <summary> | ||
| /// By default, pascalize converts strings to UpperCamelCase also removing underscores | ||
| /// For a word that are all upper case, this function by default assumes its an acronym and preserves the casing |
There was a problem hiding this comment.
[nitpick] The XML doc comment has a grammar issue: change 'For a word that are all upper case' to 'For words that are all uppercase' or 'For a word that is all uppercase'.
| /// For a word that are all upper case, this function by default assumes its an acronym and preserves the casing | |
| /// For a word that is all uppercase, this function by default assumes it's an acronym and preserves the casing |
| } | ||
| } | ||
|
|
||
| while (index < span.Length && (span[index] == ' ' || span[index] == '_' || span[index] == '-')) |
There was a problem hiding this comment.
[nitpick] Repeated checks for the same separator characters could be extracted into a helper method or constant to improve maintainability and reduce duplication.
| while (index < span.Length && (span[index] == ' ' || span[index] == '_' || span[index] == '-')) | |
| while (index < span.Length && IsSeparator(span[index])) |
|
Thank you for the contribution! Couple thoughts:
|
|
Thanks for the review !
Sounds good I can make that change
I initially thought of that but could not come up with an appropriate enum. The current way this function camel cases acronyms seems like a bug in the sense it doesn't adhere to any camel case standard that I could find which is why I didn't want to overload that further with an additional parameter. In order to think of an appropriate enum there needs to be a way to describe the current form. My preference would be to mark the current one as 'deprecated' to make it clear to existing clients that there is a more correct version available that they can migrate to. I can change |
|
I like |
Here is a checklist you should tick through before submitting a pull request:
mainbranch (more info below)Camelize()does not respect acronyms #1301 and fixes Let us configure Humanizer to treat acronyms as words #1534build.cmdorbuild.ps1and ensure there are no test failures