Skip to content

Split a single capital after a digit before an apostrophe in every converter [patch] - #162

Merged
matt-edmondson merged 3 commits into
mainfrom
fix/single-capital-after-digit-apostrophe-161
Nov 11, 2026
Merged

matt-edmondson merged 3 commits into
mainfrom
fix/single-capital-after-digit-apostrophe-161

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #161

What was wrong

"4K's price" gave snake 4ks_price but Title 4 K's Price, and the snake case of that Title output is 4_ks_price. So converting through Title case changed the words.

Before an in-word apostrophe, ReplaceNonAlphaNumericWithSpace uppercased the suffix onto the capital, giving 4KS. After a digit, that reads as an all-caps run, and IsWholeCapitalRun keeps such a run in the digit's word. Title case keeps the apostrophe, so it sees a single capital and breaks before it.

Change

The suffix is now left lowercase when the capital directly follows a digit or a caseless letter (new helper IsSingleCapitalAfterDigitOrCaselessLetter). Caseless letters are included because IsWordBoundary treats them the same way. Every converter now matches the no-apostrophe behaviour, which is the first option in the issue:

Input snake Title Pascal
4K's price 4_ks_price 4 K's Price 4KsPrice
3D's model 3_ds_model 3 D's Model 3DsModel
B2B's growth b_2_bs_growth B 2 B's Growth B2BsGrowth

Runs of two or more capitals (4KB's) and digit plurals (the 1990's, 4's and 5's) are unchanged.

Tests

  • New: ASingleCapitalAfterADigitBeforeAnApostropheShouldSplitTheSameEverywhere. It covers the issue's three rows plus a U+2019 row and 4K'ers. Each row checks Title, Pascal, camel, snake and MACRO, and also checks snake == Title→snake == Pascal→snake == camel→snake.
  • New: AnApostropheAfterADigitWordShouldKeepConvertersAgreeing. It is an invariant-only guard for 4KB's size, 名K's list, the 1990's and 4's and 5's.
  • With the fix reverted, 6 of the new cases fail: the five issue rows and 名K's list.
  • Full suite on Linux / .NET 10: 282/282 passed. dotnet build CaseConverter.sln builds every target with no warnings.

The open PR #160, which touches the apostrophe handling in the same file, is a separate change. The two may need a trivial rebase, depending on which lands first.


Generated by Claude Code

…nverter [patch]

"4K's price" gave snake "4ks_price" but Title "4 K's Price", whose snake is
"4_ks_price", so converting through Title case changed the words.

Before an in-word apostrophe, ReplaceNonAlphaNumericWithSpace uppercased the
suffix onto the capital ("4KS"). After a digit that read as an all-caps run,
which IsWholeCapitalRun keeps in the digit's word. Title case keeps the
apostrophe, saw a single capital, and broke before it. The suffix is now left
lowercase when the capital directly follows a digit or a caseless letter, so
every converter matches the no-apostrophe behaviour: snake "4_ks_price",
Pascal "4KsPrice", Title "4 K's Price". Runs of two or more capitals
("4KB's") and digit plurals ("the 1990's") are unchanged.

Fixes #161

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4bh3rDc6opLckXQGb
…ter-digit-apostrophe-161

# Conflicts:
#	CaseConverter/CaseConverter.cs
…ter-digit-apostrophe-161

# Conflicts:
#	CaseConverter/CaseConverter.cs
@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

2 participants