ios

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 9 Imported by: 18

Documentation

Index

Constants

View Source
const (
	// ScannerByDelimFlagEofAsDelim specifies that the scanner should treat EOF as the delimiter as well.
	ScannerByDelimFlagEofAsDelim ScannerByDelimFlag = 1 << iota
	// ScannerByDelimFlagDropDelimInReturn specifies that the delimiter should NOT be included in the return value.
	ScannerByDelimFlagDropDelimInReturn

	// ScannerByDelimFlagEofNotAsDelim specifies that the scanner should NOT treat EOF as the delimiter.
	ScannerByDelimFlagEofNotAsDelim = 0
	// ScannerByDelimFlagIncludeDelimInReturn specifies that the delimiter should be included in the return value.
	ScannerByDelimFlagIncludeDelimInReturn = 0
)
View Source
const (
	// ScannerByDelimFlagDefault specifies the most commonly used flags for the scanner.
	ScannerByDelimFlagDefault = ScannerByDelimFlagEofAsDelim | ScannerByDelimFlagDropDelimInReturn
)

Variables

This section is empty.

Functions

func ByteReadLine added in v0.0.13

func ByteReadLine(r *bufio.Reader) ([]byte, error)

ByteReadLine reads in a single line from a bufio.Reader and returns it in []byte. Note the returned []byte may be pointing directly into the bufio.Reader, so assume the returned []byte will be invalidated and shouldn't be used upon next ByteReadLine call.

func DirExists added in v0.0.4

func DirExists(dir string) bool

DirExists checks if a directory exists or not.

func FileExists added in v0.0.4

func FileExists(file string) bool

FileExists checks if a file exists or not.

func NewScannerByDelim

func NewScannerByDelim(r io.Reader, delim []byte, flags ScannerByDelimFlag) *bufio.Scanner

NewScannerByDelim creates a scanner that returns tokens from the source reader separated by a delimiter.

func NewScannerByDelim2

func NewScannerByDelim2(r io.Reader, delim, escape []byte, flags ScannerByDelimFlag) *bufio.Scanner

NewScannerByDelim2 creates a scanner that returns tokens from the source reader separated by a delimiter, with consideration of potential presence of escaping sequence. Note: the token returned from the scanner will **NOT** do any unescaping, thus keeping the original value.

func NewScannerByDelim3 added in v0.0.5

func NewScannerByDelim3(r io.Reader, delim, escape []byte, flags ScannerByDelimFlag, buf []byte) *bufio.Scanner

NewScannerByDelim3 creates a scanner that utilizes given buf to avoid/minimize allocation and returns tokens from the source reader separated by a delimiter, with consideration of potential presence of escaping sequence. Note: the token returned from the scanner will **NOT** do any unescaping, thus keeping the original value.

func ReadLine

func ReadLine(r *bufio.Reader) (string, error)

ReadLine reads in a single line from a bufio.Reader and returns it in string.

func StripBOM

func StripBOM(reader io.Reader) (io.Reader, error)

StripBOM returns a new io.Reader that, if needed, strips away the BOM (byte order marker) of the input io.Reader.

Types

type BytesReplacer added in v0.0.15

type BytesReplacer interface {
	// GetSizingHints returns hints for BytesReplacingReader to do sizing estimate and allocation.
	// Return values:
	// - 1st: max search token len
	// - 2nd: max replace token len
	// - 3rd: max (search_len / replace_len) ratio that is less than 1,
	//        if none of the search/replace ratio is less than 1, then return a negative number.
	// will only be called once during BytesReplacingReader initialization/reset.
	GetSizingHints() (int, int, float64)
	// Index does token search for BytesReplacingReader.
	// Return values:
	// - 1st: index of the first found search token; -1, if not found;
	// - 2nd: the found search token; ignored if not found;
	// - 3rd: the matching replace token; ignored if not found;
	Index(buf []byte) (int, []byte, []byte)
}

BytesReplacer allows customization on how BytesReplacingReader does sizing estimate during initialization/reset and does search and replacement during the execution.

type BytesReplacingReader

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

BytesReplacingReader allows transparent replacement of a given token during read operation.

func NewBytesReplacingReader

func NewBytesReplacingReader(r io.Reader, search, replace []byte) *BytesReplacingReader

NewBytesReplacingReader creates a new `*BytesReplacingReader` for a single pair of search:replace token replacement. `search` cannot be nil/empty. `replace` can.

func NewBytesReplacingReaderEx added in v0.0.15

func NewBytesReplacingReaderEx(r io.Reader, replacer BytesReplacer) *BytesReplacingReader

NewBytesReplacingReaderEx creates a new `*BytesReplacingReader` for a given BytesReplacer customization.

func (*BytesReplacingReader) Read

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

Read implements the `io.Reader` interface.

func (*BytesReplacingReader) Reset

func (r *BytesReplacingReader) Reset(r1 io.Reader, search1, replace1 []byte) *BytesReplacingReader

Reset allows reuse of a previous allocated `*BytesReplacingReader` for buf allocation optimization. `search` cannot be nil/empty. `replace` can.

func (*BytesReplacingReader) ResetEx added in v0.0.15

ResetEx allows reuse of a previous allocated `*BytesReplacingReader` for buf allocation optimization.

type LineCountingReader

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

LineCountingReader wraps an io.Reader and reports currently which line the reader is at. Note the LineAt starts a 1.

func NewLineCountingReader

func NewLineCountingReader(r io.Reader) *LineCountingReader

NewLineCountingReader creates new LineCountingReader wrapping around an input io.Reader.

func (*LineCountingReader) AtLine

func (r *LineCountingReader) AtLine() int

AtLine returns the current line number. Note it starts with 1.

func (*LineCountingReader) Read

func (r *LineCountingReader) Read(p []byte) (n int, err error)

Read implements the `io.Reader` interface.

type LineEditFunc added in v0.0.16

type LineEditFunc func(line []byte) ([]byte, error)

LineEditFunc edits a line and returns a resulting line. Note in-place editing is highly encouraged, for performance reasons, when the resulting line is no longer than the original. If your edited line is longer then the original `line`, however, you MUST allocate and return a new []byte. Directly appending at the end of the original `line` will result in undefined behavior.

type LineEditingReader added in v0.0.16

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

LineEditingReader implements io.Reader interface with a line editing mechanism. LineEditingReader reads data from underlying io.Reader and invokes the caller supplied edit function for each of the line (defined as []byte ending with '\n', therefore it works on both Mac/Linux and Windows, where '\r\n' is used). Note the last line before EOF will be edited as well even if it doesn't end with '\n'. Usage is highly flexible: the editing function can do in-place editing such as character replacement, prefix/suffix stripping, or word replacement, etc., as long as the line length isn't changed; or it can replace a line with a completely newly allocated and written line with no length restriction (although performance would be slower compared to in-place editing).

func NewLineEditingReader added in v0.0.16

func NewLineEditingReader(r io.Reader, edit LineEditFunc) *LineEditingReader

NewLineEditingReader creates a new LineEditingReader with the default buffer size.

func NewLineEditingReader2 added in v0.0.16

func NewLineEditingReader2(r io.Reader, edit LineEditFunc, bufSize int) *LineEditingReader

NewLineEditingReader2 creates a new LineEditingReader with custom buffer size.

func (*LineEditingReader) Read added in v0.0.16

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

Read implements io.Reader interface for LineEditingReader.

type LineNumReportingCsvReader

type LineNumReportingCsvReader struct {
	*csv.Reader
	// contains filtered or unexported fields
}

LineNumReportingCsvReader wraps std lib `*csv.Reader` and exposes the current line number.

func NewLineNumReportingCsvReader

func NewLineNumReportingCsvReader(r io.Reader) *LineNumReportingCsvReader

NewLineNumReportingCsvReader creates a new `*LineNumReportingCsvReader`.

func (*LineNumReportingCsvReader) LineNum

func (r *LineNumReportingCsvReader) LineNum() int

LineNum returns the current line number

type ScannerByDelimFlag

type ScannerByDelimFlag uint

ScannerByDelimFlag is the type of flags passed to NewScannerByDelim/NewScannerByDelim2.

Jump to

Keyboard shortcuts

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