conv

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SepSpace       = " "
	SepColon       = ":"
	SepComma       = ","
	SepEqualSign   = "="
	SepVerticalBar = "|"
)

Variables

This section is empty.

Functions

func BoolTo

func BoolTo[T Integer](b bool) T

BoolTo converts a bool to integer

func BytesAsStr

func BytesAsStr(b []byte) string

BytesAsStr returns the string view of byte slice

func IntToBool

func IntToBool[T Integer](v T) bool

IntToBool converts an integer to bool

func MustParseF32

func MustParseF32(s string) float32

MustParseF32 parse string to float32, panic if error

func MustParseF64

func MustParseF64(s string) float64

MustParseF64 parse string to float64, panic if error

func MustParseI16

func MustParseI16(s string) int16

MustParseI16 parse string to int16, panic if error

func MustParseI32

func MustParseI32(s string) int32

MustParseI32 parse string to int32, panic if error

func MustParseI64

func MustParseI64(s string) int64

MustParseI64 parse string to int64, panic if error

func MustParseI8

func MustParseI8(s string) int8

MustParseI8 parse string to int8, panic if error

func MustParseTo

func MustParseTo[T cmp.Ordered | bool](s string) T

func MustParseU16

func MustParseU16(s string) uint16

MustParseU16 parse string to uint16, panic if error

func MustParseU32

func MustParseU32(s string) uint32

MustParseU32 parse string to uint32, panic if error

func MustParseU64

func MustParseU64(s string) uint64

MustParseU64 parse string to uint64, panic if error

func MustParseU8

func MustParseU8(s string) uint8

MustParseU8 parse string to uint8, panic if error

func ParseBool

func ParseBool(s string) bool

ParseBool parse string to bool

func ParseF32

func ParseF32(s string) (float32, error)

ParseF32 parse string to float32

func ParseF64

func ParseF64(s string) (float64, error)

ParseF64 parse string to float64

func ParseI16

func ParseI16(s string) (int16, error)

ParseI16 parse string to int16

func ParseI32

func ParseI32(s string) (int32, error)

ParseI32 parse string to int32

func ParseI64

func ParseI64(s string) (int64, error)

ParseI64 parse string to int64

func ParseI8

func ParseI8(s string) (int8, error)

ParseI8 parse string to int8

func ParseKeyValues

func ParseKeyValues[K, V cmp.Ordered](text string, sep1, sep2 string) ([]K, []V)

ParseKeyValues 解析字符串为K-V slice

func ParseMap

func ParseMap[K, V cmp.Ordered](text string, sep1, sep2 string) map[K]V

ParseMap 解析字符串为K-V map, 示例: ParseKVPairs("x=1|y=2", SepEqualSign, SepVerticalBar) -> {"a":"x,y", "c":"z"}

func ParseSlice

func ParseSlice[T cmp.Ordered](text, sep string) []T

func ParseTo

func ParseTo[T cmp.Ordered | bool](s string) (T, error)

ParseTo parse string to any number type this generic routine is 12%-20% slower than concrete ParseXXX version, see conv_test.go

func ParseU16

func ParseU16(s string) (uint16, error)

ParseU16 parse string to uint16

func ParseU32

func ParseU32(s string) (uint32, error)

ParseU32 parse string to uint32

func ParseU64

func ParseU64(s string) (uint64, error)

ParseU64 parse string to uint64

func ParseU8

func ParseU8(s string) (uint8, error)

ParseU8 parse string to uint8

func StrAsBytes

func StrAsBytes(s string) []byte

StrAsBytes returns the bytes backing a string, it is the caller's responsibility not to mutate the bytes returned. see https://pkg.go.dev/unsafe#Pointer rule(6)

Types

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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