Help us shape the future of Go! Take the 2026 Go Developer Survey

diff

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapOldLineToNew

func MapOldLineToNew(entries []DiffEntry) map[int]int

MapOldLineToNew builds a mapping from old line numbers to new line numbers using the diff entries. For unchanged lines it maps directly. For removed lines it maps to the nearest subsequent new line in the new document. Returns a map[int]int where key=old line, value=new line.

func SplitLines

func SplitLines(content string) []string

SplitLines splits content into lines, returning an empty slice for empty input.

Types

type DiffEntry

type DiffEntry struct {
	Type    string `json:"type"`               // "unchanged", "added", or "removed"
	OldLine int    `json:"old_line,omitempty"` // 1-based line number in old content (0 if added)
	NewLine int    `json:"new_line,omitempty"` // 1-based line number in new content (0 if removed)
	Text    string `json:"text"`
}

DiffEntry represents a single line in the diff output.

func ComputeLineDiff

func ComputeLineDiff(oldContent, newContent string) []DiffEntry

ComputeLineDiff computes a line-level diff between oldContent and newContent using Hirschberg's algorithm (divide-and-conquer LCS in O(n) space). Each line is classified as "unchanged", "added", or "removed".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL