diff

package
v0.0.0-...-0d6f639 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffLine

type DiffLine struct {
	Type       LineType
	Content    string
	LineNo1    int // Line number in file 1 (0 if not applicable)
	LineNo2    int // Line number in file 2 (0 if not applicable)
	Highlights []Highlight
}

DiffLine represents a single line in the diff

type DiffResult

type DiffResult struct {
	Lines      []DiffLine
	File1Name  string
	File2Name  string
	File1Lines []string
	File2Lines []string
}

DiffResult contains the results of a diff operation

func (*DiffResult) GetStats

func (r *DiffResult) GetStats() (added, removed, unchanged int)

GetStats returns statistics about the diff

func (*DiffResult) HasChanges

func (r *DiffResult) HasChanges() bool

HasChanges returns true if there are any differences

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine handles diff operations

func NewEngine

func NewEngine(options EngineOptions) *Engine

NewEngine creates a new diff engine

func (*Engine) DiffFiles

func (e *Engine) DiffFiles(file1, file2 string) (*DiffResult, error)

DiffFiles compares two files and returns the differences

func (*Engine) DiffLines

func (e *Engine) DiffLines(lines1, lines2 []string, file1Name, file2Name string) *DiffResult

DiffLines compares two slices of lines

type EngineOptions

type EngineOptions struct {
	Language         string
	IgnoreWhitespace bool
	IgnorePatterns   []string
	TokenPatterns    map[string]string
}

EngineOptions controls diff behavior.

type Highlight

type Highlight struct {
	Start int // rune offset (inclusive)
	End   int // rune offset (exclusive)
}

Highlight marks a token range that changed within a line.

type LineType

type LineType int

LineType defines the type of diff line

const (
	Equal LineType = iota
	Added
	Removed
)

type RegexTokenizer

type RegexTokenizer struct {
	// contains filtered or unexported fields
}

RegexTokenizer tokenizes text using a regular expression.

func NewRegexTokenizer

func NewRegexTokenizer(pattern string) *RegexTokenizer

NewRegexTokenizer compiles a regex tokenizer.

func (*RegexTokenizer) Tokenize

func (r *RegexTokenizer) Tokenize(line string) []Token

Tokenize splits the line using the configured regex and records rune offsets.

type Token

type Token struct {
	Value string
	Start int
	End   int
}

Token represents a tokenized fragment of a line.

type Tokenizer

type Tokenizer interface {
	Tokenize(line string) []Token
}

Tokenizer splits a line into tokens.

Jump to

Keyboard shortcuts

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