nicediff

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package diff implements a linewise diff algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(A, B string, skipEqual bool) string

Diff returns a string containing a line-by-line unified diff of the linewise changes required to make A into B. Each line is prefixed with '+', '-', or ' ' to indicate if it should be added, removed, or is correct respectively.

func Render

func Render(chunks []Chunk, skipEqual bool) string

Render renders the slice of chunks into a representation that prefixes the lines with '+', '-', or ' ' depending on whether the line was added, removed, or equal (respectively).

Types

type Chunk

type Chunk struct {
	Added   []string
	Deleted []string
	Equal   []string
}

Chunk represents a piece of the diff. A chunk will not have both added and deleted lines. Equal lines are always after any added or deleted lines. A Chunk may or may not have any lines in it, especially for the first or last chunk in a computation.

func DiffChunks

func DiffChunks(a, b []string) []Chunk

DiffChunks uses an O(D(N+M)) shortest-edit-script algorithm to compute the edits required from A to B and returns the edit chunks.

Jump to

Keyboard shortcuts

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