catgut

package
v0.0.0-...-381c4e2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const RingBufferDefaultSize = 4096

Variables

View Source
var ErrBufferEmpty = errors.New("buffer empty")
View Source
var ErrNoMatch = errors.New("no match")
View Source
var StringFormatWriter stringFormatWriter

Functions

func GetPool

func GetPool() schnittstellen.Pool[String, *String]

func MakeErrLength

func MakeErrLength(expected, actual int64, err error) error

func NewScannerExperimental

func NewScannerExperimental(r *RingBuffer) *scannerExperimental

NewScanner returns a new scannerExperimental to read from r. The split function defaults to ScanLines.

func WriteKeySpaceValueNewline

func WriteKeySpaceValueNewline(
	w io.Writer,
	key, value io.WriterTo,
) (n int64, err error)

Types

type RingBuffer

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

func MakeRingBuffer

func MakeRingBuffer(r io.Reader, n int) *RingBuffer

func (*RingBuffer) AdvanceRead

func (rb *RingBuffer) AdvanceRead(n int)

func (*RingBuffer) Cap

func (rb *RingBuffer) Cap() int

func (*RingBuffer) Fill

func (rb *RingBuffer) Fill() (n int64, err error)

func (*RingBuffer) Len

func (rb *RingBuffer) Len() int

func (*RingBuffer) PeekReadable

func (rb *RingBuffer) PeekReadable() (rs Slice)

func (*RingBuffer) PeekUnreadable

func (rb *RingBuffer) PeekUnreadable() (rs Slice)

func (*RingBuffer) PeekUpto

func (rb *RingBuffer) PeekUpto(b byte) (readable Slice, err error)

func (*RingBuffer) PeekUptoAndIncluding

func (rb *RingBuffer) PeekUptoAndIncluding(b byte) (readable Slice, err error)

func (*RingBuffer) PeekWriteable

func (rb *RingBuffer) PeekWriteable() (rs Slice)

func (*RingBuffer) Read

func (rb *RingBuffer) Read(p []byte) (n int, err error)

func (*RingBuffer) ReadLength

func (rb *RingBuffer) ReadLength() int64

func (*RingBuffer) Reset

func (rb *RingBuffer) Reset(r io.Reader)

func (*RingBuffer) Seek

func (rb *RingBuffer) Seek(offset int64, whence int) (actual int64, err error)

func (*RingBuffer) Unread

func (rb *RingBuffer) Unread(toUnread int) (actuallyUnread int)

func (*RingBuffer) Write

func (rb *RingBuffer) Write(p []byte) (n int, err error)

type RingBufferRuneScanner

type RingBufferRuneScanner struct {
	SliceRuneScanner
	// contains filtered or unexported fields
}

func MakeRingBufferRuneScanner

func MakeRingBufferRuneScanner(rb *RingBuffer) (s *RingBufferRuneScanner)

func (*RingBufferRuneScanner) ReadRune

func (s *RingBufferRuneScanner) ReadRune() (r rune, size int, err error)

func (*RingBufferRuneScanner) Reset

func (s *RingBufferRuneScanner) Reset()

func (*RingBufferRuneScanner) ResetWith

func (s *RingBufferRuneScanner) ResetWith(rb *RingBuffer)

func (*RingBufferRuneScanner) UnreadRune

func (s *RingBufferRuneScanner) UnreadRune() (err error)

type RingBufferScanner

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

func MakeRingBufferScanner

func MakeRingBufferScanner(rb *RingBuffer) *RingBufferScanner

func (*RingBufferScanner) FirstMatch

func (s *RingBufferScanner) FirstMatch(
	mf func(rune) bool,
) (match Slice, offsetPlusMatch int, err error)

type Scanner

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

Scanner provides a convenient interface for reading data such as a file of newline-delimited lines of text. Successive calls to the Scan method will step through the 'tokens' of a file, skipping the bytes between the tokens. The specification of a token is defined by a split function of type SplitFunc; the default split function breaks the input into lines with line termination stripped. Split functions are defined in this package for scanning a file into lines, bytes, UTF-8-encoded runes, and space-delimited words. The client may instead provide a custom split function.

Scanning stops unrecoverably at EOF, the first I/O error, or a token too large to fit in the buffer. When a scan stops, the reader may have advanced arbitrarily far past the last token. Programs that need more control over error handling or large tokens, or must run sequential scans on a reader, should use bufio.Reader instead.

func NewScanner

func NewScanner(r *RingBuffer) *Scanner

NewScanner returns a new Scanner to read from r. The split function defaults to ScanLines.

func (*Scanner) Buffer

func (s *Scanner) Buffer(buf []byte, max int)

Buffer sets the initial buffer to use when scanning and the maximum size of buffer that may be allocated during scanning. The maximum token size is the larger of max and cap(buf). If max <= cap(buf), Scan will use this buffer only and do no allocation.

By default, Scan uses an internal buffer and sets the maximum token size to MaxScanTokenSize.

Buffer panics if it is called after scanning has started.

func (*Scanner) Bytes

func (s *Scanner) Bytes() []byte

Bytes returns the most recent token generated by a call to Scan. The underlying array may point to data that will be overwritten by a subsequent call to Scan. It does no allocation.

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the first non-EOF error that was encountered by the Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() bool

Scan advances the Scanner to the next token, which will then be available through the Bytes or Text method. It returns false when the scan stops, either by reaching the end of the input or an error. After Scan returns false, the Err method will return any error that occurred during scanning, except that if it was io.EOF, Err will return nil. Scan panics if the split function returns too many empty tokens without advancing the input. This is a common error mode for scanners.

func (*Scanner) Split

func (s *Scanner) Split(split SplitFunc)

Split sets the split function for the Scanner. The default split function is ScanLines.

Split panics if it is called after scanning has started.

func (*Scanner) Text

func (s *Scanner) Text() *String

Text returns the most recent token generated by a call to Scan as a newly allocated string holding its bytes.

type Slice

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

func (Slice) Bytes

func (rs Slice) Bytes() []byte

func (Slice) BytesBetween

func (rs Slice) BytesBetween(left, right int) []byte

func (Slice) Compare

func (rs Slice) Compare(b []byte) (c int)

func (Slice) Cut

func (rs Slice) Cut(b byte) (before, after Slice, ok bool)

func (Slice) Equal

func (rs Slice) Equal(b []byte) bool

func (Slice) First

func (rs Slice) First() []byte

func (Slice) FirstByte

func (a Slice) FirstByte() byte

func (Slice) IsEmpty

func (rs Slice) IsEmpty() bool

func (Slice) Len

func (rs Slice) Len() int

func (Slice) LenFirst

func (rs Slice) LenFirst() int

func (Slice) LenSecond

func (rs Slice) LenSecond() int

func (Slice) Overlap

func (rs Slice) Overlap() (o [6]byte, first, second int)

func (Slice) ReadFrom

func (rs Slice) ReadFrom(r io.Reader) (n int64, err error)

func (Slice) Second

func (rs Slice) Second() []byte

func (Slice) Slice

func (a Slice) Slice(left, right int) (b Slice)

func (Slice) SliceBytes

func (a Slice) SliceBytes() SliceBytes

func (Slice) SliceUptoAndIncluding

func (rs Slice) SliceUptoAndIncluding(b byte) (s Slice, ok bool)

func (Slice) SliceUptoButExcluding

func (rs Slice) SliceUptoButExcluding(b byte) (s Slice, ok bool)

func (Slice) Start

func (rs Slice) Start() int64

func (Slice) String

func (rs Slice) String() string

func (Slice) WriteTo

func (rs Slice) WriteTo(w io.Writer) (n int64, err error)

type SliceBytes

type SliceBytes struct {
	Slice
	Bytes []byte
}

type SliceReader

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

func MakeSliceReader

func MakeSliceReader(sl Slice) *SliceReader

func (*SliceReader) Read

func (sr *SliceReader) Read(p []byte) (n int, err error)

func (*SliceReader) ResetWith

func (sr *SliceReader) ResetWith(sl Slice)

type SliceRuneScanner

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

func MakeSliceRuneScanner

func MakeSliceRuneScanner(slice Slice) (s *SliceRuneScanner)

func (*SliceRuneScanner) Error

func (s *SliceRuneScanner) Error() error

func (*SliceRuneScanner) Offset

func (s *SliceRuneScanner) Offset() int

func (*SliceRuneScanner) ReadRune

func (s *SliceRuneScanner) ReadRune() (r rune, size int, err error)

func (*SliceRuneScanner) Remaining

func (s *SliceRuneScanner) Remaining() int

func (*SliceRuneScanner) Reset

func (s *SliceRuneScanner) Reset()

func (*SliceRuneScanner) ResetSliceOnly

func (s *SliceRuneScanner) ResetSliceOnly(slice Slice)

func (*SliceRuneScanner) ResetWith

func (s *SliceRuneScanner) ResetWith(slice Slice)

func (*SliceRuneScanner) Scan

func (s *SliceRuneScanner) Scan() (r rune, width int, ok bool)

func (*SliceRuneScanner) UnreadRune

func (s *SliceRuneScanner) UnreadRune() (err error)

type SplitFunc

type SplitFunc = bufio.SplitFunc

SplitFunc is the signature of the split function used to tokenize the input. The arguments are an initial substring of the remaining unprocessed data and a flag, atEOF, that reports whether the Reader has no more data to give. The return values are the number of bytes to advance the input and the next token to return to the user, if any, plus an error, if any.

Scanning stops if the function returns an error, in which case some of the input may be discarded. If that error is ErrFinalToken, scanning stops with no error.

Otherwise, the Scanner advances the input. If the token is not nil, the Scanner returns it to the user. If the token is nil, the Scanner reads more data and continues scanning; if there is no more data--if atEOF was true--the Scanner returns. If the data does not yet hold a complete token, for instance if it has no newline while scanning lines, a SplitFunc can return (0, nil, nil) to signal the Scanner to read more data into the slice and try again with a longer slice starting at the same point in the input.

The function is never called with an empty data slice unless atEOF is true. If atEOF is true, however, data may be non-empty and, as always, holds unprocessed text.

type SplitFuncExperimental

type SplitFuncExperimental func(data Slice, atEOF bool) (advance int, token []byte, err error)

SplitFunc is the signature of the split function used to tokenize the input. The arguments are an initial substring of the remaining unprocessed data and a flag, atEOF, that reports whether the Reader has no more data to give. The return values are the number of bytes to advance the input and the next token to return to the user, if any, plus an error, if any.

Scanning stops if the function returns an error, in which case some of the input may be discarded. If that error is ErrFinalToken, scanning stops with no error.

Otherwise, the scannerExperimental advances the input. If the token is not nil, the scannerExperimental returns it to the user. If the token is nil, the scannerExperimental reads more data and continues scanning; if there is no more data--if atEOF was true--the scannerExperimental returns. If the data does not yet hold a complete token, for instance if it has no newline while scanning lines, a SplitFunc can return (0, nil, nil) to signal the scannerExperimental to read more data into the slice and try again with a longer slice starting at the same point in the input.

The function is never called with an empty data slice unless atEOF is true. If atEOF is true, however, data may be non-empty and, as always, holds unprocessed text.

type String

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

func Make

func Make(b *String) (a *String)

func MakeFromBytes

func MakeFromBytes(b []byte) (s *String)

func MakeFromString

func MakeFromString(v string) (s *String)

func (*String) Append

func (str *String) Append(vs ...*String) (n int, err error)

func (*String) Available

func (str *String) Available() int

func (*String) AvailableBuffer

func (str *String) AvailableBuffer() []byte

func (*String) Bytes

func (str *String) Bytes() []byte

func (*String) CopyTo

func (src *String) CopyTo(dst *String) (err error)

func (*String) Equals

func (a *String) Equals(b *String) bool

func (*String) EqualsBytes

func (a *String) EqualsBytes(b []byte) bool

func (*String) EqualsString

func (a *String) EqualsString(b string) bool

func (*String) Grow

func (str *String) Grow(n int)

func (*String) Len

func (str *String) Len() int

func (*String) Map

func (str *String) Map(mapping func(r rune) rune, s []byte) (n int)

func (*String) MarshalBinary

func (src *String) MarshalBinary() ([]byte, error)

func (*String) MarshalText

func (src *String) MarshalText() ([]byte, error)

func (*String) ReadFrom

func (dst *String) ReadFrom(r io.Reader) (n int64, err error)

func (*String) ReadFromBuffer

func (dst *String) ReadFromBuffer(src *bytes.Buffer) (err error)

func (*String) ReadNFrom

func (dst *String) ReadNFrom(r io.Reader, toRead int) (read int, err error)

func (*String) Reset

func (str *String) Reset()

func (*String) Set

func (dst *String) Set(src string) (err error)

func (*String) SetBytes

func (dst *String) SetBytes(src []byte) (err error)

func (*String) String

func (str *String) String() string

func (*String) UnmarshalBinary

func (src *String) UnmarshalBinary(b []byte) error

func (*String) UnmarshalText

func (src *String) UnmarshalText(b []byte) error

func (*String) Write

func (str *String) Write(p []byte) (int, error)

func (*String) WriteLower

func (str *String) WriteLower(s []byte) (n int)

WriteLower writes all Unicode letters mapped to their lower case.

func (*String) WriteLowerOrError

func (str *String) WriteLowerOrError(s []byte) (err error)

func (*String) WriteRune

func (dst *String) WriteRune(r rune) (int, error)

func (*String) WriteTo

func (src *String) WriteTo(w io.Writer) (n int64, err error)

func (*String) WriteToStringWriter

func (src *String) WriteToStringWriter(
	w schnittstellen.WriterAndStringWriter,
) (n int64, err error)

type StringFormatReadWriter

type StringFormatReadWriter[T any] interface {
	StringFormatReader[T]
	schnittstellen.StringFormatWriter[T]
}

type StringFormatReader

type StringFormatReader[T any] interface {
	ReadStringFormat(*RingBuffer, T) (int64, error)
}

Jump to

Keyboard shortcuts

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