csvtable

package
v0.0.0-...-508fc3c Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeQuotes

func EscapeQuotes(val string) string

Types

type Encoder

type Encoder interface {
	Bytes([]byte) ([]byte, error)
}

Encoder is an interface to encode byte strings.

func PassthroughEncoder

func PassthroughEncoder() Encoder

PassthroughEncoder returns an Encoder that returns the passed data unchanged.

type EncoderFunc

type EncoderFunc func([]byte) ([]byte, error)

EncoderFunc implements the Encoder interface for a function.

func (EncoderFunc) Bytes

func (f EncoderFunc) Bytes(data []byte) ([]byte, error)

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 (*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 Padding

type Padding int
const (
	NoPadding Padding = iota
	AlignLeft
	AlignRight
	AlignCenter
)

type Writer

type Writer[T any] struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter[T any]() *Writer[T]

func (*Writer[T]) Delimiter

func (w *Writer[T]) Delimiter() rune

func (*Writer[T]) Encoder

func (w *Writer[T]) Encoder() Encoder

func (*Writer[T]) EscapeQuotes

func (w *Writer[T]) EscapeQuotes() string

func (*Writer[T]) NewLine

func (w *Writer[T]) NewLine() string

func (*Writer[T]) NilValue

func (w *Writer[T]) NilValue() string

func (*Writer[T]) QuoteAllFields

func (w *Writer[T]) QuoteAllFields() bool

func (*Writer[T]) QuoteEmptyFields

func (w *Writer[T]) QuoteEmptyFields() bool

func (*Writer[T]) ViewStrings

func (w *Writer[T]) ViewStrings(ctx context.Context, view retable.View) ([][]string, error)

ViewStrings returns the view formatted as a slice of string slices.

func (*Writer[T]) WithColumnFormatter

func (w *Writer[T]) WithColumnFormatter(columnIndex int, formatter retable.CellFormatter) *Writer[T]

WithColumnFormatter returns a new writer with the passed formatter registered for columnIndex. If nil is passed as formatter, then a previous registered column formatter is removed.

func (*Writer[T]) WithColumnFormatterFunc

func (w *Writer[T]) WithColumnFormatterFunc(columnIndex int, formatterFunc retable.CellFormatterFunc) *Writer[T]

WithColumnFormatterFunc returns a new writer with the passed formatterFunc registered for columnIndex. If nil is passed as formatterFunc, then a previous registered column formatter is removed.

func (*Writer[T]) WithDelimiter

func (w *Writer[T]) WithDelimiter(delimiter rune) *Writer[T]

func (*Writer[T]) WithEncoder

func (w *Writer[T]) WithEncoder(encoder Encoder) *Writer[T]

func (*Writer[T]) WithEscapeQuotes

func (w *Writer[T]) WithEscapeQuotes(escapeQuotes string) *Writer[T]

func (*Writer[T]) WithHeaderRow

func (w *Writer[T]) WithHeaderRow(headerRow bool) *Writer[T]

func (*Writer[T]) WithInterfaceTypeFormatter

func (w *Writer[T]) WithInterfaceTypeFormatter(typ reflect.Type, fmt retable.CellFormatter) *Writer[T]

func (*Writer[T]) WithInterfaceTypeFormatterFunc

func (w *Writer[T]) WithInterfaceTypeFormatterFunc(typ reflect.Type, fmt retable.CellFormatterFunc) *Writer[T]

func (*Writer[T]) WithKindFormatter

func (w *Writer[T]) WithKindFormatter(kind reflect.Kind, fmt retable.CellFormatter) *Writer[T]

func (*Writer[T]) WithKindFormatterFunc

func (w *Writer[T]) WithKindFormatterFunc(kind reflect.Kind, fmt retable.CellFormatterFunc) *Writer[T]

func (*Writer[T]) WithNewLine

func (w *Writer[T]) WithNewLine(newLine string) *Writer[T]

func (*Writer[T]) WithNilValue

func (w *Writer[T]) WithNilValue(nilValue string) *Writer[T]

func (*Writer[T]) WithPadding

func (w *Writer[T]) WithPadding(padding Padding) *Writer[T]

func (*Writer[T]) WithQuoteAllFields

func (w *Writer[T]) WithQuoteAllFields(quoteAllFields bool) *Writer[T]

func (*Writer[T]) WithQuoteEmptyFields

func (w *Writer[T]) WithQuoteEmptyFields(quoteEmptyFields bool) *Writer[T]

func (*Writer[T]) WithTableViewer

func (w *Writer[T]) WithTableViewer(viewer retable.Viewer) *Writer[T]

func (*Writer[T]) WithTypeFormatter

func (w *Writer[T]) WithTypeFormatter(typ reflect.Type, fmt retable.CellFormatter) *Writer[T]

func (*Writer[T]) WithTypeFormatterFunc

func (w *Writer[T]) WithTypeFormatterFunc(typ reflect.Type, fmt retable.CellFormatterFunc) *Writer[T]

func (*Writer[T]) WithTypeFormatterReflectFunc

func (w *Writer[T]) WithTypeFormatterReflectFunc(function any) *Writer[T]

func (*Writer[T]) WithTypeFormatterReflectRawFunc

func (w *Writer[T]) WithTypeFormatterReflectRawFunc(function any) *Writer[T]

func (*Writer[T]) WithTypeFormatters

func (w *Writer[T]) WithTypeFormatters(formatter *retable.ReflectTypeCellFormatter) *Writer[T]

func (*Writer[T]) Write

func (w *Writer[T]) Write(ctx context.Context, dest io.Writer, table T) error

Write calls WriteView with the result of Viewer.NewView(table) using the writer's viewer if not nil or else retable.DefaultViewer.

func (*Writer[T]) WriteView

func (w *Writer[T]) WriteView(ctx context.Context, dest io.Writer, view retable.View) error

WriteView writes the view to dest as formatted as CSV.

func (*Writer[T]) WriteWithViewer

func (w *Writer[T]) WriteWithViewer(ctx context.Context, dest io.Writer, viewer retable.Viewer, table T) error

WriteWithViewer calls WriteView with the result of viewer.NewView(table).

Jump to

Keyboard shortcuts

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