Documentation
¶
Overview ¶
Package wordwrap provide a utility to wrap text on word boundaries.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner wraps UTF-8 encoded text at word boundaries when lines exceed a limit number of characters. Newlines are preserved, including consecutive and trailing newlines, though trailing whitespace is stripped from each line.
Clients should not assume Scanner is thread-safe.
func NewScanner ¶
NewScanner creates and initializes a new Scanner given a reader and fixed line limit. The new Scanner takes ownership of the reader, and the caller should not use it after this call.
func (*Scanner) ReadLine ¶
ReadLine reads a single wrapped line, not including end-of-line characters ("\n"). Trailing newlines are preserved. At EOF, the result will be an empty string and the error will be io.EOF.
ReadLine always attempts to return at least one line, even on empty input.
ReadLine attempts to handle tab characters gracefully, converting them to spaces aligned on the boundary define in SetTabWidth.
func (*Scanner) SetPrefix ¶
SetPrefix sets a string to prefix each future line. The prefix is not applied to empty lines and the prefix's length is not included in the character limit specified in NewScanner.
It's safe to call SetPrefix between calls to ReadLine.
func (*Scanner) SetTabWidth ¶
SetTabWidth sets the width of tab characters.
It's safe to call SetTabWidth between calls to ReadLine.