fwv

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2019 License: Apache-2.0 Imports: 8 Imported by: 2

README

fwv

manipulate “Fixed Width Values”

fwv

Install

go get -u github.com/taskie/fwv/cmd/fwv

Usage

Convert CSV to Fixed Width Values
fwv foo.csv foo.txt

or

fwv -f csv <foo.csv >foo.txt
foo.csv (input)
a,bb,あいう,ccc
漢字,d,eee,f
foo.txt (output)
a    bb あいう ccc
漢字 d  eee    f
Convert Fixed Width Values to CSV
fwv foo.txt foo.csv

or

fwv -t csv <foo.txt >foo.csv
Treat "Eastern Asian Ambiguous Width" as halfwidth
fwv -E

or

env FWV_EAA_HALF_WIDTH=1 fwv
Ignore character width

Only the number of characters (runes) are considered.

fwv -W
Specify a delimiter
fwv -d '│'
foo.txt (output)
a   │bb│あいう│ccc
漢字│d │eee   │f

Dependencies

dependency

License

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version  = "0.1.0"
	Revision = ""
)

Functions

This section is empty.

Types

type ColumnSpec

type ColumnSpec struct {
	// contains filtered or unexported fields
}

type Converter

type Converter struct {
	Reader                  io.Reader
	Writer                  io.Writer
	FromType                string
	ToType                  string
	UseWidth                bool
	EastAsianAmbiguousWidth int
	Whitespaces             string
	NoTrim                  bool
	UseCRLF                 bool
	Comma                   rune
	CSVComment              rune
	Delimiter               string
	Colored                 bool
	ColumnRanges            []IntRange
	ShowColumnRanges        bool
}

func NewConverter

func NewConverter(w io.Writer, r io.Reader, fromType string, toType string) *Converter

func (*Converter) Convert

func (c *Converter) Convert() error

type IntRange

type IntRange struct {
	Begin int
	End   int
}

type ReadInfo

type ReadInfo struct {
	ColumnRanges []IntRange
}

type Reader

type Reader struct {
	UseWidthCalculator bool
	WidthCalculator    WidthCalculator
	ColumnRanges       []IntRange
	NoTrim             bool
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r io.Reader) Reader

func NewReaderWithWidthCalculator

func NewReaderWithWidthCalculator(r io.Reader, wcalc WidthCalculator) Reader

func (*Reader) ForEach

func (r *Reader) ForEach(handler func(record []string) error) (*ReadInfo, error)

func (*Reader) ReadAll

func (r *Reader) ReadAll() ([][]string, error)

func (*Reader) ReadAllInfo

func (r *Reader) ReadAllInfo() ([][]string, *ReadInfo, error)

func (*Reader) SetWhitespaces

func (r *Reader) SetWhitespaces(whitespaces string)

type SimpleWidthCalculator

type SimpleWidthCalculator struct{}

func (*SimpleWidthCalculator) CalcWidthOfRune

func (wcalc *SimpleWidthCalculator) CalcWidthOfRune(c rune) int

func (*SimpleWidthCalculator) CalcWidthOfString

func (wcalc *SimpleWidthCalculator) CalcWidthOfString(s string) int

type TextWidthCalculator

type TextWidthCalculator struct {
	EastAsianAmbiguousWidth int
}

func (*TextWidthCalculator) CalcWidthOfRune

func (wcalc *TextWidthCalculator) CalcWidthOfRune(c rune) int

func (*TextWidthCalculator) CalcWidthOfString

func (wcalc *TextWidthCalculator) CalcWidthOfString(s string) int

type WidthCalculator

type WidthCalculator interface {
	CalcWidthOfRune(c rune) int
	CalcWidthOfString(s string) int
}

type Writer

type Writer struct {
	WidthCalculator WidthCalculator
	UseCRLF         bool
	Colored         bool
	Delimiter       string
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer) Writer

func NewWriterWithWidthCalculator

func NewWriterWithWidthCalculator(w io.Writer, wcalc WidthCalculator) Writer

func (*Writer) CalcMaxWidthArrayOfColumns

func (w *Writer) CalcMaxWidthArrayOfColumns(records [][]string) []int

func (*Writer) ForEach

func (w *Writer) ForEach(records [][]string, handler func(line string) error) error

func (*Writer) WriteAll

func (w *Writer) WriteAll(records [][]string) error

Directories

Path Synopsis
cli
fwv
cmd
fwv

Jump to

Keyboard shortcuts

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