textmatch

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: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyOld       = errors.New("old text is empty")
	ErrNoOpEdit       = errors.New("old text and new text are identical")
	ErrNoMatch        = errors.New("old text did not match content")
	ErrAmbiguousMatch = errors.New("old text matched multiple locations")
)

Functions

func UnifiedDiff

func UnifiedDiff(oldText, newText, path string, contextLines int) string

func UnifiedDiffExact

func UnifiedDiffExact(oldText, newText, path string, contextLines int) string

UnifiedDiffExact emits a line diff without normalizing BOMs or line endings. It is used when the byte-level replacement itself is the operation being reported, rather than a normalized text edit.

Types

type AmbiguityError

type AmbiguityError struct {
	Count int
	Lines []int
}

func (*AmbiguityError) Error

func (e *AmbiguityError) Error() string

func (*AmbiguityError) Unwrap

func (e *AmbiguityError) Unwrap() error

type Range

type Range struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

Range is a half-open byte range in the normalized, BOM-free source content.

type Request

type Request struct {
	Content    string
	Old        string
	New        string
	ReplaceAll bool
}

type Result

type Result struct {
	Content      string
	Replacements int
	Tier         Tier
	Ranges       []Range
	LineEnding   string
	HadBOM       bool
}

func Apply

func Apply(req Request) (Result, error)

type Tier

type Tier int
const (
	TierExact Tier = iota
	TierTrailingWhitespace
	TierIndentation
)

func (Tier) String

func (t Tier) String() string

Jump to

Keyboard shortcuts

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