Imports #
"bytes"
"errors"
"io"
"unicode/utf8"
"bytes"
"errors"
"io"
"unicode/utf8"
Discard is a Transformer for which all Transform calls succeed by consuming all bytes and writing nothing.
var Discard Transformer = discard{...}
ErrEndOfSpan means that the input and output (the transformed input) are not identical.
var ErrEndOfSpan = *ast.CallExpr
ErrShortDst means that the destination buffer was too short to receive all of the transformed bytes.
var ErrShortDst = *ast.CallExpr
ErrShortSrc means that the source buffer has insufficient data to complete the transformation.
var ErrShortSrc = *ast.CallExpr
Nop is a SpanningTransformer that copies src to dst.
var Nop SpanningTransformer = nop{...}
const defaultBufSize = 4096
errInconsistentByteCount means that Transform returned success (nil error) but also returned nSrc inconsistent with the src argument.
var errInconsistentByteCount = *ast.CallExpr
errShortInternal means that an internal buffer is not large enough to make progress and the Transform operation must be aborted.
var errShortInternal = *ast.CallExpr
const initialBufSize = 128
type removeF func(r rune) bool
SpanningTransformer extends the Transformer interface with a Span method that determines how much of the input already conforms to the Transformer.
type SpanningTransformer interface {
Transformer
Span(src []byte, atEOF bool) (n int, err error)
}
Transformer transforms bytes.
type Transformer interface {
Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)
Reset()
}
NopResetter can be embedded by implementations of Transformer to add a nop Reset method.
type NopResetter struct {
}
Reader wraps another io.Reader by transforming the bytes read.
type Reader struct {
r io.Reader
t Transformer
err error
dst []byte
dst0 int
dst1 int
src []byte
src0 int
src1 int
transformComplete bool
}
Writer wraps another io.Writer by transforming the bytes read. The user needs to call Close to flush unwritten bytes that may be buffered.
type Writer struct {
w io.Writer
t Transformer
dst []byte
src []byte
n int
}
chain is a sequence of links. A chain with N Transformers has N+1 links and N+1 buffers. Of those N+1 buffers, the first and last are the src and dst buffers given to chain.Transform and the middle N-1 buffers are intermediate buffers owned by the chain. The i'th link transforms bytes from the i'th buffer chain.link[i].b at read offset chain.link[i].p to the i+1'th buffer chain.link[i+1].b at write offset chain.link[i+1].n, for i in [0, N).
type chain struct {
link []link
err error
errStart int
}
type discard struct {
NopResetter
}
type link struct {
t Transformer
b []byte
p int
n int
}
type nop struct {
NopResetter
}
Append appends the result of converting src[:n] using t to dst, where n <= len(src), If err == nil, n will be len(src). It calls Reset on t.
func Append(t Transformer, dst []byte, src []byte) (result []byte, n int, err error)
Bytes returns a new byte slice with the result of converting b[:n] using t, where n <= len(b). If err == nil, n will be len(b). It calls Reset on t.
func Bytes(t Transformer, b []byte) (result []byte, n int, err error)
Chain returns a Transformer that applies t in sequence.
func Chain(t ...Transformer) Transformer
Close implements the io.Closer interface.
func (w *Writer) Close() error
NewReader returns a new Reader that wraps r by transforming the bytes read via t. It calls Reset on t.
func NewReader(r io.Reader, t Transformer) *Reader
NewWriter returns a new Writer that wraps w by transforming the bytes written via t. It calls Reset on t.
func NewWriter(w io.Writer, t Transformer) *Writer
Read implements the io.Reader interface.
func (r *Reader) Read(p []byte) (int, error)
Deprecated: Use runes.Remove instead.
func RemoveFunc(f func(r rune) bool) Transformer
Reset resets the state of Chain. It calls Reset on all the Transformers.
func (c *chain) Reset()
func (removeF) Reset()
Reset implements the Reset method of the Transformer interface.
func (NopResetter) Reset()
func (nop) Span(src []byte, atEOF bool) (n int, err error)
String returns a string with the result of converting s[:n] using t, where n <= len(s). If err == nil, n will be len(s). It calls Reset on t.
func String(t Transformer, s string) (result string, n int, err error)
Transform implements the Transformer interface.
func (t removeF) Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)
Transform applies the transformers of c in sequence.
func (c *chain) Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)
func (discard) Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)
func (nop) Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)
Write implements the io.Writer interface. If there are not enough bytes available to complete a Transform, the bytes will be buffered for the next write. Call Close to convert the remaining bytes.
func (w *Writer) Write(data []byte) (n int, err error)
func doAppend(t Transformer, pDst int, dst []byte, src []byte) (result []byte, n int, err error)
func (l *link) dst() []byte
func (c *chain) fatalError(errIndex int, err error)
grow returns a new []byte that is longer than b, and copies the first n bytes of b to the start of the new slice.
func grow(b []byte, n int) []byte
func (l *link) src() []byte
Generated with Arrow