scannerz

package
v0.48.5 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package scannerz contains functionality for scanning data, most specifically for working with bufio.Scanner. See scannerz.NewScanner.

Index

Constants

This section is empty.

Variables

View Source
var OptScanBufLimit = datasize.NewOpt(
	"tuning.scan-buffer-limit",
	nil,
	datasize.MustParseString("32MB"),
	"Scan token buffer limit",
	`Maximum size of the buffer used for scanning tokens. The buffer will start
small and grow as needed, but will not exceed this limit.

Use units B, KB, MB, GB, etc. For example, 64KB, or 10MB. If no unit specified,
bytes are assumed.`,
	options.TagTuning,
)

OptScanBufLimit is an Opt for configuring the buffer size of a bufio.Scanner returned from scannerz.NewScanner.

Functions

func Head1

func Head1(ctx context.Context, s string) string

Head1 returns the first line of s, without the linebreak.

func IndentLines

func IndentLines(ctx context.Context, s, indent string) string

IndentLines returns a new string built from indenting each line of s.

func LineCount

func LineCount(ctx context.Context, r io.Reader, skipEmpty bool) int

LineCount returns the number of lines in r. If skipEmpty is true, empty lines are skipped (a whitespace-only line is not considered empty). If r is nil or any error occurs, -1 is returned.

func NewScanner

func NewScanner(ctx context.Context, r io.Reader) *bufio.Scanner

NewScanner returns a new bufio.Scanner configured via OptScanBufLimit set on ctx.

func TrimHead

func TrimHead(ctx context.Context, s string, n int) string

TrimHead trims the first n lines from s. It panics if n is negative. If n is zero, s is returned unchanged.

func VisitLines

func VisitLines(ctx context.Context, s string, fn func(i int, line string) string) string

VisitLines visits the lines of s, returning a new string built from applying fn to each line.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳