string/text_diff_structured_utils library

Structured diff of two texts by sentences and by words — roadmap #415.

Produces a UI-friendly edit script (a list of equal/insert/delete ops in order) rather than a rendered string, so a caller can color, animate, or summarize the changes. The generic diffSequences engine is reused for both the word-level and sentence-level conveniences.

Classes

SeqDiffOp<T>
One step of an edit script: a kind and the value it applies to.

Enums

SeqDiffKind
The kind of change an edit-script step represents.

Functions

diffSentences(String oldText, String newText) List<SeqDiffOp<String>>
Sentence-level structured diff of oldText vs newText, reusing tokenizeSentences to split on sentence boundaries. Audited: 2026-06-12 11:26 EDT
diffSequences<T>(List<T> a, List<T> b) List<SeqDiffOp<T>>
Computes the LCS-based edit script that turns a into b: a list of equal / delete / insert ops in input order. delete items appear only in a, insert items only in b, and the equal items are their longest common subsequence. O(n·m) time and space. Audited: 2026-06-12 11:26 EDT
diffWords(String oldText, String newText) List<SeqDiffOp<String>>
Word-level structured diff of oldText vs newText, reusing tokenizeWords to split into words (punctuation stripped). Audited: 2026-06-12 11:26 EDT