Documentation
¶
Overview ¶
Parse a whitespace separated list of values
Index ¶
- Variables
- func Unmarshal(d []byte, v any) error
- type Line
- type Reader
- func (r *Reader) ColumnNameOf(i int) (*string, error)
- func (r *Reader) CurrentRow() int
- func (r *Reader) Headers() []string
- func (r *Reader) IndexedAt(n string) []int
- func (r *Reader) Read() (Line, error)
- func (r *Reader) ReadAll() (records []Line, err error)
- func (r *Reader) ToDocument() (*doc.Document, error)
- type UnmarshalWSV
Constants ¶
This section is empty.
Variables ¶
var ( ErrFieldCount = errors.New("wrong number of fields") ErrLineFeedTerm = errors.New("line feed terminated before the line end end") ErrInvalidNull = errors.New("null `-` specifier cannot be included without white space surrounding, unless it is the last value in the line. To record a literal `-` please wrap the value in double quotes") ErrBareQuote = errors.New("bare \" in non-quoted-field") ErrReaderEnded = errors.New("reader ended, nothing left to read") ErrCommentPlacement = errors.New("comments should be the last elements in a row, if immediate preceding lines are null, they cannot be omitted and must be explicitly declared") )
var ( ErrFieldNotFound = errors.New("field does not exist") ErrEndOfLine = errors.New("no more fields left in this line") )
Functions ¶
Types ¶
type Line ¶ added in v1.1.0
type Line interface {
// Returns the field value at the 0-index or `ErrFieldNotFound` if out of bounds
Field(fi int) (*internal.Field, error)
// Get the value of comment for the line
Comment() string
// Get the line number
LineNumber() int
// A count of the number of data fields in the line
FieldCount() int
// Get the next field value, or error if at the end of the line for data
NextField() (*internal.Field, error)
// Returns true if the line is a slice of headers
IsHeaderLine() bool
// Returns serialized values of all fields on a line
FieldsValues() []string
// All the fields in the line
Fields() []internal.Field
}
type Reader ¶
type Reader struct {
IncludesHeader bool
IsTabular bool
NullTrailingColumns bool
AllowPartialError bool
// contains filtered or unexported fields
}
A WSV Document Reader
func NewReader ¶
Creates a new WSV NewReader
- By default the first non-empty and non-comment line is considered the header
- By default it expects a tabular [each record has the same number of fields] document
- By default omitted trailing fields for a record are allowed
func (*Reader) ColumnNameOf ¶
Return the column name at the index i, will return "" if not found
func (*Reader) Read ¶
Reads the current line of a reader and returns a *Line.
- If `r.IsTabular == true` and the current line being parsed has more fields than amount of headers `r.Read()` returns a the *Line along with the error *ParseError.
- If the record contains a field that cannot be parsed, `r.Read()` returns a *Line with as many records as it could before encountering an error. The partial record contains all fields read before the error.
- If there is no data left to be read, `r.Read()` returns a *Line with an empty slice Fields and io.EOF.
- Subsequent calls to `r.Read()` after io.EOF returns a nil and ErrReaderEnded