utils/diff/diff_utils library

Diff utilities for computing, formatting, and applying text diffs.

Provides line-level, word-level, and character-level diffing, patch creation/application, and semantic grouping of changes.

Classes

ChangeBlock
A contiguous block of related changes.
CharDiff
A character-level diff element.
DiffStats
Summary statistics for a diff.
Hunk
A single hunk in a patch.
LineDiff
A single line in a line-level diff.
PatchResult
Result of applying a patch.
PatchSet
A set of hunks that together describe a transformation.
SemanticDiff
Groups related diff lines into logical change blocks.
WordDiff
A word-level diff element.

Enums

DiffType
The type of a diff element.
EditOp
Primitive edit operation used by shortest-edit-script.

Functions

applyPatch(String text, PatchSet patch) PatchResult
Apply a patch to text, returning a PatchResult.
computeCharDiff(String oldStr, String newStr) List<CharDiff>
Compute a character-level diff between oldStr and newStr.
computeLineDiff(String oldText, String newText) List<LineDiff>
Compute a line-level diff between oldText and newText.
computeWordDiff(String oldLine, String newLine) List<WordDiff>
Compute a word-level diff between oldLine and newLine.
createPatch(String oldText, String newText, {int contextLines = 3}) PatchSet
Create a PatchSet from oldText to newText.
diffStats(String oldText, String newText) DiffStats
Compute DiffStats between oldText and newText.
formatPatch(PatchSet patch) String
Format a PatchSet as a unified diff string.
generateSummary(List<LineDiff> diffs) String
Generate a human-readable summary from a list of LineDiffs.
longestCommonSubsequence<T>(List<T> a, List<T> b) List<T>
Compute the longest common subsequence of two lists.
shortestEditScript<T>(List<T> a, List<T> b) List<EditOp>
Compute the shortest edit script (Myers' algorithm simplified).