diff

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package diff provides bounded, dependency-free line diffs for tool output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatUnified

func FormatUnified(path string, r Result) string

func FormatUnifiedAt

func FormatUnifiedAt(path string, r Result, oldStart, newStart, context int) string

func Stats

func Stats(r Result) (insertions, deletions int)

func TruncateUTF8

func TruncateUTF8(s string, maxBytes int) string

TruncateUTF8 returns the longest prefix of s that is valid UTF-8 and at most maxBytes long; a non-positive maxBytes is treated as no limit, so a valid s is returned whole. It walks the window forward with utf8.DecodeRuneInString, so a long valid prefix followed by an invalid byte costs O(n) instead of the O(n^2) rescans of the previous trim-one-byte loop. A decoded U+FFFD with size 3 is a genuine replacement character and does not stop the walk; only RuneError with size 1 (an invalid or truncated sequence) does. The walk runs even when s already fits maxBytes, so a short input containing an invalid byte is cut back to its longest valid prefix rather than returned whole.

Types

type Kind

type Kind uint8
const (
	Equal Kind = iota
	Delete
	Insert
)

type Op

type Op struct {
	Kind  Kind
	Lines []string
}

type Options

type Options struct {
	MaxInputBytes int
	Timeout       time.Duration
}

type Result

type Result struct{ Ops []Op }

func Compute

func Compute(oldText, newText string, opts Options) (Result, error)

Jump to

Keyboard shortcuts

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