linediff

package module
v0.0.0-...-e277775 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 4 Imported by: 0

README

Line Diff

This is a simplistic way to diff text using custom tokenization and lookahead criteria.

This can be used as a library for more complicated use cases. Or...

diffhtml

This tool allows producing an HTML rendering of all the differences in a CSV file.

This output was created using diffhtml --csv=test.csv -a 0 -b 1 --delim=' ;'. test_screenshot.png

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DiffCrossConfidence = 3
	BufferSize          = runebuffer.DefaultBufferSize
)

DiffCrossConfidence determines how many tokens the cross comparison phase will look ahead before giving up. This can be tuned according to the length of the incoming data set to emit more or less verbose diffs.

View Source
var SplitSpaces = SplitterFunc(func(tr *TokenReader) []string {
	var tokens []string
	for {
		token, found := tr.Until(" ")
		if !found {
			return tokens
		}
		tokens = append(tokens, token)
		for {
			space, found := tr.AcceptToken(" ")
			if !found {
				break
			}
			tokens = append(tokens, space)
		}
	}
})

Functions

This section is empty.

Types

type DiffSet

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

func Diff

func Diff(a, b string) *DiffSet

func DiffSplit

func DiffSplit(a, b string, split Splitter) *DiffSet

func (*DiffSet) Add

func (s *DiffSet) Add(tag Tag, tokens ...string)

func (*DiffSet) AddAddition

func (s *DiffSet) AddAddition(tokens ...string)

func (*DiffSet) AddRemoval

func (s *DiffSet) AddRemoval(tokens ...string)

func (*DiffSet) AddSimilarity

func (s *DiffSet) AddSimilarity(tokens ...string)

func (*DiffSet) Iterator

func (s *DiffSet) Iterator() *DiffSetIterator

func (*DiffSet) String

func (s *DiffSet) String() string

type DiffSetIterator

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

func (*DiffSetIterator) Next

func (i *DiffSetIterator) Next() (string, Tag, bool)

type Splitter

type Splitter interface {
	Split(tr *TokenReader) []string
}

type SplitterFunc

type SplitterFunc func(tr *TokenReader) []string

func (SplitterFunc) Split

func (f SplitterFunc) Split(tr *TokenReader) []string

type Tag

type Tag int
const (
	Same Tag = iota
	Added
	Removed
)

type TokenReader

type TokenReader struct {
	*runebuffer.RuneBuffer
}

func NewStringTokenReader

func NewStringTokenReader(s string) *TokenReader

func NewStringTokenReaderWithSize

func NewStringTokenReaderWithSize(s string, size int) *TokenReader

func NewTokenReader

func NewTokenReader(r io.Reader) *TokenReader

func NewTokenReaderWithSize

func NewTokenReaderWithSize(r io.Reader, size int) *TokenReader

func (*TokenReader) Accept

func (tr *TokenReader) Accept(list string) (string, bool)

Accept reads runes matching the accept list, returning the read token if any runes were read. The list is split to runes, and all unique runes are included in a match set.

func (*TokenReader) AcceptToken

func (tr *TokenReader) AcceptToken(token string) (string, bool)

AcceptToken returns exactly the token from the input if it exists. Otherwise, "" and false are returned, and all read runes are unread.

func (*TokenReader) Until

func (tr *TokenReader) Until(list string) (string, bool)

Until reads until a rune in the list string matches, returning the read token if any runes were read. The list is split to runes, and all unique runes are included in a match set. This can read the entire input into memory if the runes do not exist past the current read point.

func (*TokenReader) UntilToken

func (tr *TokenReader) UntilToken(token string) (string, bool)

UntilToken returns all from the input runes up to the token if it exists. If the token is not found or the end of the stream is reached, then "" and false are returned, and all read runes are unread. This will return "" and true if the token is the very next set of runes in the stream. This can read the entire input into memory before unreading if the token doesn't exist past the current read point.

Directories

Path Synopsis
cmd
diffhtml command

Jump to

Keyboard shortcuts

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