Keep punctuation attached to its word in ToTitleCase - #77
Merged
Merged
Conversation
ToTitleCase split before every non-letter, so punctuation became a word of its own and TextInfo.ToTitleCase capitalized the letter after it: "hello, world" came out as "Hello , World" and "don't stop" as "Don 'T Stop". In title case, break after a letter only before a digit, and treat an underscore as a word separator. A case change now starts a new word only after a letter or digit, so "(Hello" stays together. ToPascalCase and ToMacroCase strip punctuation before splitting, so their output is unchanged. Fixes #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018AEYBNCRr6chFLiZDv1MVj
|
This was referenced Sep 28, 2026
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.



Fixes #75
What was wrong
ToTitleCaseranSplitOnCaseChangeon the raw input. That function inserts a word boundary between a letter and any non-letter that follows it, so punctuation ended up as a word of its own.TextInfo.ToTitleCasethen capitalized the letter after it:hello, worldHello , WorldHello, Worlddon't stopDon 'T StopDon't Stopfoo_barFoo _BarFoo BarChange
SplitOnCaseChange/IsWordBoundarytake abreakBeforeAnyNonLetterflag. The existing single-argument overload passestrue, soToPascalCaseandToMacroCasestill get it.ToTitleCasepassesfalse, which means that after a letter it breaks only before a digit (abc123→Abc 123still works).ToTitleCase,_is mapped to a space first, as the issue suggests.-is left forTextInfo.ToTitleCase, which already treats it as a separator, sowell-knownbecomesWell-Known.fooBar) now starts a new word only when a letter or digit comes before it. Without this,(Hellosplit into( Hello.ToPascalCaseandToMacroCasereplace every non-alphanumeric with a space before splitting, so all this removes for them is a redundant double space that was already collapsed. Their existing tests pass unchanged.:,?and(and a guard that the case-change and digit splits still work in title case.Verification
dotnet test: 39/39 pass.dotnet build CaseConverter/CaseConverter.csprojsucceeds for every target framework with no warnings.This PR and #76 edit different functions in the same file, so either can merge first.
🤖 Generated with Claude Code
https://claude.ai/code/session_018AEYBNCRr6chFLiZDv1MVj
Generated by Claude Code