Skip to content

Normalize an all-caps word joined by '-', '.' or a tab in ToTitleCase [patch] - #86

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/82-titlecase-all-caps-runs
Sep 28, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/82-titlecase-all-caps-runs

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #82

What changed

LowercaseAllCapsWords split its input only on ' '. TextInfo.ToTitleCase also treats -, . and tabs as word boundaries, and it keeps any all-caps word it finds as an acronym. So an all-caps segment inside a space-delimited token that also had lowercase letters was never lowercased first.

It now lowercases each maximal run of letters and apostrophes that is entirely uppercase. That is the unit TextInfo treats as a word, so each word converts the same way whatever sits next to it.

Input Before After
foo-BAR Foo-BAR Foo-Bar
FOO-BAR Foo-Bar Foo-Bar
API-key API-Key Api-Key
foo.BAR Foo.BAR Foo.Bar
HELLO\tworld HELLO\tWorld Hello\tWorld
HELLO world Hello World Hello World

Apostrophes count as part of a word, so DON'T stop still becomes Don't Stop.

Tests

  • ToTitleCaseShouldNormalizeAllCapsWordsJoinedByPunctuationOrTabs covers every row in the issue plus DON'T stop. With the fix reverted, exactly the four broken rows fail.
  • The existing ToTitleCase tests, including the punctuation cases from d8bdab2, still pass. The full suite passes (57 tests), and the solution builds for every target framework.

This branch is independent of #85 (the apostrophe fix for #83). The two PRs touch different helpers in CaseConverter.cs and merge cleanly in either order.

🤖 Generated with Claude Code

https://claude.ai/code/session_012mvcqKMc35CMobct1fmizc


Generated by Claude Code

… [patch]

LowercaseAllCapsWords split only on spaces, but TextInfo.ToTitleCase also
treats '-', '.' and tabs as word boundaries and keeps an all-caps word it
finds there. So "foo-BAR" became "Foo-BAR" while "FOO-BAR" became
"Foo-Bar". It now lowercases each all-caps run of letters and
apostrophes, which is what TextInfo treats as a word.

Fixes #82

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012mvcqKMc35CMobct1fmizc
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToTitleCase keeps an all-caps word unchanged when it's joined by '-', '.' or a tab: "foo-BAR" → "Foo-BAR" but "FOO-BAR" → "Foo-Bar"

2 participants