strutil

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1 << 10
	MB = 1 << 20
	GB = 1 << 30
	TB = 1 << 40
)
View Source
const KVPairQuote = '\''

Variables

UTF8Len is an alias of utf8.RuneCountInString which returns the number of runes in s. Erroneous and short encodings are treated as single runes of width 1 byte.

Functions

func BytesAsString

func BytesAsString(b []byte) string

对[]byte的修改会影响到返回的string

func DecodeBase62String

func DecodeBase62String(s string) int64

解码Base62

func EncodeBase62String

func EncodeBase62String(id int64) string

编码Base62

func FindFirstDigit

func FindFirstDigit(s string) int

查找第一个数字的位置

func FindFirstNonDigit

func FindFirstNonDigit(s string) int

查找第一个非数字的位置

func LongestCommonPrefix

func LongestCommonPrefix(s1, s2 string) string

字符串最长共同前缀

func MustParseF32

func MustParseF32(s string) float32

func MustParseF64

func MustParseF64(s string) float64

func MustParseI16

func MustParseI16(s string) int16

func MustParseI32

func MustParseI32(s string) int32

func MustParseI64

func MustParseI64(s string) int64

func MustParseI8

func MustParseI8(s string) int8

func MustParseU16

func MustParseU16(s string) uint16

func MustParseU32

func MustParseU32(s string) uint32

func MustParseU64

func MustParseU64(s string) uint64

func MustParseU8

func MustParseU8(s string) uint8

func NameHash added in v0.6.1

func NameHash(name string) uint32

fnv-a hash

func ParseBool

func ParseBool(s string) bool

func ParseF32

func ParseF32(s string) (float32, error)

func ParseF64

func ParseF64(s string) (float64, error)

func ParseI16

func ParseI16(s string) (int16, error)

func ParseI32

func ParseI32(s string) (int32, error)

func ParseI64

func ParseI64(s string) (int64, error)

func ParseI8

func ParseI8(s string) (int8, error)

func ParseKeyValuePairs

func ParseKeyValuePairs(text string, sep, equal byte) map[string]string

解析字符串为K-V map, 示例:s = "a='x,y',c=z"

ParseSepKeyValues(s,",","=") ==> {"a":"x,y", "c":"z"}

func ParseU16

func ParseU16(s string) (uint16, error)

func ParseU32

func ParseU32(s string) (uint32, error)

func ParseU64

func ParseU64(s string) (uint64, error)

func ParseU8

func ParseU8(s string) (uint8, error)

func PrettyBytes

func PrettyBytes(n int64) string

打印容量大小

func RandBytes

func RandBytes(length int) []byte

随机长度的字节数组

func RandString

func RandString(length int) string

随机长度的字符串

func Reverse

func Reverse(str string) string

反转字符串

func RuneWidth

func RuneWidth(r rune) int

RuneWidth returns character width in monotype font. Multi-byte characters are usually twice the width of single byte characters.

Algorithm comes from `mb_strwidth` in PHP. http://php.net/manual/en/function.mb-strwidth.php

func StringAsBytes

func StringAsBytes(s string) []byte

StringAsBytes 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)

func ToCamelCase

func ToCamelCase(s string) string

ToCamel converts a string to CamelCase

func ToDelimited

func ToDelimited(s string, del uint8) string

ToDelimited converts a string to delimited.snake.case (in this case `del = '.'`)

func ToKebabCase

func ToKebabCase(s string) string

ToKebab converts a string to kebab-case

func ToLowerCamelCase

func ToLowerCamelCase(s string) string

ToLowerCamel converts a string to lowerCamelCase

func ToScreamingDelimited

func ToScreamingDelimited(s string, del uint8, screaming bool) string

ToScreamingDelimited converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`)

func ToScreamingKebab

func ToScreamingKebab(s string) string

ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE

func ToScreamingSnake

func ToScreamingSnake(s string) string

ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnake converts a string to snake_case

func UnmarshalJSON added in v0.1.8

func UnmarshalJSON(data []byte, v interface{}) error

使用bigint序列化大整数

func WordCount

func WordCount(str string) int

WordCount returns number of words in a string.

Word is defined as a locale dependent string containing alphabetic characters, which may also contain but not start with `'` and `-` characters.

Types

This section is empty.

Jump to

Keyboard shortcuts

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