Documentation
¶
Overview ¶
Package lines provides line-oriented text processing primitives and a buffered line processor that applies a transform to each line of an input.
The per-line operations are small and pure; Process owns the scanning, context-cancellation, counting, and joining. The package holds no CLI or orchestration logic and is reusable by any domain that needs line processing.
Index ¶
Constants ¶
const ErrReadInput errs.Const = "failed to read input"
ErrReadInput is returned when reading the input fails. The underlying cause is wrapped via errs.Const.With, so the result matches both ErrReadInput and the cause under errors.Is.
Variables ¶
This section is empty.
Functions ¶
func Process ¶
Process scans reader line by line, applies transform, and joins the kept lines with "\n". It stops early if ctx is cancelled and reports the total and kept line counts.
Process is a buffered line processor, not a streaming one: every kept line is retained in memory and joined into a single Output, so peak memory is O(input).
A trailing newline is not round-tripped: lines are joined with "\n" and no terminator, so "a\nb\nc\n" and "a\nb\nc" both yield "a\nb\nc". CRLF is normalized to LF, because the scanner strips a trailing "\r" from each line.
A single line longer than MaxLine fails with ErrReadInput wrapping bufio.ErrTooLong.
Types ¶
type Line ¶
type Line string
Line is a single line of input or output.
func Numbered ¶
func Numbered(line Line, number LineNumber) Line
Numbered returns the line prefixed with its right-aligned line number.
func WithPrefix ¶
WithPrefix returns the line with prefix prepended.
type LineBytes ¶
type LineBytes int
LineBytes is a size, in bytes, of a single scanned line.
const MaxLine LineBytes = 1 << 20
MaxLine is the largest single line Process accepts. It raises bufio's default 64 KiB scan ceiling to 1 MiB; a line longer than this makes Process fail with ErrReadInput wrapping bufio.ErrTooLong.
type Stats ¶
type Stats struct {
Total LineNumber
Kept LineNumber
}
Stats reports the line counts observed during processing.