Skip to content

Pascal/Camel/Snake/Kebab/Macro split words at an apostrophe: "don't stop" → "DonTStop" / "don_t_stop" #83

Description

@matt-edmondson

What's wrong

CaseConverter/CaseConverter.cs:35-56, ReplaceNonAlphaNumericWithSpace, turns an apostrophe into a space. It is used by the Pascal/Camel path (~line 327) and by the Snake/Kebab/Macro path (~line 399). The letters after an apostrophe therefore become a separate word:

Input Method Actual Expected
"don't stop" ToPascalCase "DonTStop" "DontStop"
"don't stop" ToCamelCase "donTStop" "dontStop"
"don't stop" ToSnakeCase "don_t_stop" "dont_stop"
"don't stop" ToMacroCase "DON_T_STOP" "DONT_STOP"
"o'neil" ToPascalCase / ToSnakeCase "ONeil" / "o_neil" "Oneil" / "oneil"

Reproduced with MSTest asserts.

Why it matters

Generating identifiers, slugs or constant names from human text such as UI labels or titles is a primary use case, and contractions are common in that text. ToTitleCase was fixed in d8bdab2 to keep "Don't" as one word, so the sibling methods now disagree with it. Lodash and similar libraries strip in-word apostrophes (lodash's reApos step) for this reason.

Suggested fix

In ReplaceNonAlphaNumericWithSpace, drop ' and U+2019 (right single quotation mark) when they sit between two letters, instead of replacing them with a space. Apostrophes elsewhere (leading or trailing quotes) can keep acting as separators.

Acceptance: every row above produces the expected output, with tests for both the ASCII ' and U+2019.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions