-
Notifications
You must be signed in to change notification settings - Fork 1k
Preserve ALL-CAPS pluralization for multi-letter inputs #1670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,9 +195,36 @@ | |
| bool IsUncountable(string word) => | ||
| uncountables.Contains(word); | ||
|
|
||
| static string MatchUpperCase(string word, string replacement) => | ||
| char.IsUpper(word[0]) && | ||
| char.IsLower(replacement[0]) ? StringHumanizeExtensions.Concat(char.ToUpper(replacement[0]), replacement.AsSpan(1)) : replacement; | ||
| static string MatchUpperCase(string word, string replacement) | ||
| { | ||
| var lettersCount = 0; | ||
| var allLettersUpper = true; | ||
| foreach (var c in word) | ||
| { | ||
| if (char.IsLetter(c)) | ||
| { | ||
| lettersCount++; | ||
| if (!char.IsUpper(c)) | ||
| { | ||
| allLettersUpper = false; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If the input contains multiple letters and all of them are uppercase | ||
| // (e.g. an ALL CAPS phrase or acronym of length > 1), return the replacement | ||
| // fully uppercased so the plural suffix matches the input casing. | ||
| if (lettersCount > 1 && allLettersUpper) | ||
| { | ||
| return replacement.ToUpperInvariant(); | ||
|
Comment on lines
+218
to
+220
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On all-caps inputs, Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| return char.IsUpper(word[0]) && char.IsLower(replacement[0]) | ||
| ? StringHumanizeExtensions.Concat(char.ToUpper(replacement[0]), replacement.AsSpan(1)) | ||
| : replacement; | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// If the word is the letter s, singular or plural, return the letter s singular | ||
|
|
||
Check notice
Code scanning / CodeQL
Missed opportunity to use All Note