Documentation ¶
Index ¶
- Constants
- func ByteReadLine(r *bufio.Reader) ([]byte, error)
- func DirExists(dir string) bool
- func FileExists(file string) bool
- func NewScannerByDelim(r io.Reader, delim []byte, flags ScannerByDelimFlag) *bufio.Scanner
- func NewScannerByDelim2(r io.Reader, delim, escape []byte, flags ScannerByDelimFlag) *bufio.Scanner
- func NewScannerByDelim3(r io.Reader, delim, escape []byte, flags ScannerByDelimFlag, buf []byte) *bufio.Scanner
- func ReadLine(r *bufio.Reader) (string, error)
- func StripBOM(reader io.Reader) (io.Reader, error)
- type BytesReplacingReader
- type LineCountingReader
- type LineNumReportingCsvReader
- type ScannerByDelimFlag
Constants ¶
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 )
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
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 FileExists ¶ added in v0.0.4
FileExists checks if a file exists or not.
func NewScannerByDelim ¶
NewScannerByDelim creates a scanner that returns tokens from the source reader separated by a delimiter.
func NewScannerByDelim2 ¶
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.
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 ¶
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.
type LineNumReportingCsvReader ¶
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.