str

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeMatch = iota
	TypeReplace
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CharDiff

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

CharDiff is a per-character diff algorithm, meaning that it makes no distinctions about word or line boundaries when generating a diff.

func NewCharDiff

func NewCharDiff(opts ...CharDiffOpt) *CharDiff

func (*CharDiff) Diffs

func (c *CharDiff) Diffs(ctx context.Context, actual, expected []rune) <-chan Diff

type CharDiffOpt

type CharDiffOpt func(CharDiff) CharDiff

CharDiffOpt is an option function for changing the behavior of the NewCharDiff constructor.

func CharDiffBaseCost

func CharDiffBaseCost(cost float64) CharDiffOpt

CharDiffBaseCost is a CharDiff option to set the base cost per diff section. Increasing this will reduce the number of diff sections in the output at the cost of larger diff sections.

Default is 0.

func CharDiffPerCharCost

func CharDiffPerCharCost(cost float64) CharDiffOpt

CharDiffPerCharCost is a CharDiff option to set the cost-per-character of any differences returned. Increasing this cost will reduce the size of diff sections at the cost of more diff sections.

Default is 1

type Diff

type Diff interface {
	// Cost is the calculated cost of changing from one value to another.
	// Basically, if provided with multiple diffs, the Differ will always prefer
	// the lowest cost.
	//
	// Generally, a cost of 0 should represent exactly equal values, so negative
	// numbers shouldn't usually be used. However, if they are used, they will
	// work the same as positive values, being preferred over any value higher
	// than them.
	Cost() float64

	// Sections returns all of the sections of the diff. This will be used to
	// generate output, depending on the diff formats being used.
	Sections() []DiffSection
}

Diff represents a full diff of two values.

type DiffSection

type DiffSection struct {
	Type             Type
	Actual, Expected []rune
}

DiffSection represents a single chunk of a diff.

type Type

type Type int

Jump to

Keyboard shortcuts

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