split

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: MIT Imports: 9 Imported by: 1

README

go-split

Performant string splitting and joining by comma, taking quotes into account. Useful for user supplied input e.g. CLI args

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinBools added in v1.1.0

func JoinBools[Bool ~bool](slice []Bool) string

JoinBools will pass bool slice to JoinFunc(), formatting and combining into a single comma-space separated string.

func JoinDurations added in v1.1.0

func JoinDurations(slice []time.Duration) string

JoinDurations will pass duration slice to JoinFunc(), formatting and combining into a single comma-space separated string.

func JoinFloats added in v1.1.0

func JoinFloats[Float constraints.Float](slice []Float) string

JoinFloats will pass float slice to JoinFunc(), formatting and combining into a single comma-space separated string.

func JoinFunc added in v1.1.0

func JoinFunc[T any](slice []T, each func(buf []byte, idx int) []byte, size int) string

JoinFunc will join given slice of elements, using the passed function to append each element at index from the slice, forming a combined comma-space separated string. Passed size is for buffer preallocation.

func JoinInts added in v1.1.0

func JoinInts[Int constraints.Signed](slice []Int) string

JoinInts will pass signed integer slice to JoinFunc(), formatting and combining into a single comma-space separated string.

func JoinSizes added in v1.1.0

func JoinSizes(slice []bytesize.Size) string

JoinSizes will pass byte size slice to JoinFunc(), formatting and combining into a single comma-space separated string.

func JoinStrings added in v1.1.0

func JoinStrings[String ~string](slice []String) string

JoinStrings will pass string slice to JoinFunc(), quoting where necessary and combining into a single comma-space separated string.

func JoinTimes added in v1.1.0

func JoinTimes(slice []time.Time, format string) string

JoinTimes will pass time slice to JoinFunc(), formatting and combining into a single comma-space separated string.

func JoinUints added in v1.1.0

func JoinUints[Uint constraints.Unsigned](slice []Uint) string

JoinUints will pass unsigned integer slice to JoinFunc(), formatting and combining into a single comma-space separated string.

func SplitBools added in v1.1.0

func SplitBools[Bool ~bool](str string) ([]Bool, error)

SplitBools will pass string input to SplitFunc(), parsing and compiling a slice of bools.

func SplitDurations added in v1.1.0

func SplitDurations(str string) ([]time.Duration, error)

SplitDurations will pass string input to SplitFunc(), parsing and compiling a slice of durations.

func SplitFloats added in v1.1.0

func SplitFloats[Float constraints.Float](str string) ([]Float, error)

SplitFloats will pass string input to SplitFunc(), parsing and compiling a slice of floats.

func SplitFunc added in v1.1.0

func SplitFunc(str string, fn func(string) error) error

SplitFunc will split input string on commas, taking into account string quoting and stripping extra whitespace, passing each split to the given function hook.

func SplitInts added in v1.1.0

func SplitInts[Int constraints.Signed](str string) ([]Int, error)

SplitInts will pass string input to SplitFunc(), parsing and compiling a slice of signed integers.

func SplitSizes added in v1.1.0

func SplitSizes(str string) ([]bytesize.Size, error)

SplitSizes will pass string input to SplitFunc(), parsing and compiling a slice of byte sizes.

func SplitStrings added in v1.1.0

func SplitStrings[String ~string](str string) ([]String, error)

SplitStrings will pass string input to SplitFunc(), compiling a slice of strings.

func SplitTimes added in v1.1.0

func SplitTimes(str string, format string) ([]time.Time, error)

SplitTimes will pass string input to SplitFunc(), parsing and compiling a slice of times.

func SplitUints added in v1.1.0

func SplitUints[Uint constraints.Unsigned](str string) ([]Uint, error)

SplitUints will pass string input to SplitFunc(), parsing and compiling a slice of unsigned integers.

Types

type Splitter

type Splitter struct{ B []byte }

Splitter holds onto a byte buffer for use in minimising allocations during SplitFunc().

func (*Splitter) SplitFunc

func (s *Splitter) SplitFunc(str string, fn func(string) error) error

SplitFunc will split input string on commas, taking into account string quoting and stripping extra whitespace, passing each split to the given function hook.

Jump to

Keyboard shortcuts

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