skim

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLineTooLong = errors.New("line too long")

ErrLineTooLong means there was a line encountered that exceeded max_line_size for the space.

Functions

This section is empty.

Types

type Scanner

type Scanner struct {
	Stats
	// contains filtered or unexported fields
}

Scanner is like bufio.Scanner but it it understands how to skip over and report lines that are too long.

func NewScanner

func NewScanner(r io.Reader, buffer []byte, limit int) *Scanner

func (*Scanner) Peek

func (s *Scanner) Peek() byte

func (*Scanner) Scan

func (s *Scanner) Scan() ([]byte, error)

Scan returns the next line of input as a byte slice or nil and an error indicating the state of things. A terminal "\r\n" sequence is first replaced with a newline, and then the terminal newline is returned in the slice, except in the case of a final line without a newline. When a line is encountered that is larger than the max line size, then the partial line is returned along with ErrLineTooLong. In this case, Scan can be subsequently called for the rest of the line, possibly with another line too long error, and so on. Skip can also be called to easily skip over the rest of the line. At EOF, nil is returned. XXX If Scan is called directly instead of ScanLine, then Stats are not properly tracked. for the slice and io.EOF for the error.

func (*Scanner) ScanLine

func (s *Scanner) ScanLine() ([]byte, error)

Scan returns the next line skipping blank lines and too-long lines and accumulating statistics.

func (*Scanner) Skip

func (s *Scanner) Skip() (int, error)

Skip discards all input up to and including the next newline or end of file, and returns the number of bytes skipped. Returns an error if the underlying reader returns an error, except for EOF, which is ignored since the caller will detect EOF on the next call to Scan.

type Stats

type Stats struct {
	Bytes       int `json:"bytes_read"`
	Lines       int `json:"lines_read"`
	BlankLines  int `json:"blank_lines"`
	LineTooLong int `json:"line_too_long"`
}

Jump to

Keyboard shortcuts

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