Help us shape the future of Go! Take the 2026 Go Developer Survey

buffer

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package buffer provides Cove's text buffer: a rope of bytes plus a line-start index, giving O(lg n) edits and O(1) line addressing. The rope implementation is swappable; nothing outside this package touches it directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer is a mutable text buffer addressed by byte offset or (line, col). Lines and columns are 0-based; col is a byte offset within the line.

func New

func New(data []byte) *Buffer

New creates a buffer from data. The slice is copied; callers keep ownership.

func (*Buffer) Bytes

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

Bytes returns the full buffer contents as a copy.

func (*Buffer) Delete

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

Delete removes the bytes in [start, end).

func (*Buffer) Insert

func (b *Buffer) Insert(off int, text []byte)

Insert inserts text at byte offset off.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the buffer size in bytes.

func (*Buffer) Line

func (b *Buffer) Line(i int) []byte

Line returns the content of line i without its trailing newline. The returned slice is only valid until the next edit.

func (*Buffer) LineCount

func (b *Buffer) LineCount() int

LineCount returns the number of lines. Never less than 1.

func (*Buffer) LineLen

func (b *Buffer) LineLen(i int) int

LineLen returns the length of line i in bytes, excluding the newline.

func (*Buffer) Offset

func (b *Buffer) Offset(line, col int) int

Offset converts (line, col) to a byte offset, clamping col to line length.

func (*Buffer) Pos

func (b *Buffer) Pos(off int) (line, col int)

Pos converts a byte offset to (line, col).

func (*Buffer) Slice

func (b *Buffer) Slice(start, end int) []byte

Slice returns the bytes in [start, end). Only valid until the next edit.

Jump to

Keyboard shortcuts

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