Documentation
¶
Overview ¶
Package parse turns the messy textual fields of a bank CSV (amounts, dates, raw rows) into the typed values the rest of ledgerly works with.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultDateLayouts = []string{
"2006-01-02",
"02.01.2006",
"2.1.2006",
"02/01/2006",
"2/1/2006",
"2006/01/02",
"02-01-2006",
}
DefaultDateLayouts are tried, in order, when a profile does not pin down its own date format. ISO comes first because it is unambiguous; the German day-first formats follow. Padded and non-padded variants are both listed so "2.1.2026" and "02.01.2026" both parse.
Functions ¶
func ParseAmount ¶
func ParseAmount(s string, dec DecimalSeparator) (model.Money, error)
ParseAmount parses a monetary string into model.Money (minor units). It copes with grouping separators, either decimal convention, surrounding whitespace, currency symbols and a leading sign.
Types ¶
type DecimalSeparator ¶
type DecimalSeparator int
DecimalSeparator tells the amount parser how to interpret '.' and ',' in a number. Auto guesses from the shape of the string, which is good enough for most exports; a bank profile can pin it down when the data is ambiguous.
const ( // DecimalAuto guesses the decimal separator from the input. DecimalAuto DecimalSeparator = iota // DecimalComma treats ',' as the decimal separator (1.234,56). DecimalComma // DecimalDot treats '.' as the decimal separator (1,234.56). DecimalDot )
type ReadOptions ¶
type ReadOptions struct {
// Delimiter is the field separator; 0 means auto-detect.
Delimiter rune
// SkipRows drops this many decoded lines before the header is read, for
// banks that print a preamble above the actual table.
SkipRows int
}
ReadOptions tunes how a CSV is read. The zero value auto-detects the delimiter and skips nothing, which is what ReadCSV uses.
type Table ¶
Table is a decoded CSV file: a header row plus the data rows, with the delimiter that was used so callers can report it.
func ReadCSV ¶
ReadCSV reads a CSV from r, auto-detecting both the byte encoding and the field delimiter. German bank exports are frequently semicolon-separated and encoded as Windows-1252 with a UTF-8 BOM, so we cannot assume the Go defaults.
func ReadCSVOpts ¶
func ReadCSVOpts(r io.Reader, opts ReadOptions) (*Table, error)
ReadCSVOpts reads a CSV honouring the given options.