Repository navigation
Conversation
The boundary lookarounds used an ASCII-only class ([a-zA-Z0-9]), so any non-ASCII letter counted as a word boundary and replacement rules could match inside words: an ERN -> EAN rule corrupted "vergrößern" into "vergrößEAN" (Beingpax#756). Word chars are now Unicode letters/marks/digits, minus the non-spaced scripts — via Script_Extensions so shared marks like the prolonged sound mark U+30FC stay exempt — mirroring the usesWordBoundaries exemptions. Punctuation boundaries and punctuation-ending triggers (c++) keep working, and Latin triggers flush against CJK/Thai text still match.
jonahclarsen
pushed a commit
to jonahclarsen/VoiceInk
that referenced
this pull request
Aug 16, 2026
…nt-unicode-boundaries fix: Unicode-aware word boundaries in word replacements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #756.
Problem: The word-boundary lookarounds in
WordReplacementServiceuse an ASCII-only class ([a-zA-Z0-9]), so every non-ASCII letter (ß, ö, é, Cyrillic, etc.) is treated as a word boundary. A rule likeERN → EANthen matches the tail of the German word vergrößern (the character before "ern" is ß) and corrupts it to vergrößEAN, exactly as reported. Introduced in 620a843 when\bwas replaced with the ASCII lookarounds.Fix: The word-character class is now Unicode letters/marks/digits, minus the non-spaced scripts (Han, Hiragana, Katakana, Hangul, Thai), mirroring the existing
usesWordBoundariesexemptions, so Latin triggers sitting flush against CJK/Thai text still match. The subtraction usesscx=(Script_Extensions) rather thanScript=so shared marks like the prolonged sound mark ー (U+30FC, Script=Common) stay exempt and triggers flush against katakana loanwords (サーバーapi) keep matching. The lookaround structure is kept (not reverted to\b), so triggers ending in punctuation likec++keep working, which is why 620a843 moved off\bin the first place.3 changed code lines in one file; all three call sites route through this method.
Verification (standalone harness that copies the pattern construction verbatim, 19 cases):
Before:
After: those stay intact, and existing behavior is preserved:
Full 19-case harness (run: swift word_replacement_boundary_check.swift, add --old for the current pattern)