Skip to content

Keep a plural acronym in one piece: "APIs" no longer splits as "AP Is" [patch] - #102

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/99-plural-acronyms
Sep 29, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/99-plural-acronyms

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #99

What changed

IsWordBoundary has an acronym-tail rule: it breaks before the last capital of an uppercase run when a lowercase letter follows it, so XMLDoc becomes XML Doc. The rule also fired on plural acronyms, where that lowercase letter is just the plural s.

A new IsPluralSuffix check exempts a lone s that ends its word. The word ends when the s is followed by the end of the string, a non-letter, or a capital. A longer lowercase run is still a real word, so HTTPServer, HTMLParser, ABCdef and IOStream split exactly as before.

Input Call Before After
APIs ToSnakeCase() ap_is apis
URLs ToPascalCase() UrLs Urls
getIDs ToSnakeCase() get_i_ds get_ids
the URLs list ToTitleCase() The Ur Ls List The Urls List
PDFsAndDOCs ToSnakeCase() pd_fs_and_do_cs pdfs_and_docs

This also brings the plural in line with the possessive form fixed in #93, where API's already gives apis.

Testing

  • New tests:
    • APluralAcronymShouldStayOneWord covers every input from the issue, plus GUIDs_2, across Pascal, Camel, Snake, Kebab, Macro and Title.
    • AnAcronymFollowedByAWordShouldStillSplit pins the boundary: HTTPServer, XMLDoc, HTMLParser, ABCdef, IOStream and URLsList.
  • With the source change reverted, 7 tests fail. With it, all 97 pass on net10.0.
  • dotnet build CaseConverter.sln builds every target (net10.0/9.0/8.0, netstandard2.0/2.1) with 0 warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AtF6Ynq3K6Km6HSRHaKuX8


Generated by Claude Code

…" [patch]

The acronym-tail rule breaks before the last capital of an uppercase run
when a lowercase letter follows it, so that "XMLDoc" becomes "XML Doc".
It also fired on a plural acronym, where the lowercase letter is only
the plural "s", so "getIDs" became "get_i_ds". Don't break when that
lowercase run is a lone "s" ending the word: followed by the end of the
string, a non-letter or a capital. "HTTPServer" still splits.

Fixes #99

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

Plural acronyms split mid-word: "APIs".ToSnakeCase() = "ap_is", "URLs".ToPascalCase() = "UrLs" (while "API's" → "apis")

2 participants