Skip to content

Treat a titlecase digraph as a capital when splitting words [patch] - #158

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/156-titlecase-digraph-boundary
Nov 4, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/156-titlecase-digraph-boundary

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #156
Fixes #106

The triage on #156 asked for both to be fixed together, so a single rule for TitlecaseLetter covers both directions.

What was wrong

Dž, Lj, Nj and Dz are in category Lt, so char.IsUpper returns false for them and the word splitter treated them as lowercase.

Input Call Before After
"MsDž" ToPascalCase() Msdž MsDž (idempotent)
"msDž" ToSnakeCase() msdž ms_dž
"LjubljanaLjubljana" ToPascalCase() Ljubljanaljubljana unchanged
"DžEMAL" ToSnakeCase() / ToKebabCase() dž_emal / dž-emal džemal
"DžEMAL" ToMacroCase() DŽ_EMAL DŽEMAL
"DžEMAL" ToTitleCase() Dž Emal Džemal

Change

  • New IsUpperOrTitlecase helper. IsWordBoundary (previousIsUpper / currentIsUpper) and EndsWordThatIsNotUppercase use it instead of char.IsUpper.
  • IsAllCaps (public): a titlecase digraph followed directly by a capital no longer stops a string from being all caps. Without this, "DžEMAL" stayed as DžEMAL under title and Pascal case instead of becoming Džemal the way "DŽEMAL" does. A lone Dž, Džemal and ADž are still not all caps. The XML doc states the new rule.

Tests

With the source change reverted, 7 of these fail. With it, the full suite passes (221/221, net10.0).

Heads-up: the triage noted that open PRs #141, #143, #146, #147, #152, #153 and #155 also change the word-boundary code. This PR only changes three char.IsUpper call sites and adds two helpers, so any conflict should be small.


Generated by Claude Code

Dž, Lj, Nj and Dz are in category Lt, so char.IsUpper is false for them and the
word splitter read them as lowercase. That broke words in both directions:

- "msDž" (what ToPascalCase writes for "ms DŽ") had no boundary before the
  digraph, so ToPascalCase was not idempotent ("MsDž" -> "Msdž") and
  ToSnakeCase lost a word ("msdž" instead of "ms_dž"). (#156)
- "DžEMAL" had a camel hump after the digraph, so it split into "dž_emal",
  "DŽ_EMAL" and "Dž Emal". (#106)

IsWordBoundary and EndsWordThatIsNotUppercase now count Lt as uppercase, so
one rule covers both directions. IsAllCaps also treats a titlecase digraph
followed directly by a capital as caps, so "DžEMAL" title-cases to "Džemal" the
same way "DŽEMAL" does. A lone "Dž" or "Džemal" is still not all caps.

Fixes #156
Fixes #106

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5pQJXg15qnY2s2Kwt
# Conflicts:
#	CaseConverter/CaseConverter.cs
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit d1365df into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/156-titlecase-digraph-boundary branch November 4, 2026 02:45
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