Skip to content

Keep a zero-width joiner, non-joiner or soft hyphen inside its word [patch] - #147

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/145-format-chars-in-word
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/145-format-chars-in-word

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #145

What changed

  • New IsFormatCharacterWithinWord: a single-UTF-16-unit UnicodeCategory.Format character with a letter on each side. The letter before it may carry combining marks, as the virama of क्‍ष does. U+200B ZERO WIDTH SPACE is excluded because it marks a word break.
  • IsCombiningMark now means "part of the letter before it", covering marks (now IsMark) and these format characters. That one change carries the fix through ReplaceNonAlphaNumericWithSpace, IsWordBoundary, IsWordCharacter, and the skip-over/skip-back helpers.
  • TitleCaseKeepingTypographicApostrophes swaps an in-word format character for ' around TextInfo.ToTitleCase and puts it back afterwards, the same way it already handles an in-word U+2019. This stops "cooperate" becoming "CoOperate".
Input Before After
Persian میخواهم (ZWNJ) snake می_خواهم, Pascal drops the ZWNJ one word, ZWNJ kept
क्‍ष (ZWJ) snake क्_ष one word
cooperate Title/Pascal CoOperate, snake co_operate Cooperate / cooperate

The issue lists stripping the soft hyphen from joined outputs as optional. This PR doesn't do it: the character is kept, so every converter preserves what the input contained.

Tests

  • AFormatCharacterInsideAWordShouldNotSplitIt covers each of the three inputs in every converter.
  • AFormatCharacterInsideAWordShouldStayInThatWord covers the same words next to another word.
  • AFormatCharacterNotBetweenLettersShouldStillSeparateWords keeps U+200B, a leading or trailing soft hyphen, and a ZWNJ between spaces acting as separators.
  • Without the fix, 5 of the new rows fail. With it, the full suite passes (218/218), and the solution builds for every target framework.

This branch is cut from main independently of #146 (#144). The two touch different functions.


Generated by Claude Code

…patch]

Every character that is not a letter, mark or digit became a word break, which
included format characters that sit inside a word: the ZWNJ of Persian
"می‌خواهم", the ZWJ of a Devanagari conjunct, and a soft hyphen. One word split
into two ("co­operate" gave snake "co_operate"), and TextInfo.ToTitleCase
capitalised the letter after them ("CoOperate").

A single-unit format character with a letter on each side (the letter before
may carry combining marks) is now treated like a combining mark, and is swapped
for an apostrophe around TextInfo.ToTitleCase the way an in-word U+2019 already
is. The zero-width space still separates words.

Fixes #145

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

2 participants