text

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package text provides a column-writer and general-purpose text filter.

Index

Constants

View Source
const (
	CR   = "\r"
	LF   = "\n"
	CRLF = "\r\n"

	HT   = "\t"
	SP   = " "
	HTSP = "\t "

	Whitespace = "\t\r\n "
)
View Source
const (
	Eighty int = 80
)

Variables

This section is empty.

Functions

func ColumnWriter

func ColumnWriter(col int, sep string, w io.Writer) *columnwriter

NewColumnWriter wraps w such that only lines of length (including sep) at most col, terminated by sep are written. This is achieved by injecting sep. After closing with Close, if any bytes were written, sep will have been the last bytes written. ColumnWriter panics if col < 0, len(sep) <= 0 or col <= len(sep).

One rule for Go text recoders is that the empty input is transformed to the empty output.

func ToCrlf

func ToCrlf(lf []byte) []byte

Adds a trailing LF on non-zero input which is non-terminated.

func ToCrlfReader

func ToCrlfReader(r io.Reader) io.Reader

func ToLf

func ToLf(crlf []byte) []byte

Adds a trailing CRLF on non-zero input which is non-terminated.

func ToLfReader

func ToLfReader(r io.Reader) io.Reader

Zero-byte readers result in zero-byte readers. Otherwise, unterminated lines are terminated. Sole "\r" are interpreted as a line break (old Mac OS style).

Types

type MappedReader

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

func Map

func Map(m Mapping, r io.Reader) *MappedReader

func (*MappedReader) Read

func (mr *MappedReader) Read(p []byte) (int, error)

type Mapping

type Mapping struct {
	// 1 <= Lookahead
	Lookahead int

	// len([]byte) == Lookahead except at EOF
	// len([]byte) > 0
	F func(window []byte) (emit []byte, read int, err error)
}

func Crlf

func Crlf() Mapping

Lf maps any of the common three newline representations ("\n" (Unix), "\r\n" (mail, DOS), "\r" (old Mac OS)) and converts them to "\r\n".

func Lf

func Lf() Mapping

Lf maps any of the common three newline representations ("\n" (Unix), "\r\n" (mail, DOS), "\r" (old Mac OS)) and converts them to "\n".

func NoNUL

func NoNUL() Mapping

NoNUL replaces NUL bytes ('\x00') with '?'.

func TruncateUpperBit

func TruncateUpperBit() Mapping

func UTF8

func UTF8() Mapping

func UTF8Strict

func UTF8Strict() Mapping

Jump to

Keyboard shortcuts

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