Description
Generate bounded LF-oriented unified text hunks with exact insertion/deletion ranges, preserved CR content and missing-final-newline markers, reusing the existing LCS tie convention without filesystem access or GNU byte-for-byte equivalence.
A unified diff represents line changes as hunks, with unchanged context surrounding removed and added lines. Hunk ranges refer separately to the old and new text, and final newline presence can itself be a meaningful difference.
Generate bounded LF-oriented unified text hunks with exact insertion/deletion ranges, preserved CR content and missing-final-newline markers, reusing the existing LCS tie convention without filesystem access or GNU byte-for-byte equivalence.
When to use this tool
Use this tool to inspect line changes between two supplied texts with unified hunk ranges, context, and final-newline evidence.
How to use the tool and how it works
- Supply before, after, contextLines, oldLabel, newLabel in the field shapes below.
- Run the calculation. Correct format, shape, range, or undefined-statistic errors before interpreting a result.
- Read addedLines, changed, diff, hunkCount, removedLines. Use the conventions below.
Split both strings at LF while retaining CR as content and recording whether each final line has a newline. Encode complete line identities, obtain a longest common subsequence, and emit deletions, additions and unchanged context. Merge touching context windows into hunks and calculate old/new ranges from consumed-line counts; emit missing-final-newline markers where needed.1
Delegated operations used for this result: longest common subsequence. Their calculation or parsing conventions apply to the corresponding result fields.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| before | Before | Required. Text; maximum UTF-16 length 16384. |
| after | After | Required. Text; maximum UTF-16 length 16384. |
| contextLines | Context Lines | Optional. Safe integer; minimum 0; maximum 20; default 3. |
| oldLabel | ASCII path-like display label, not a filesystem operation; timestamps are omitted. | Optional. Text; minimum UTF-16 length 1; maximum UTF-16 length 128; default "a/input.txt". |
| newLabel | ASCII path-like display label, not a filesystem operation; timestamps are omitted. | Optional. Text; minimum UTF-16 length 1; maximum UTF-16 length 128; default "b/input.txt". |
| Output field | Interpretation | Returned shape |
|---|---|---|
| addedLines | Added Lines | Required. Safe integer; minimum 0; maximum 256. |
| changed | Changed | Required. Boolean. |
| diff | Diff | Required. Text; maximum UTF-16 length 65536. |
| hunkCount | Hunk Count | Required. Safe integer; minimum 0; maximum 512. |
| removedLines | Removed Lines | Required. Safe integer; minimum 0; maximum 256. |
{
"input": {
"before": "alpha\nbeta\ngamma\n",
"after": "alpha\nBETA\ngamma\ndelta\n",
"contextLines": 1
},
"output": {
"addedLines": 2,
"changed": true,
"diff": "--- a/input.txt\n+++ b/input.txt\n@@ -1,3 +1,4 @@\n alpha\n-beta\n+BETA\n gamma\n+delta\n",
"hunkCount": 1,
"removedLines": 1
}
} Limitations and assumptions
- Each input has at most 256 LF-delimited lines. Labels are display text, not file operations. Identical inputs return changed=false and an empty diff; repeated-line choices follow the linked LCS convention rather than promising GNU byte-for-byte output.
- The field tables state structural bounds; cross-field constraints and bounded search or output budgets also apply. Unknown keys are rejected where the object contract disallows them. Input errors are distinct from null fields and deliberate invalid controls in a successful output.
Alternative or Complementary methods
Choose the statistic according to the question and data conventions. Inspect the supplied series or matrix and the stated assumptions before comparing outputs from implementations with different defaults.
References
Similar or alternative tools
- levenshtein
Minimum number of single-character insertions, deletions or substitutions needed to turn one string into another.
- string distance matrix
Generate caller-based Unicode-code-point strings using bounded feasible insertion/deletion/substitution/adjacent-swap edits and retain edit records, identity labels, and delegated pairwise Levenshtein/optimal-string-alignment matrices plus JSON; edit count is not minimum distance and OSA is not unrestricted Damerau distance.