splitter

package module
v0.0.0-...-ab480d2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindCsvRecordStart

func FindCsvRecordStart(buffer SplitBuffer, start int, expectNRecords int) int

FindCsvRecordStart finds the next closest possible starting position of a CSV record in the buffer. It starts searching from the starting index to find the next unquoted newline character under two scenarios:

  1. Assuming the search starts within quotes.
  2. Assuming the search starts outside of quotes.

For each of the found newline positions, it attempts to parse the subsequent data as CSV records, expecting a specified number of records that all share the same number of fields. If a valid starting position is found where the expected number of records can be parsed correctly, it returns that position. If no valid starting position is found, it returns -1.

func FindNextUnquotedNewline

func FindNextUnquotedNewline(buffer SplitBuffer, start int) [2]int

FindNextUnquotedNewline finds the next unquoted newline character in the buffer starting from the given index. It returns two indices:

  1. The index assuming the search starts within quotes.
  2. The index assuming the search starts outside of quotes.

Types

type SplitBuffer

type SplitBuffer []byte

SplitBuffer is a byte slice with helper methods for parsing CSV data.

func (SplitBuffer) Eof

func (b SplitBuffer) Eof(at int) bool

Eof checks if the given index is at or beyond the end of the buffer.

func (SplitBuffer) Equals

func (b SplitBuffer) Equals(at int, r ...rune) bool

Equals checks if the buffer matches one or more runes starting at the given index.

func (SplitBuffer) FindClosingQuote

func (b SplitBuffer) FindClosingQuote(start int) int

FindClosingQuote finds the index of the next possible closing quote starting from the given index. That is, it finds the next non-double quote character. It returns -1 if no closing quote is found.

func (SplitBuffer) IsEscapedQuote

func (b SplitBuffer) IsEscapedQuote(at int) bool

IsEscapedQuote checks if the given index is an escaped quote (two consecutive double quotes).

func (SplitBuffer) IsNewline

func (b SplitBuffer) IsNewline(at int) bool

IsNewline checks if the given index is a newline character or sequence.

func (SplitBuffer) IsQuote

func (b SplitBuffer) IsQuote(at int) bool

IsQuote checks if the given index is a quote character.

func (SplitBuffer) NextIndexOf

func (b SplitBuffer) NextIndexOf(r rune, start int) int

NextIndexOf returns the index of the next occurrence of the given rune starting from the specified index.

Jump to

Keyboard shortcuts

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