diff

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: MIT Imports: 2 Imported by: 0

README

go-diff

A simple diff library for Go.

Usage

Install

Add go-diff to your project.

go get github.com/ktnyt/go-diff
Character diff
package main

import (
	"fmt"

	"github.com/ktnt/go-diff"
)

func main() {
	ops := diff.Diff("coelacanth", "pelican")

	// Output: copelaicanth
	fmt.Println(ops.Concat())
}
Line diff
package main

import (
	"fmt"

	"github.com/ktnt/go-diff"
)

func main() {
	ops := diff.LineDiff("foo\nbar\nbaz", "foo\nbaz\nbar")

	// Output:
	// |       foo
	// -       bar
	// |       baz
	// +       bar
	fmt.Println(ops.Join())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Common

type Common Equiv

Common represents a shared equiv.

func (Common) String

func (op Common) String() string

String returns the pretiffied edit string representation.

type CommonLine

type CommonLine string

CommonLine represents a shared line.

func (CommonLine) String

func (op CommonLine) String() string

String returns the pretiffied edit string representation.

type Context

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

Context represents a diff context.

func NewContext

func NewContext(a, b []rune) *Context

NewContext returns a new Context.

type Delete

type Delete Equiv

Delete represents an delete operation.

func (Delete) String

func (op Delete) String() string

String returns the pretiffied edit string representation.

type DeleteLine

type DeleteLine string

DeleteLine represents a line delete operation.

func (DeleteLine) String

func (op DeleteLine) String() string

String returns the pretiffied edit string representation.

type Equiv

type Equiv = rune

Equiv represents a line equivalence value.

type Insert

type Insert Equiv

Insert represents an insert operation.

func (Insert) String

func (op Insert) String() string

String returns the pretiffied edit string representation.

type InsertLine

type InsertLine string

InsertLine represents a line insert operation.

func (InsertLine) String

func (op InsertLine) String() string

String returns the pretiffied edit string representation.

type Op

type Op interface {
	String() string
}

Op represents an edit operation.

type Ops

type Ops []Op

Ops represents a slice of edit operations.

func Diff

func Diff(s, t string) Ops

Diff returns the shortest edit sequence of two strings.

func LineDiff

func LineDiff(s, t string) Ops

LineDiff returns the line diff of the two strings.

func (Ops) Concat

func (ops Ops) Concat() string

Concat concatenates the string representations of the edit operations

func (Ops) Join

func (ops Ops) Join() string

Join concatenates the string representations of the edit operations

type Point

type Point struct {
	X, Y int
}

Point represents a point in the edit graph.

type Route

type Route struct {
	X, Y, R int
}

Route represents a point in the edit graph with an associated route.

Jump to

Keyboard shortcuts

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