Skip to content

Keep a contraction's plural after a capital run in one word [patch] - #169

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/capital-run-before-apostrophe-plural-165
Nov 11, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/capital-run-before-apostrophe-plural-165

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #165

What was wrong

"DON'Ts" snaked to do_nts, and "the DOs and DON'Ts" snaked to the_dos_and_do_nts. Title case gives Don'ts, so converting through Title case changed the words.

The steps that produced it:

  1. The suffix Ts is not all lowercase, so it was not uppercased onto the capital before the apostrophe.
  2. The O'Neil rule then lowered the T, leaving DONts.
  3. SplitOnCaseChange read that as the acronym DO followed by Nts.

Change

This takes the fix the issue proposed, written as two small helpers, EndsCapitalRun and IsCapitalThenLowercase. Both step back and forward by code point and over combining marks, as the neighbouring helpers do.

The new rule: when the capital before the apostrophe ends a run of two or more capitals, and the suffix is one capital followed only by lowercase letters, the suffix is uppercased too. That gives DONTS, which is what DONTs and DON'TS already give.

When only one capital comes before the apostrophe, as in O'Neil, the O'Neil rule still applies.

Input snake Pascal Title
DON'Ts / DON’Ts donts Donts Don'ts
CAN'Ts cants Cants
ABC'Ds abcds Abcds
the DOs and DON'Ts the_dos_and_donts TheDosAndDonts
O'Neil, DON'T stop, CEO's unchanged

Tests

  • New: AContractionPluralAfterACapitalRunShouldStayOneWord. It covers the five acceptance-criteria inputs, including U+2019.
  • Each row checks Pascal, camel, snake, kebab and MACRO, and also checks Title→snake == snake.
  • On unfixed main, all 5 rows fail.
  • The existing O'Neil, o'NEIL, CEO's and DON'T rows still pass.
  • Full suite on Linux / .NET 10: 278/278 passed. dotnet build CaseConverter.sln gives 0 warnings and 0 errors.

The open PRs #160, #162, #163 and #168 also touch the apostrophe branch of ReplaceNonAlphaNumericWithSpace. As the triage noted, whichever lands last should rebase and rerun the full suite.


Generated by Claude Code

"DON'Ts" snaked to "do_nts" and "the DOs and DON'Ts" to
"the_dos_and_do_nts", while Title case gives "Don'ts". The suffix "Ts"
is not all lowercase, so it was not uppercased onto the capital before
the apostrophe; the O'Neil rule then lowered the "T", leaving "DONts",
which SplitOnCaseChange reads as the acronym "DO" plus "Nts".

When the capital before the apostrophe ends a run of two or more
capitals and the suffix is one capital followed only by lowercase
letters, the suffix is now uppercased too, giving "DONTS" as "DONTs" and
"DON'TS" already do. A single capital before the apostrophe ("O'Neil")
keeps the O'Neil rule.

Fixes #165

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

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit d39db03 into main Nov 11, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/capital-run-before-apostrophe-plural-165 branch November 11, 2026 00:02
matt-edmondson pushed a commit that referenced this pull request Nov 11, 2026
Resolve the test-file conflict with #169: both added a test method at the end of the class, so keep both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW2QxLJ6PwV5nQrv4Us
matt-edmondson pushed a commit that referenced this pull request Nov 11, 2026
#169 widened the condition that uppercases a suffix onto the capital
before an in-word apostrophe, which took ReplaceNonAlphaNumericWithSpace
to a cognitive complexity of 17 (Sonar S3776, limit 15) and fails the
quality gate. The condition now lives in IsSuffixUppercasedOntoCapital;
behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW2QxLJ6PwV5nQrv4Us
matt-edmondson added a commit that referenced this pull request Nov 11, 2026
* Keep a titlecase digraph after an apostrophe in its word [patch]

"a'Džemal" snaked to "a_džemal" while the two-letter spelling "a'Džemal"
gives "adžemal". IsCapitalAfterApostropheInLowercaseContext tested
char.IsUpper on the letter after the apostrophe, which is false for a
titlecase digraph (category Lt), so the O'Neil rule never lowered it.
SplitOnCaseChange then saw a lowercase-to-titlecase change and broke the
word. The test now uses IsUpperOrTitlecase, as SplitOnCaseChange has since
#158, so "a'Džemal" and "l'Ljubljana" give the same words as their
two-letter spellings in every converter.

Fixes #167

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

* Move the apostrophe-suffix uppercase test into its own helper [patch]

#169 widened the condition that uppercases a suffix onto the capital
before an in-word apostrophe, which took ReplaceNonAlphaNumericWithSpace
to a cognitive complexity of 17 (Sonar S3776, limit 15) and fails the
quality gate. The condition now lives in IsSuffixUppercasedOntoCapital;
behaviour is unchanged.

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
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