Skip to content

Trim before case-mapping the first char in ToUppercaseFirstChar/ToLowercaseFirstChar - #81

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/first-char-leading-whitespace
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/first-char-leading-whitespace

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #79

What was wrong

ToUppercaseFirstChar / ToLowercaseFirstChar mapped the first code point before trimming. When the input began with whitespace, the whitespace got case-mapped and then trimmed off, so the first letter was never changed: " hello".ToUppercaseFirstChar() returned "hello".

Change

  • Both helpers now run CollapseSpaces(input).Trim() first and then map the first code point. This keeps the astral-letter handling from Case-map an astral first letter in ToCamelCase and the first-char helpers #76.
  • I kept the space collapsing. The issue allowed keeping it if documented, and removing it would change the output for existing callers. The XML summaries now say the result is trimmed and has runs of spaces collapsed, and a remark explains that leading whitespace no longer takes the first letter's place.

Tests

  • ToUppercaseFirstCharShouldSkipLeadingWhitespace / ToLowercaseFirstCharShouldSkipLeadingWhitespace cover a leading space, a leading tab, and surrounding spaces.
  • FirstCharHelpersShouldCollapseRunsOfSpaces pins the space collapsing that is now documented.
  • With the fix reverted, all 6 new leading-whitespace cases fail. With the fix, the full suite passes: 50/50 on net10.0. The library builds cleanly for every target framework.

🤖 Generated with Claude Code

https://claude.ai/code/session_013qSqApi9HSiBjyHaJQYPTP


Generated by Claude Code

ToUppercaseFirstChar and ToLowercaseFirstChar mapped input[0] and only
then trimmed, so with leading whitespace the whitespace was "case-mapped"
and trimmed away while the first letter was left unchanged
(" hello" -> "hello"). They now collapse and trim first, then map the
first code point. The existing space collapsing is kept and now stated
in the XML summaries.

Fixes #79

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

ToUppercaseFirstChar/ToLowercaseFirstChar do nothing when the input starts with whitespace (" hello" → "hello")

1 participant