Fix casing of O'Brien / d'Artagnan style names in all-caps input - #101
Open
afonsojanu wants to merge 1 commit into
Open
Fix casing of O'Brien / d'Artagnan style names in all-caps input#101afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
When a whole line is shouted in caps, titlecase lowercases each word before recapitalizing it, except for words caught by the apostrophe rule (d', l', o' style names). That branch only fixed up the two letters around the apostrophe and left everything after them exactly as it came in, so "O'BRIEN'S HOUSE" turned into "O'BRIEN'S House" instead of "O'Brien's House", and "D'ARTAGNAN" came out as "d'ARTAGNAN". Downcase the remainder of the word first when the line is all caps, same as the other word-handling branches already do, before applying the apostrophe-specific capitalization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While running some all-caps headlines through titlecase I noticed names with an apostrophe in the second position come out wrong:
Everything else in the sentence gets shouted-caps normalized before recapitalization, but the word itself stays untouched past the second letter.
The
APOS_SECONDbranch only ever touches the letter right after the apostrophe (word[2]) and appends the rest of the word unchanged. That's fine for mixed-case input, which the library deliberately leaves alone (there's an existing test forl'GranGestaying as-is). But when the whole line is in caps, every other branch in the loop lowercases the word first so recapitalizing produces a normal title-case word, and this branch skips that step, so the tail of the word is left shouting.Fix downcases the remainder of the word before recapitalizing it, but only when
all_capsis true, so the existing mixed-case behavior is untouched:Added two cases to
TEST_DATAcovering both the vowel-prefix (O') and consonant-prefix (D') paths through this branch. Confirmed both fail against the old code and pass with the fix; the rest of the suite (including the existing mixed-case apostrophe cases) is unaffected.