Skip to content

Keep a plural acronym whole before a contraction [patch] - #160

Open
matt-edmondson wants to merge 5 commits into
mainfrom
claude/caseconverter-159-plural-contraction
Open

matt-edmondson wants to merge 5 commits into
mainfrom
claude/caseconverter-159-plural-contraction

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #159

What was wrong

ReplaceNonAlphaNumericWithSpace joins an in-word apostrophe out before SplitOnCaseChange runs, so CEOs've reached the splitter as CEOsve. An s followed by more lowercase letters doesn't count as a plural (IsPluralSuffix), so the acronym-tail rule broke before the O:

Input Snake before Snake after
CEOs've / CEOs’ve ce_osve ceosve
VIPs're here vi_psre_here vipsre_here
DJs'll play d_jsll_play djsll_play
MCs'll m_csll mcsll
CEOs'VE ce_osve ceosve

Change

In ReplaceNonAlphaNumericWithSpace, a new branch applies when an in-word apostrophe:

  • follows the s of a run of two or more capitals (new IsPluralAcronymEndingAt), and
  • is followed by a contraction that is all lowercase or all caps.

In that case the s and the contraction are uppercased, the same way CEO's already becomes CEOS, so the splitter sees one all-caps word. A single capital (Ms're) is left alone, because it never split. ToTitleCase takes a separate path and is unchanged.

The all-caps contraction (CEOs'VE) wasn't in the issue but has the same split, so I covered it in the same branch.

Tests

  • PluralAcronymBeforeAContractionShouldStayOneWord checks every row of the issue for Title, Pascal, camel, snake, kebab and macro, with both ' and U+2019.
  • FormsNextToAPluralAcronymContractionShouldKeepTheirWords pins the neighbouring forms the issue asked to keep: APIs, CEOs, CEO's, CEOs' office, VIPS're, Vips're, O'Reilly, UserIDIsValid, Ms're, CEOS'VE.

Verification:

  • With the fix reverted, 9 of the new cases fail.
  • With it, the full suite passes: 292/292 on net10.0.
  • dotnet build -c Release of the library across all TFMs succeeds with no warnings.

#109, the double-apostrophe case, touches the same apostrophe-joining path. Whichever PR lands second should rebase and rerun both sets of tests.


Generated by Claude Code

With the apostrophe joined out, "CEOs've" reached the word splitter as
"CEOsve". An "s" with more lowercase after it is not a plural, so the
acronym-tail rule broke before the "O": snake "ce_osve", Pascal
"CeOsve", macro "CE_OSVE". The same happened to "VIPs're", "DJs'll",
"MCs'll", with U+2019 too, and to an all-caps contraction ("CEOs'VE").

When an in-word apostrophe follows the "s" of a run of two or more
capitals and the contraction is all lowercase or all caps, the "s" and
the contraction are now uppercased, the way "CEO's" already becomes
"CEOS", so the word stays whole: "ceosve", "Ceosve", "CEOSVE".

Fixes #159

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3Ri1HBoN2geG4RgBi
SonarCloud flagged ReplaceNonAlphaNumericWithSpace at a cognitive
complexity of 18 (S3776, limit 15) once the plural-acronym branch was
added. The casing decided at an in-word apostrophe now lives in
CaseSuffixAfterApostrophe, which returns the three flags, with no change
in behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3Ri1HBoN2geG4RgBi
Resolve the conflict with #163 in ReplaceNonAlphaNumericWithSpace:
CaseSuffixAfterApostrophe keeps the plural-acronym branch and now takes
its uppercase decision from main's UppercasesSuffix, so a later lowercase
suffix of an uppercased word stays uppercased (#109).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4bDHFRUmCXATBKDFr
Resolve the conflict in ReplaceNonAlphaNumericWithSpace: keep the PR's
CaseSuffixAfterApostrophe helper and carry main's new all-caps-suffix-after-
a-single-capital-after-a-digit rule (#174) into it, and keep both
IsPluralAcronymEndingAt and main's AppendMarkIfItHasABase. 359/359 tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3gbT4qC2ULvUvM9Dr
@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