edit

Imports

Imports #

"fmt"
"sort"

Type Aliases

edits type #

An edits is a list of edits that is sortable by start offset, breaking ties by end offset.

type edits []edit

Structs

Buffer struct #

A Buffer is a queue of edits to apply to a given byte slice.

type Buffer struct {
old []byte
q edits
}

edit struct #

An edit records a single text modification: change the bytes in [start,end) to new.

type edit struct {
start int
end int
new string
}

Functions

Bytes method #

Bytes returns a new byte slice containing the original data with the queued edits applied.

func (b *Buffer) Bytes() []byte

Delete method #

func (b *Buffer) Delete(start int, end int)

Insert method #

func (b *Buffer) Insert(pos int, new string)

Len method #

func (x edits) Len() int

Less method #

func (x edits) Less(i int, j int) bool

NewBuffer function #

NewBuffer returns a new buffer to accumulate changes to an initial data slice. The returned buffer maintains a reference to the data, so the caller must ensure the data is not modified until after the Buffer is done being used.

func NewBuffer(data []byte) *Buffer

Replace method #

func (b *Buffer) Replace(start int, end int, new string)

String method #

String returns a string containing the original data with the queued edits applied.

func (b *Buffer) String() string

Swap method #

func (x edits) Swap(i int, j int)

Generated with Arrow