csv

package
v0.0.0-...-ebdd804 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func CompactSpacedStrings

func CompactSpacedStrings(rows [][]string) (numModified int)

CompactSpacedStrings removes spaces if they are between every other character, meaning that every odd character index is a space.

func ParseFileWithFormat

func ParseFileWithFormat(ctx context.Context, csvFile fs.FileReader, format *Format) (rows [][]string, err error)

func ParseWithFormat

func ParseWithFormat(data []byte, format *Format) (rows [][]string, err error)

func RemoveEmptyRows

func RemoveEmptyRows(rows [][]string) [][]string

RemoveEmptyRows removes rows without columns, or rows where all columns are empty strings.

func ReplaceNewlineWithSpacefunc

func ReplaceNewlineWithSpacefunc(rows [][]string)

func SetEmptyRowsNil

func SetEmptyRowsNil(rows [][]string) [][]string

SetEmptyRowsNil sets rows to nil, where all columns are empty strings.

func SetRowsWithNonUniformColumnsNil

func SetRowsWithNonUniformColumnsNil(rows [][]string) [][]string

SetRowsWithNonUniformColumnsNil set rows to nil that don't have the same field count as the majority of rows, so every rows is either nil or has the same number of fields.

Types

type ColumnMapping

type ColumnMapping struct {
	Index       int
	StructField string
}

type CompactSpacedStringsModifier

type CompactSpacedStringsModifier struct{}

func (CompactSpacedStringsModifier) Modify

func (m CompactSpacedStringsModifier) Modify(rows [][]string) [][]string

func (CompactSpacedStringsModifier) Name

type DataType

type DataType string
const (
	DataTypeString              DataType = "STRING"
	DataTypeNullableString      DataType = "NULL_STRING"
	DataTypeInt                 DataType = "INT"
	DataTypeNullableInt         DataType = "NULL_INT"
	DataTypeFloat               DataType = "FLOAT"
	DataTypeNullableFloat       DataType = "NULL_FLOAT"
	DataTypeMoneyAmount         DataType = "MONEY_AMOUNT"
	DataTypeNullableMoneyAmount DataType = "NULL_MONEY_AMOUNT"
	DataTypeCurrency            DataType = "CURRENCY"
	DataTypeNullableCurrency    DataType = "NULL_CURRENCY"
	DataTypeDate                DataType = "DATE"
	DataTypeNullableDate        DataType = "NULL_DATE"
	DataTypeTime                DataType = "TIME"
	DataTypeNullableTime        DataType = "NULL_TIME"
	DataTypeIBAN                DataType = "IBAN"
	DataTypeNullableIBAN        DataType = "NULL_IBAN"
	DataTypeBIC                 DataType = "BIC"
	DataTypeNullableBIC         DataType = "NULL_BIC"
)

func StringDataTypes

func StringDataTypes(str string) []DataType

StringDataTypes returns valid non nullable data types for the passed string. DataTypeString is not returned because it's always valid.

func (DataType) Nullable

func (t DataType) Nullable() bool

func (DataType) Valid

func (t DataType) Valid() bool

type Format

type Format struct {
	Encoding  string `json:"encoding"`
	Separator string `json:"separator"`
	Newline   string `json:"newline"`
}

func NewFormat

func NewFormat(separator string) *Format

NewFormat returns a Format with the passed separator, UTF-8 encoding, and "\r\n" newlines.

func ParseDetectFormat

func ParseDetectFormat(data []byte, configOrNil *FormatDetectionConfig) (rows [][]string, format *Format, err error)

ParseDetectFormat returns a slice of strings per row with the format detected via the FormatDetectionConfig.

func ParseFileDetectFormat

func ParseFileDetectFormat(ctx context.Context, csvFile fs.FileReader, configOrNil *FormatDetectionConfig) (rows [][]string, format *Format, err error)

ParseFileDetectFormat returns a slice of strings per row with the format detected via the FormatDetectionConfig.

func (*Format) Validate

func (f *Format) Validate() error

Validate returns an error in case of an invalid Format. Can be called on nil receiver.

type FormatDetectionConfig

type FormatDetectionConfig struct {
	Encodings     []string `json:"encodings"`
	EncodingTests []string `json:"encodingTests"`
}

func NewFormatDetectionConfig

func NewFormatDetectionConfig() *FormatDetectionConfig

type Modifier

type Modifier interface {
	Name() string
	Modify(rows [][]string) [][]string
}

type ModifierList

type ModifierList []Modifier

func (ModifierList) MarshalJSON

func (l ModifierList) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler

func (ModifierList) Modify

func (l ModifierList) Modify(rows [][]string) [][]string

func (*ModifierList) UnmarshalJSON

func (l *ModifierList) UnmarshalJSON(data []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler

type Reader

type Reader struct {
	Format          *Format                `json:"format,omitempty"`
	FormatDetection *FormatDetectionConfig `json:"formatDetection,omitempty"`
	ScanConfig      *strfmt.ScanConfig     `json:"config"`
	Modifiers       ModifierList           `json:"modifiers"`
	Columns         []ColumnMapping        `json:"columns"`
	// contains filtered or unexported fields
}

func NewReader

func NewReader(reader io.Reader, format *Format, newlineReplacement string, modifiers ModifierList, columns []ColumnMapping, scanConfig ...*strfmt.ScanConfig) (r *Reader, err error)

NewReader reads from an io.Reader

func NewReaderFromFile

func NewReaderFromFile(file fs.FileReader, format *Format, newlineReplacement string, modifiers ModifierList, columns []ColumnMapping, scanConfig ...*strfmt.ScanConfig) (r *Reader, err error)

NewReaderFromFile reads from a fs.FileReader

func NewReaderFromRows

func NewReaderFromRows(rows [][]string, format *Format, newlineReplacement string, modifiers ModifierList, columns []ColumnMapping, scanConfig ...*strfmt.ScanConfig) (r *Reader, err error)

NewReaderFromRows returns a Reader that uses pre-parsed rows

func (*Reader) NumRows

func (r *Reader) NumRows() int

func (*Reader) ReadRow

func (r *Reader) ReadRow(index int, destStruct reflect.Value) error

func (*Reader) ReadRowStrings

func (r *Reader) ReadRowStrings(index int) ([]string, error)

type RemoveBottomRowModifier

type RemoveBottomRowModifier struct{}

RemoveBottomRowModifier removes the given number of rows at the bottom

func (RemoveBottomRowModifier) Modify

func (m RemoveBottomRowModifier) Modify(rows [][]string) [][]string

func (RemoveBottomRowModifier) Name

type RemoveEmptyRowsModifier

type RemoveEmptyRowsModifier struct{}

func (RemoveEmptyRowsModifier) Modify

func (m RemoveEmptyRowsModifier) Modify(rows [][]string) [][]string

func (RemoveEmptyRowsModifier) Name

type RemoveTopRowModifier

type RemoveTopRowModifier struct{}

RemoveTopRowModifier removes the given number of rows at the top

func (RemoveTopRowModifier) Modify

func (m RemoveTopRowModifier) Modify(rows [][]string) [][]string

func (RemoveTopRowModifier) Name

func (m RemoveTopRowModifier) Name() string

type Renderer

type Renderer struct {
	*structtable.TextRenderer
	// contains filtered or unexported fields
}

func NewRenderer

func NewRenderer(config *strfmt.FormatConfig) *Renderer

func (*Renderer) MIMEType

func (*Renderer) MIMEType() string

func (*Renderer) RenderBeginTableText

func (csv *Renderer) RenderBeginTableText(writer io.Writer) error

func (*Renderer) RenderEndTableText

func (*Renderer) RenderEndTableText(writer io.Writer) error

func (*Renderer) RenderHeaderRowText

func (csv *Renderer) RenderHeaderRowText(writer io.Writer, columnTitles []string) error

func (*Renderer) RenderRowText

func (csv *Renderer) RenderRowText(writer io.Writer, fields []string) error

func (*Renderer) SetDelimiter

func (csv *Renderer) SetDelimiter(delimiter string) error

func (*Renderer) WithDelimiter

func (csv *Renderer) WithDelimiter(delimiter string) *Renderer

func (*Renderer) WithFormat

func (csv *Renderer) WithFormat(format *Format) *Renderer

func (*Renderer) WithHeaderComment

func (csv *Renderer) WithHeaderComment(headerSuffix string) *Renderer

func (*Renderer) WithQuoteAllFields

func (csv *Renderer) WithQuoteAllFields(quote bool) *Renderer

func (*Renderer) WithQuoteEmptyFields

func (csv *Renderer) WithQuoteEmptyFields(quote bool) *Renderer

type ReplaceNewlineWithSpaceModifier

type ReplaceNewlineWithSpaceModifier struct{}

func (ReplaceNewlineWithSpaceModifier) Modify

func (m ReplaceNewlineWithSpaceModifier) Modify(rows [][]string) [][]string

func (ReplaceNewlineWithSpaceModifier) Name

type SetBottomRowNilModifier

type SetBottomRowNilModifier struct{}

SetBottomRowNilModifier removes the given number of rows at the bottom

func (SetBottomRowNilModifier) Modify

func (m SetBottomRowNilModifier) Modify(rows [][]string) [][]string

func (SetBottomRowNilModifier) Name

type SetEmptyRowsNilModifier

type SetEmptyRowsNilModifier struct{}

func (SetEmptyRowsNilModifier) Modify

func (m SetEmptyRowsNilModifier) Modify(rows [][]string) [][]string

func (SetEmptyRowsNilModifier) Name

type SetRowsWithNonUniformColumnsNilModifier

type SetRowsWithNonUniformColumnsNilModifier struct{}

func (SetRowsWithNonUniformColumnsNilModifier) Modify

func (m SetRowsWithNonUniformColumnsNilModifier) Modify(rows [][]string) [][]string

func (SetRowsWithNonUniformColumnsNilModifier) Name

type SetTopRowNilModifier

type SetTopRowNilModifier struct{}

SetTopRowNilModifier removes the given number of rows at the top

func (SetTopRowNilModifier) Modify

func (m SetTopRowNilModifier) Modify(rows [][]string) [][]string

func (SetTopRowNilModifier) Name

func (m SetTopRowNilModifier) Name() string

Jump to

Keyboard shortcuts

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