strutil

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 DecodeBase62String

func DecodeBase62String(s string) int64

解码Base62

func EncodeBase62String

func EncodeBase62String(id int64) string

编码Base62

func FastBytesToString

func FastBytesToString(b []byte) string

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

func FastStringToBytes

func FastStringToBytes(s string) []byte

修改返回的[]byte会引起panic

func FindFirstDigit

func FindFirstDigit(s string) int

查找第一个数字的位置

func FindFirstNonDigit

func FindFirstNonDigit(s string) int

查找第一个非数字的位置

func FindStringInArray

func FindStringInArray(a []string, x string) int

在array中查找string

func LongestCommonPrefix

func LongestCommonPrefix(s1, s2 string) string

字符串最长共同前缀

func ParseBool

func ParseBool(s string) bool

func ParseF32

func ParseF32(s string) float32

func ParseF64

func ParseF64(s string) float64

func ParseI16

func ParseI16(s string) int16

func ParseI32

func ParseI32(s string) int32

func ParseI64

func ParseI64(s string) int64

func ParseI8

func ParseI8(s string) int8

func ParseKVToStruct

func ParseKVToStruct(env map[string]string, ptr reflect.Value)

将kv值设置到struct

func ParseSepKeyValues

func ParseSepKeyValues(text string, sep1, sep2 string) map[string]string

解析字符串为map,格式: "a='x,y',c=z" to {"a":"x,y", "c":"z"}

func ParseStringAs

func ParseStringAs(typename, value string) interface{}

解析字符串为数值、布尔

func ParseStringToValue

func ParseStringToValue(s string, v reflect.Value) bool

解析字符串的值到value

func ParseU16

func ParseU16(s string) uint16

func ParseU32

func ParseU32(s string) uint32

func ParseU64

func ParseU64(s string) uint64

func ParseU8

func ParseU8(s string) uint8

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