lines

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package lines splits inputs into lines and represents each line by its boundaries: offsets into the input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lines

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

Lines holds an input and its line boundaries. Each line includes its newline character.

func Split

func Split[T string | []byte](s T) Lines

Split returns the lines of s. The result must only be used while s is not modified. Call Lines.Release when the result is no longer needed.

func SplitPair

func SplitPair[T string | []byte](x, y T) (xl, yl Lines, prefix, suffix int)

SplitPair returns the lines of x and y and the number of lines in their longest common prefix and suffix. The prefix and suffix don't overlap. The results must only be used while x and y are not modified. Call Lines.Release on both results when they are no longer needed.

func (*Lines) At

func (l *Lines) At(i int) string

At returns line i like Lines.Line, but without computing its boundaries, so that it inlines. Line i must be one whose boundaries are always computed: any line of Split, or a line between the common prefix and suffix of SplitPair.

func (*Lines) Len

func (l *Lines) Len() int

Len returns the number of lines.

func (*Lines) Line

func (l *Lines) Line(i int) string

Line returns line i. The result shares memory with the input of l.

func (*Lines) Release

func (l *Lines) Release()

Release returns the memory of l to a pool. The caller must not use l after Release.

func (*Lines) Size

func (l *Lines) Size(i, j int) int

Size returns the number of bytes in lines [i, j).

func (*Lines) Span

func (l *Lines) Span(i int) (start, end int)

Span returns the offsets of the first byte of line i and of the byte after it in the input.

Jump to

Keyboard shortcuts

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