iohelper

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: MIT Imports: 7 Imported by: 1

README

Deprecated - Kept for existing project references but for new usage please use github.com/jf-tech/go-corelib/ios package.

iohelper

CI codecov Go Report Card PkgGoDev

Collection of I/O helpers in Golang

Golang Version: 1.12.17

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 NewScannerByDelim added in v1.0.1

func NewScannerByDelim(r io.Reader, delim string, flags ScannerByDelimFlag) *bufio.Scanner

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

func NewScannerByDelim2 added in v1.0.1

func NewScannerByDelim2(r io.Reader, delim string, escape *rune, 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 ReadLine added in v1.0.3

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

ReadLine reads in a single line from a bufio.Reader.

func StripBOM added in v1.0.3

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 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`. `search` cannot be nil/empty. `replace` can.

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.

type LineCountingReader added in v1.0.4

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 added in v1.0.4

func NewLineCountingReader(r io.Reader) *LineCountingReader

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

func (*LineCountingReader) AtLine added in v1.0.4

func (r *LineCountingReader) AtLine() int

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

func (*LineCountingReader) Read added in v1.0.4

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

Read implements the `io.Reader` interface.

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 added in v1.0.1

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