Skip to content

Stream text deltas by Unicode scalars, not Characters (#315) - #342

Closed
stikves wants to merge 1 commit into
apple:mainfrom
stikves:sukru/fix-issue-315
Closed

stikves wants to merge 1 commit into
apple:mainfrom
stikves:sukru/fix-issue-315

Conversation

@stikves

@stikves stikves commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #315. Fix authored by @iannellomarco (cherry-picked, authorship preserved).

A token that extends the previous grapheme cluster (a ZWJ joining another emoji, a combining mark, an Indic vowel sign/virama) leaves the Swift Character count unchanged. The streaming strategies then mis-detected "no new text" — VanillaDecodingStrategy re-emitted the whole line so far and dropped the trailing text in flushTrailingText; the two constrained strategies re-emitted the extended grapheme via a Character-wise common prefix. Compare and slice the delta by Unicode scalars in all three places; StreamingTextDeltaTests streams such text one UTF-8 byte per token through each strategy.

This fixes the delta correctness (deltas now concatenate to the decoded text). It does not change that streaming re-decodes the full token sequence each step — tracked separately in #341 (incremental scalar detokenizer).

A token that extends the previous grapheme cluster (a ZWJ joining another
emoji, a combining mark, an Indic vowel sign or virama) leaves the
Character count unchanged. VanillaDecodingStrategy then failed its
count/hasPrefix test and re-emitted the whole line so far, and dropped the
trailing text in flushTrailingText; the two constrained strategies took a
Character-wise commonPrefix and re-emitted the extended grapheme.

Compare and slice Unicode scalars in all three places, and add tests that
stream such text one UTF-8 byte per token through each strategy.

(cherry picked from commit e3f5c0c)
@tjia1818 tjia1818 closed this Oct 12, 2026
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.

[Swift runtime] Streamed text re-emits text when a token extends the previous grapheme (ZWJ emoji, combining marks, Indic signs)

3 participants