transform

Imports

Imports #

"bytes"
"errors"
"io"
"unicode/utf8"

Constants & Variables

Discard var #

Discard is a Transformer for which all Transform calls succeed by consuming all bytes and writing nothing.

var Discard Transformer = discard{...}

ErrEndOfSpan var #

ErrEndOfSpan means that the input and output (the transformed input) are not identical.

var ErrEndOfSpan = *ast.CallExpr

ErrShortDst var #

ErrShortDst means that the destination buffer was too short to receive all of the transformed bytes.

var ErrShortDst = *ast.CallExpr

ErrShortSrc var #

ErrShortSrc means that the source buffer has insufficient data to complete the transformation.

var ErrShortSrc = *ast.CallExpr

Nop var #

Nop is a SpanningTransformer that copies src to dst.

var Nop SpanningTransformer = nop{...}

defaultBufSize const #

const defaultBufSize = 4096

errInconsistentByteCount var #

errInconsistentByteCount means that Transform returned success (nil error) but also returned nSrc inconsistent with the src argument.

var errInconsistentByteCount = *ast.CallExpr

errShortInternal var #

errShortInternal means that an internal buffer is not large enough to make progress and the Transform operation must be aborted.

var errShortInternal = *ast.CallExpr

initialBufSize const #

const initialBufSize = 128

Type Aliases

removeF type #

type removeF func(r rune) bool

Interfaces

SpanningTransformer interface #

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 interface #

Transformer transforms bytes.

type Transformer interface {
Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)
Reset()
}

Structs

NopResetter struct #

NopResetter can be embedded by implementations of Transformer to add a nop Reset method.

type NopResetter struct {

}

Reader 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 struct #

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 struct #

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
}

discard struct #

type discard struct {
NopResetter
}

nop struct #

type nop struct {
NopResetter
}

Functions

Append function #

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 function #

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 function #

Chain returns a Transformer that applies t in sequence.

func Chain(t ...Transformer) Transformer

Close method #

Close implements the io.Closer interface.

func (w *Writer) Close() error

NewReader function #

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 function #

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 method #

Read implements the io.Reader interface.

func (r *Reader) Read(p []byte) (int, error)

RemoveFunc function #

Deprecated: Use runes.Remove instead.

func RemoveFunc(f func(r rune) bool) Transformer

Reset method #

Reset resets the state of Chain. It calls Reset on all the Transformers.

func (c *chain) Reset()

Reset method #

func (removeF) Reset()

Reset method #

Reset implements the Reset method of the Transformer interface.

func (NopResetter) Reset()

Span method #

func (nop) Span(src []byte, atEOF bool) (n int, err error)

String function #

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 method #

Transform implements the Transformer interface.

func (t removeF) Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)

Transform method #

Transform applies the transformers of c in sequence.

func (c *chain) Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)

Transform method #

func (discard) Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)

Transform method #

func (nop) Transform(dst []byte, src []byte, atEOF bool) (nDst int, nSrc int, err error)

Write method #

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)

doAppend function #

func doAppend(t Transformer, pDst int, dst []byte, src []byte) (result []byte, n int, err error)

dst method #

func (l *link) dst() []byte

fatalError method #

func (c *chain) fatalError(errIndex int, err error)

grow function #

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

src method #

func (l *link) src() []byte

Generated with Arrow