conversion

package
v0.0.0-...-f38f987 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseInt

func ParseInt(in []byte) (int, error)

func ParseSignedInts

func ParseSignedInts(in []byte) (int, error)

func ParseString

func ParseString(in []byte) (string, error)

func StringsToBytes

func StringsToBytes(in []string) [][]byte

Types

type Parser

type Parser[T any] func([]byte) (T, error)

type Tokenizer

type Tokenizer func([]byte) [][]byte
var SplitCharacters Tokenizer = func(b []byte) [][]byte {
	sc := bufio.NewScanner(bytes.NewReader(b))
	sc.Split(bufio.ScanRunes)
	out := [][]byte{}
	for sc.Scan() {
		char := make([]byte, len(sc.Bytes()))
		copy(char, sc.Bytes())
		out = append(out, char)
	}
	return out
}
var SplitCommas Tokenizer = func(b []byte) [][]byte {
	return StringsToBytes(strings.Split(string(b), ","))
}
var SplitLines Tokenizer = func(b []byte) [][]byte {
	sc := bufio.NewScanner(bytes.NewReader(b))
	out := [][]byte{}
	for sc.Scan() {
		line := make([]byte, len(sc.Bytes()))
		copy(line, sc.Bytes())
		out = append(out, line)
	}
	return out
}

Jump to

Keyboard shortcuts

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