Documentation ¶
Index ¶
- Constants
- Variables
- func AreIntegers(s string, sep rune, maxLen int) (bool, int)
- func AreUnsignedIntegers(s string, sep rune, maxLen int) (bool, int)
- func BigIntSliceFromString(str string) ([]*big.Int, error)
- func BoolSliceFromString(str string) ([]bool, error)
- func CopyInt(S []int) (T []int)
- func CopyStr(S []string) (T []string)
- func Float64SliceFromString(str string) ([]float64, error)
- func IndexInt(S []int, s int) int
- func IndexStr(S []string, s string) int
- func InsertInt(S []int, i int, s int) []int
- func Int16SliceFromString(str string) ([]int16, error)
- func Int32SliceFromString(str string) ([]int32, error)
- func Int64SliceFromString(str string) ([]int64, error)
- func Int64SlicesFromString(str string) ([][]int64, error)
- func Int8SliceFromString(str string) ([]int8, error)
- func IntSliceFromString(str string) ([]int, error)
- func JoinBigIntSlice(S []*big.Int, sep string) string
- func JoinBoolSlice(S []bool, sep string) string
- func JoinBoolSliceWithNames(S []bool, sep string, trueStr string, falseStr string) string
- func JoinInt16Slice(S []int16, sep string) string
- func JoinInt32Slice(S []int32, sep string) string
- func JoinInt64Slice(S []int64, sep string) string
- func JoinInt8Slice(S []int8, sep string) string
- func JoinIntSlice(S []int, sep string) string
- func JoinUint16Slice(S []uint16, sep string) string
- func JoinUint32Slice(S []uint32, sep string) string
- func JoinUint64Slice(S []uint64, sep string) string
- func JoinUint8Slice(S []uint8, sep string) string
- func JoinUintSlice(S []uint, sep string) string
- func RemoveInt(S []int, i int) []int
- func RemoveStr(S []string, i int) []string
- func ReverseInt(S []int) []int
- func ReverseInt32(S []int32) []int32
- func ReverseInt64(S []int64) []int64
- func SplitAndTrim(s string, sep string) (T []string)
- func StringNTimes(S string, sep string, N int) string
- func TrimSpaceAndSurroundingBrackets(s string) string
- func Uint16SliceFromString(str string) ([]uint16, error)
- func Uint32SliceFromString(str string) ([]uint32, error)
- func Uint64SliceFromString(str string) ([]uint64, error)
- func Uint8SliceFromString(str string) ([]uint8, error)
- func UintSliceFromString(str string) ([]uint, error)
- type Splitter
Constants ¶
const (
MsgFailedToConvertIndex = "Failed to convert entry at index %d."
)
Error messages.
const Sep = ','
Sep defines the separator used when splitting strings
Variables ¶
var ( ErrUninitializedSplitter = errors.New("Uninitialized splitter") ErrInvalidRune = errors.New("Invalid rune") ErrEOFWhilstEscaped = errors.New("Unexpected EOF whilst in an escaped sequence") ErrTooLarge = errors.New("Substring is too large") ErrUnbalancedBraces = errors.New("Unbalanced braces") ErrUnexpectedEndOfString = errors.New("Unexpected end of string") )
Common errors.
Functions ¶
func AreIntegers ¶
AreIntegers performs a check that the given string is of the form
[[:space:]*[-][:space:]*[0-9,:space:]+[:space:]*:sep:]*
i.e. represents a sequence of integers separated by the rune 'sep'. The "maxLen" argument specifies the maximum number of digits allowed in an integer; set to 0 to impose no limit. Returns true followed by the slice length on success, false followed by the index (in the slice) of the first malformed entry otherwise. (A rune is defined to be white-space if it satisfies unicode.IsSpace. If 'sep' is white-space, a digit, or '-' then a panic occurs.)
func AreUnsignedIntegers ¶
AreUnsignedIntegers performs a check that the given string is of the form
[[:space:]*[0-9,:space:]+[:space:]*:sep:]*
i.e. represents a sequence of unsigned integers separated by the rune 'sep'. The "maxLen" argument specifies the maximum number of digits allowed in an integer; set to 0 to impose no limit. Returns true followed by the slice length on success, false followed by the index (in the slice) of the first malformed entry otherwise. (A rune is defined to be white-space if it satisfies unicode.IsSpace.)
func BigIntSliceFromString ¶
BigIntSliceFromString converts a string into a slice of *big.Ints (i.e. []*big.Int).
func BoolSliceFromString ¶
BoolSliceFromString converts a string into a slice of bools (i.e. []bool).
func Float64SliceFromString ¶
Float64SliceFromString converts a string into a slice of float64s (i.e. []float64).
func Int16SliceFromString ¶
Int16SliceFromString converts a string into a slice of int16s (i.e. []int16).
func Int32SliceFromString ¶
Int32SliceFromString converts a string into a slice of int32s (i.e. []int32).
func Int64SliceFromString ¶
Int64SliceFromString converts a string into a slice of int64s (i.e. []int64).
func Int64SlicesFromString ¶
Int64SlicesFromString returns str as a slice of slices of int64s (i.e. [][]int64).
func Int8SliceFromString ¶
Int8SliceFromString converts a string into a slice of int8s (i.e. []int8).
func IntSliceFromString ¶
IntSliceFromString converts a string into a slice of ints (i.e. []int).
func JoinBigIntSlice ¶
JoinBigIntSlice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinBoolSlice ¶
JoinBoolSlice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string.
func JoinBoolSliceWithNames ¶
JoinBoolSliceWithNames concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string. The string trueStr will be used when a boolean is true; the string falseStr will be used when a boolean is false.
func JoinInt16Slice ¶
JoinInt16Slice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinInt32Slice ¶
JoinInt32Slice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinInt64Slice ¶
JoinInt64Slice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinInt8Slice ¶
JoinInt8Slice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinIntSlice ¶
JoinIntSlice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinUint16Slice ¶
JoinUint16Slice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinUint32Slice ¶
JoinUint32Slice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinUint64Slice ¶
JoinUint64Slice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string.
func JoinUint8Slice ¶
JoinUint8Slice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func JoinUintSlice ¶
JoinUintSlice concatenates the elements of S to create a single string. The separator string sep is placed between elements in the resulting string
func ReverseInt ¶
ReverseInt returns a new slice whose entries are equal to the entries of S, but in the reverse order.
func ReverseInt32 ¶
ReverseInt32 returns a new slice whose entries are equal to the entries of S, but in the reverse order.
func ReverseInt64 ¶
ReverseInt64 returns a new slice whose entries are equal to the entries of S, but in the reverse order.
func SplitAndTrim ¶
SplitAndTrim returns splits the string s using the separator sep, and trims any whitespace from the resulting substrings. Only non-empty substrings will be included in the returned slice.
func StringNTimes ¶
StringNTimes concatenates N copies of S to create a single string. The separator string sep is placed between elements in the resulting string.
func TrimSpaceAndSurroundingBrackets ¶
TrimSpaceAndSurroundingBrackets removes initial and training white-space and at most one matching pair of brackets from the string. White-space is as defined by unicode.IsSpace, valid pairs of matching brackets are '(',')' and '{','}' and '[',']'.
func Uint16SliceFromString ¶
Uint16SliceFromString converts a string into a slice of uint16s (i.e. []uint16).
func Uint32SliceFromString ¶
Uint32SliceFromString converts a string into a slice of uint32s (i.e. []uint32).
func Uint64SliceFromString ¶
Uint64SliceFromString converts a string into a slice of uint64s (i.e. []uint64).
func Uint8SliceFromString ¶
Uint8SliceFromString converts a string into a slice of uint8s (i.e. []uint8).
func UintSliceFromString ¶
UintSliceFromString converts a string into a slice of uints (i.e. []uint).
Types ¶
type Splitter ¶
type Splitter struct { // IsEscape is an optional function that should return true if the given rune is an escape rune. If true, the next rune will be escaped and added verbatim (along with the escape rune) to the returned substring. If io.EOF is reached whilst escaped, an ErrEOFWhilstEscaped error will be returned by Next(). IsEscape func(ch rune) bool // Ignore is an optional function that can be be used to ignored a rune when scanning the stream. Ignored runes will be skipped-over and not form part of any returned substrings. Ignore should return true if the given rune should be ignored. The escape rune, or a rune preceded by the escape rune, will not be considered. Ignore func(ch rune) bool // SplitOn is an optional function that can be used to specify the end of a substring (the split rune itself will not be included). If notspecified, splits will occur on ','. Ignored runes, the escape rune, or runes preceded by the escape rune, will not be considered. SplitOn func(ch rune) bool // IsValid is an optional function that can be used to validate the stream. It should return true if the given rune is valid, false otherwise. If IsValid returns false, then the Splitter's Next() function will return an ErrInvalidRune error. Split runes, ignored runes, the escape rune, or runes preceded by the escape rune, will not be considered. IsValid func(ch rune) bool // Set TrimSpace to true to have consecutive white-space (as defined by unicode.IsSpace) trimmed from the start and end of each substring. A rune will only be considered if it is valid, is not ignored, has not been escaped, and is not used for splitting the stream into substrings. TrimSpace bool // Set CollateSpace to true to have consecutive white-space (as defined by unicode.IsSpace) to a single ' '. A rune will only be considered if it is valid, is not ignored, has not been escaped, and is not used for splitting the stream into substrings. CollateSpace bool // Set MaxLength to the maximum length of a substring (or the default of for no limit beyond that imposed by bytes.Buffer). If the maximum length is exceeded, Next() will return an ErrTooLarge error. MaxLength int // contains filtered or unexported fields }
Splitter provides a convenient way of scanning an io.Reader and splitting it at specified runes.
func DefaultStringSplitter ¶
DefaultStringSplitter returns a new splitter for the given string. It will split on the seperator sep, automatically removing all white-space (as determined by univode.IsSpace) as it goes.
func (*Splitter) Index ¶
Index returns the index of the next rune in the stream to be read. Note that this count includes ignored runes, split runes, etc. hence may be larger the the total given by the substrings.