Skip to content

Keep the letter after a typographic apostrophe lowercase in ToTitleCase [patch] - #91

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/title-case-typographic-apostrophe
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/title-case-typographic-apostrophe

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #89

What was wrong

TextInfo.ToTitleCase keeps the letter after an ASCII ' lowercase, but treats U+2019 (the typographic apostrophe) as a word separator. So "don’t stop".ToTitleCase() gave Don’T Stop, although the rest of the library (IsApostropheWithinWord, IsWordCharacter) already treats U+2019 the same as '.

Change

ToTitleCase now calls a new TitleCaseKeepingTypographicApostrophes helper. It swaps each in-word U+2019 (one with a letter on each side, as decided by IsApostropheWithinWord) for ', runs TextInfo.ToTitleCase, and then puts U+2019 back at the same indices. TextInfo.ToTitleCase does not change the string's length, so restoring by index is safe. A U+2019 used as a quote mark, and so not inside a word, is left alone and still separates words.

Tests

ToTitleCaseShouldKeepATypographicApostropheInsideItsWord:

  • "don’t stop" → Don’t Stop
  • "it’s fine" → It’s Fine
  • "’quoted’ word" → ’Quoted’ Word (a quote-mark U+2019 still separates words)

With CaseConverter.cs reverted, the first two rows fail. With the change, all 68 tests pass on net10.0, and the solution builds for every target with 0 warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N3tMVtLPuNwsQF7rUEBTMQ


Generated by Claude Code

…se [patch]

TextInfo.ToTitleCase only special-cases the ASCII apostrophe, so an in-word
U+2019 was treated as a word separator: "don’t stop" became "Don’T Stop".
Swap each in-word U+2019 for ' before the call and restore it by index after.

Fixes #89

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N3tMVtLPuNwsQF7rUEBTMQ
@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 capitalizes the letter after a U+2019 apostrophe: "don’t stop" -> "Don’T Stop"

2 participants