Import path:
gitlab.soludian.com/soludian/fountain/libs/base/string_util
string_util
import "gitlab.soludian.com/soludian/fountain/libs/base/string_util"Match provides a simple pattern matcher with unicode support.
Package string_util provide some string,char,byte util functions
Index
- Constants
- Variables
- func AddIrregularRule(single string, plural string)
- func AddPluralRule(rule string, replacement string)
- func AddSingularRule(rule string, replacement string)
- func AddSlashes(s string) string
- func AddUncountableRule(word string)
- func AfterFirst(s, sep string) string
- func AfterLast(s, sep string) string
- func Allowable(pattern string) (min, max string)
- func AnyToString(val any, defaultAsErr bool) (s string, err error)
- func B32HexDecode(str string) string
- func B32HexEncode(str string) string
- func B32StdDecode(str string) string
- func B32StdEncode(str string) string
- func B64RawURLDecode(str string) string
- func B64RawURLDecodeBytes(str string) []byte
- func B64RawURLEncode(str string) string
- func B64RawURLEncodeBytes(src []byte) string
- func B64StdDecode(str string) string
- func B64StdDecodeBytes(str string) []byte
- func B64StdEncode(str string) string
- func B64StdEncodeBytes(src []byte) string
- func B64URLDecode(str string) string
- func B64URLDecodeBytes(str string) []byte
- func B64URLEncode(str string) string
- func B64URLEncodeBytes(src []byte) string
- func BeforeFirst(s, sep string) string
- func BeforeLast(s, sep string) string
- func BlankOr(val, defVal string) string
- func Bool(s string) (bool, error)
- func Byte2str(b []byte) string
- func Byte2string(b []byte) string
- func BytePos(s string, bt byte) int
- func Camel(s string, sep ...string) string
- func CamelCase(s string, sep ...string) string
- func Compare(s1, s2, op string) bool
- func ContainsAll(s string, subs []string) bool
- func ContainsByte(s string, c byte) bool
- func ContainsOne(s string, subs []string) bool
- func Cut(s, sep string) (before string, after string, found bool)
- func DatetimeNo(prefix string) string
- func EscapeHTML(s string) string
- func EscapeJS(s string) string
- func FilterEmail(s string) string
- func FirstLine(output string) string
- func Float32(s string) float32
- func Float32Or(s string, defVal float32) float32
- func Float32OrDefault(s string, defVal float32) float32
- func Float32OrErr(s string) (float32, error)
- func Float32OrPanic(s string) float32
- func Float64(s string) float64
- func Float64Or(s string, defVal float64) float64
- func Float64OrDefault(s string, defVal float64) float64
- func Float64OrErr(s string) (float64, error)
- func Float64OrPanic(s string) float64
- func FromBytes(b []byte) string
- func GlobMatch(pattern, s string) bool
- func HasAllSubs(s string, subs []string) bool
- func HasEmpty(ss ...string) bool
- func HasOnePrefix(s string, prefixes []string) bool
- func HasOneSub(s string, subs []string) bool
- func HasOneSuffix(s string, suffixes []string) bool
- func HasPrefix(s string, prefix string) bool
- func HasSuffix(s string, suffix string) bool
- func IContains(s, sub string) bool
- func IEqual(s1, s2 string) bool
- func Implode(sep string, ss ...string) string
- func Indent(s, prefix string) string
- func IndentBytes(b, prefix []byte) []byte
- func Int(s string) (int, error)
- func Int32(s string) (int32, error)
- func Int32Or(s string, defVal int32) int32
- func Int32OrDefault(s string, defVal int32) int32
- func Int32OrPanic(s string) int32
- func Int64(s string) int64
- func Int64Or(s string, defVal int64) int64
- func Int64OrDefault(s string, defVal int64) int64
- func Int64OrErr(s string) (int64, error)
- func Int64OrPanic(s string) int64
- func IntOr(s string, defVal int) int
- func IntOrDefault(s string, defVal int) int
- func IntOrPanic(s string) int
- func Ints(s string, sep ...string) []int
- func IsAllEmpty(ss ...string) bool
- func IsAlphaNum(c uint8) bool
- func IsAlphabet(char uint8) bool
- func IsBlank(s string) bool
- func IsBlankBytes(bs []byte) bool
- func IsEmpty(s string) bool
- func IsEndOf(s, suffix string) bool
- func IsNotBlank(s string) bool
- func IsNumChar(c byte) bool
- func IsNumeric(s string) bool
- func IsPlural(word string) bool
- func IsSingular(word string) bool
- func IsSpace(c byte) bool
- func IsSpaceRune(r rune) bool
- func IsStartOf(s, prefix string) bool
- func IsStartsOf(s string, prefixes []string) bool
- func IsSymbol(r rune) bool
- func IsValidUtf8(s string) bool
- func IsVersion(s string) bool
- func Join(sep string, ss ...string) string
- func JoinAny(sep string, parts ...any) string
- func JoinList(sep string, ss []string) string
- func LTrim(s string, cutSet ...string) string
- func LikeMatch(pattern, s string) bool
- func Lower(s string) string
- func LowerFirst(s string) string
- func Lowercase(s string) string
- func Ltrim(s string, cutSet ...string) string
- func MatchNodePath(pattern, s string, sep string) bool
- func MaybeWildcard(str string) bool
- func MicroTimeHexID() string
- func MicroTimeID() string
- func MustBool(s string) bool
- func MustCut(s, sep string) (before string, after string)
- func MustFloat32(s string) float32
- func MustFloat64(s string) float64
- func MustInt(s string) int
- func MustInt32(s string) int32
- func MustInt64(s string) int64
- func MustString(val any) string
- func MustToTime(s string, layouts ...string) time.Time
- func MustUint(s string) uint64
- func NewReplacer(pairs map[string]string) *strings.Replacer
- func NewShortUUID() string
- func NewULID() string
- func NewUUID() string
- func NoCaseEq(s, t string) bool
- func OrCond(cond bool, s1, s2 string) string
- func OrElse(s, orVal string) string
- func OrHandle(s string, fn com_def.StringHandleFunc) string
- func PadBytes(bs []byte, pad byte, length int, pos PosFlag) []byte
- func PadBytesLeft(bs []byte, pad byte, length int) []byte
- func PadBytesRight(bs []byte, pad byte, length int) []byte
- func PadChars[T byte | rune](cs []T, pad T, length int, pos PosFlag) []T
- func PadLeft(s, pad string, length int) string
- func PadRight(s, pad string, length int) string
- func PadRunes(rs []rune, pad rune, length int, pos PosFlag) []rune
- func PadRunesLeft(rs []rune, pad rune, length int) []rune
- func PadRunesRight(rs []rune, pad rune, length int) []rune
- func Padding(s, pad string, length int, pos PosFlag) string
- func ParseSizeRange(expr string, opt *ParseSizeOpt) (min, max uint64, err error)
- func PathMatch(pattern, s string) bool
- func Plural(word string) string
- func Pluralize(word string, count int, inclusive bool) string
- func QuickMatch(pattern, s string) bool
- func QuietBool(s string) bool
- func QuietCut(s, sep string) (before string, after string)
- func QuietFloat32(s string) float32
- func QuietFloat64(s string) float64
- func QuietInt(s string) int
- func QuietInt32(s string) int32
- func QuietInt64(s string) int64
- func QuietString(val any) string
- func Quote(s string) string
- func RTrim(s string, cutSet ...string) string
- func RandWithTpl(n int, letters string) string
- func RandomBytes(length int) ([]byte, error)
- func RandomChars(ln int) string
- func RandomCharsV2(ln int) string
- func RandomCharsV3(ln int) string
- func RandomString(length int) (string, error)
- func RemoveDiacritics(s string) string
- func RenderTemplate(input string, data any, fns template.FuncMap, isFile ...bool) string
- func RenderText(input string, data any, fns template.FuncMap, isFile ...bool) string
- func Repeat(s string, times int) string
- func RepeatBytes(char byte, times int) []byte
- func RepeatChars[T byte | rune](char T, times int) []T
- func RepeatRune(char rune, times int) []rune
- func ReplaceAll(s string, old string, new string) string
- func Replaces(str string, pairs map[string]string) string
- func ReplacesAll(s string, new string, olds ...string) string
- func Resize(s string, length int, align PosFlag) string
- func Rtrim(s string, cutSet ...string) string
- func RuneCount(s string) int
- func RuneIsLower(c rune) bool
- func RuneIsUpper(c rune) bool
- func RuneIsWord(c rune) bool
- func RunePos(s string, ru rune) int
- func RuneWidth(r rune) int
- func RunesWidth(rs []rune) (w int)
- func SafeBool(s string) bool
- func SafeByteSize(sizeStr string) uint64
- func SafeFloat32(s string) float32
- func SafeFloat64(s string) float64
- func SafeInt(s string) int
- func SafeInt32(s string) int32
- func SafeInt64(s string) int64
- func SafeString(in any) string
- func SafeUint(s string) uint64
- func Similarity(s, t string, rate float32) (float32, bool)
- func SimpleMatch(s string, keywords []string) bool
- func Singular(word string) string
- func SnakeCase(s string, sep ...string) string
- func Split(s, sep string) (ss []string)
- func SplitInlineComment(val string, strict ...bool) (string, string)
- func SplitKV(s, sep string) (string, string)
- func SplitN(s, sep string, n int) (ss []string)
- func SplitNTrimmed(s, sep string, n int) (ss []string)
- func SplitNValid(s, sep string, n int) (ss []string)
- func SplitTrimmed(s, sep string) (ss []string)
- func SplitValid(s, sep string) (ss []string)
- func StandardizedCapitalizeCamel(input string) string
- func StandardizedCapitalizeWords(input string) string
- func StandardizedNumber(number, lenNumber int) string
- func StrPos(s, sub string) int
- func String(val any) (string, error)
- func StringOr(val any, defVal string) string
- func StringOrDefault(val any, defVal string) string
- func StringOrErr(val any) (string, error)
- func StringOrPanic(val any) string
- func Strings(s string, sep ...string) []string
- func StripSlashes(s string) string
- func Substr(s string, pos, length int) string
- func SubstrCount(s, substr string, params ...uint64) (int, error)
- func TextSplit(s string, w int) []string
- func TextTruncate(s string, w int, tail string) string
- func TextWidth(s string) int
- func TextWrap(s string, w int) string
- func Title(s string) string
- func ToArray(s string, sep ...string) []string
- func ToBool(s string) (bool, error)
- func ToByteSize(sizeStr string) (uint64, error)
- func ToBytes(s string) (b []byte)
- func ToDuration(s string) (time.Duration, error)
- func ToFloat32(s string) (float32, error)
- func ToFloat64(s string) (float64, error)
- func ToInt(s string) (int, error)
- func ToInt32(s string) (int32, error)
- func ToInt64(s string) (int64, error)
- func ToIntSlice(s string, sep ...string) (ints []int, err error)
- func ToInts(s string, sep ...string) ([]int, error)
- func ToSlice(s string, sep ...string) []string
- func ToString(val any) (string, error)
- func ToStringWithFunc(val any, fbFn com_def.ToStringFunc) (str string, err error)
- func ToStrings(s string, sep ...string) []string
- func ToTime(s string, layouts ...string) (t time.Time, err error)
- func ToUint(s string) (uint64, error)
- func Trim(s string, cutSet ...string) string
- func TrimCut(s, sep string) (string, string)
- func TrimLeft(s string, cutSet ...string) string
- func TrimRight(s string, cutSet ...string) string
- func Truncate(s string, w int, tail string) string
- func URLDecode(s string) string
- func URLEncode(s string) string
- func Uint(s string) uint64
- func UintOr(s string, defVal uint64) uint64
- func UintOrDefault(s string, defVal uint64) uint64
- func UintOrErr(s string) (uint64, error)
- func UintOrPanic(s string) uint64
- func Unquote(s string) string
- func Upper(s string) string
- func UpperFirst(s string) string
- func UpperWord(s string) string
- func Uppercase(s string) string
- func Utf8Len(s string) int
- func Utf8Split(s string, w int) []string
- func Utf8Truncate(s string, w int, tail string) string
- func Utf8Width(s string) int
- func Utf8len(s string) int
- func Valid(ss ...string) string
- func VersionCompare(v1, v2, op string) bool
- func WidthWrap(s string, w int) string
- func WildcardMatch(pattern, str string) bool
- func WildcardMatchLimit(pattern, str string, maxcomp int) (matched, stopped bool)
- func WordWrap(s string, w int) string
- func WrapTag(s, tag string) string
- func ZeroOr[T ~string](val, defVal T) T
- type BaseEncoder
- type BaseType
- type Buffer
- type Builder
- func (b *Builder) ResetGet() string
- func (b *Builder) Write(p []byte)
- func (b *Builder) WriteAny(v any)
- func (b *Builder) WriteAnys(vs ...any)
- func (b *Builder) WriteByteNE(c byte)
- func (b *Builder) WriteMulti(bs ...byte)
- func (b *Builder) WriteRune(r rune)
- func (b *Builder) WriteString(s string)
- func (b *Builder) WriteStrings(ss ...string)
- func (b *Builder) Writef(tpl string, vs ...any)
- func (b *Builder) Writeln(s string)
- type ByteChanPool
- type ParseSizeOpt
- type PosFlag
- type Rule
- type Runes
- type SimilarComparator
- type StrVal
- type Value
- func (s Value) Bool() bool
- func (s Value) Bytes() []byte
- func (s Value) HasPrefix(sub string) bool
- func (s Value) HasSuffix(sub string) bool
- func (s Value) Int() int
- func (s Value) Int64() int64
- func (s Value) IsBlank() bool
- func (s Value) IsEmpty() bool
- func (s Value) IsEndWith(sub string) bool
- func (s Value) IsStartWith(sub string) bool
- func (s Value) OrElse(or string) string
- func (s *Value) Set(val string) error
- func (s Value) Split(sep string) []string
- func (s Value) SplitN(sep string, n int) []string
- func (s Value) String() string
- func (s Value) Val() string
- func (s Value) WithTrimSpace() Value
Constants
const (
KNumbers = "0123456789"
KHexChars = "0123456789abcdef"
KAlphaBet = "abcdefghijklmnopqrstuvwxyz"
KAlphaBet1 = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
KAlphaNum = "abcdefghijklmnopqrstuvwxyz0123456789"
KAlphaNum2 = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
KAlphaNum3 = "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
KBase62Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
KBase64Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/"
)Variables
var (
// ErrDateLayout error
ErrDateLayout = errors.New("invalid date layout string")
// ErrInvalidParam error
ErrInvalidParam = errors.New("invalid input for parse time")
)var (
UpWords = UpperWord
LoFirst = LowerFirst
UpFirst = UpperFirst
Snake = SnakeCase
)https://github.com/rs/xid
https://github.com/satori/go.uuidvar (
DefMinInt = 1000
DefMaxInt = 9999
)Equal check, alias of strings.EqualFold
var Equal = strings.EqualFoldErrInvalidSizeExpr invalid size expression error
var ErrInvalidSizeExpr = errors.New("invalid size expr")SprintToStrFunc convert any value to string by fmt.Sprint
var SprintToStrFunc = func(v any) (string, error) {
if v == nil {
return "", nil
}
return fmt.Sprint(v), nil
}func AddIrregularRule
func AddIrregularRule(single string, plural string)AddIrregularRule -- Add an irregular word definition.
func AddPluralRule
func AddPluralRule(rule string, replacement string)AddPluralRule -- Add a pluralization rule to the collection.
func AddSingularRule
func AddSingularRule(rule string, replacement string)AddSingularRule -- Add a singularization rule to the collection.
func AddSlashes
func AddSlashes(s string) stringAddSlashes add slashes for the string.
func AddUncountableRule
func AddUncountableRule(word string)AddUncountableRule -- Add an uncountable word rule.
func AfterFirst
func AfterFirst(s, sep string) stringAfterFirst get substring after first sep.
func AfterLast
func AfterLast(s, sep string) stringAfterLast get substring after last sep.
func Allowable
func Allowable(pattern string) (min, max string)Allowable parses the pattern and determines the minimum and maximum allowable values that the pattern can represent. When the max cannot be determined, 'true' will be returned for infinite.
func AnyToString
func AnyToString(val any, defaultAsErr bool) (s string, err error)AnyToString convert any value to string.
For defaultAsErr:
- False will use fmt.Sprint convert complex type
- True will return error on fail.
func B32HexDecode
func B32HexDecode(str string) stringB32HexDecode base32 decode
func B32HexEncode
func B32HexEncode(str string) stringB32HexEncode base32 encode
func B32StdDecode
func B32StdDecode(str string) stringB32StdDecode base32 std decode
func B32StdEncode
func B32StdEncode(str string) stringB32StdEncode base32 std encode
func B64RawURLDecode
func B64RawURLDecode(str string) stringB64Decode base64 raw url decode
func B64RawURLDecodeBytes
func B64RawURLDecodeBytes(str string) []byteB64RawURLDecodeBytes base64 raw url decode
func B64RawURLEncode
func B64RawURLEncode(str string) stringB64RawURLEncode base64 raw url encode
func B64RawURLEncodeBytes
func B64RawURLEncodeBytes(src []byte) stringB64RawURLEncodeBytes base64 raw url encode
func B64StdDecode
func B64StdDecode(str string) stringB64StdDecode base64 std decode
func B64StdDecodeBytes
func B64StdDecodeBytes(str string) []byteB64StdDecodeBytes base64 std decode
func B64StdEncode
func B64StdEncode(str string) stringB64StdEncode base64 std encode
func B64StdEncodeBytes
func B64StdEncodeBytes(src []byte) stringB64StdEncodeBytes base64 std encode
func B64URLDecode
func B64URLDecode(str string) stringB64Decode base64 url decode
func B64URLDecodeBytes
func B64URLDecodeBytes(str string) []byteB64URLDecodeBytes base64 url decode
func B64URLEncode
func B64URLEncode(str string) stringB64URLEncode base64 url encode
func B64URLEncodeBytes
func B64URLEncodeBytes(src []byte) stringB64URLEncodeBytes base64 url encode
func BeforeFirst
func BeforeFirst(s, sep string) stringBeforeFirst get substring before first sep.
func BeforeLast
func BeforeLast(s, sep string) stringBeforeLast get substring before last sep.
func BlankOr
func BlankOr(val, defVal string) stringBlankOr return default value on val is blank, else return val
func Bool
func Bool(s string) (bool, error)Bool parse string to bool. like strconv.ParseBool()
func Byte2str
func Byte2str(b []byte) stringByte2str converts a byte slice to a string without copy.
func Byte2string
func Byte2string(b []byte) stringByte2string converts a byte slice to a string without copy.
func BytePos
func BytePos(s string, bt byte) intBytePos alias of the strings.IndexByte
func Camel
func Camel(s string, sep ...string) stringCamel alias of the CamelCase
func CamelCase
func CamelCase(s string, sep ...string) stringCamelCase convert string to camel case.
Support:
"range_price" -> "rangePrice"
"range price" -> "rangePrice"
"range-price" -> "rangePrice"func Compare
func Compare(s1, s2, op string) boolCompare for two string.
func ContainsAll
func ContainsAll(s string, subs []string) boolContainsAll substr(s) in the given string. alias of HasAllSubs()
func ContainsByte
func ContainsByte(s string, c byte) boolContainsByte in given string.
func ContainsOne
func ContainsOne(s string, subs []string) boolContainsOne substr(s) in the given string. alias of HasOneSub()
func Cut
func Cut(s, sep string) (before string, after string, found bool)Cut same of the strings.Cut
func DatetimeNo
func DatetimeNo(prefix string) stringDatetimeNo generate. can use for order-no.
- No prefix, return like: 2023041410484904074285478388(len: 28)
- With prefix, return like: prefix2023041410484904074285478388(len: 28 + len(prefix))
func EscapeHTML
func EscapeHTML(s string) stringEscapeHTML escape html string
func EscapeJS
func EscapeJS(s string) stringEscapeJS escape javascript string
func FilterEmail
func FilterEmail(s string) stringFilterEmail filter email, clear invalid chars.
func FirstLine
func FirstLine(output string) stringFirstLine from command output
func Float32
func Float32(s string) float32Float64 convert string to float32, will ignore error
func Float32Or
func Float32Or(s string, defVal float32) float32Float32Or convert string to float32, return default value on fail
func Float32OrDefault
func Float32OrDefault(s string, defVal float32) float32Float32OrDefault convert string to float32, return default value on fail
func Float32OrErr
func Float32OrErr(s string) (float32, error)Float32OrErr convert string to float32, return error on fail
func Float32OrPanic
func Float32OrPanic(s string) float32Float32OrPanic convert value to float32, will panic on error
func Float64
func Float64(s string) float64Float64 convert string to float64, will ignore error
func Float64Or
func Float64Or(s string, defVal float64) float64Float64Or convert string to float64, return default value on fail
func Float64OrDefault
func Float64OrDefault(s string, defVal float64) float64Float64OrDefault convert string to float64, return default value on fail
func Float64OrErr
func Float64OrErr(s string) (float64, error)Float64OrErr convert string to float64, return error on fail
func Float64OrPanic
func Float64OrPanic(s string) float64Float64OrPanic convert value to float64, will panic on error
func FromBytes
func FromBytes(b []byte) stringFromBytes converts a byte slice to a string without copy.
func GlobMatch
func GlobMatch(pattern, s string) boolGlobMatch check for a string match the pattern.
Difference with PathMatch() is: `*` can match any char, contain `/`.
func HasAllSubs
func HasAllSubs(s string, subs []string) boolHasAllSubs all substr in the given string.
func HasEmpty
func HasEmpty(ss ...string) boolHasEmpty value for input strings
func HasOnePrefix
func HasOnePrefix(s string, prefixes []string) boolHasOnePrefix the string start withs one of the subs
func HasOneSub
func HasOneSub(s string, subs []string) boolHasOneSub substr(s) in the given string.
func HasOneSuffix
func HasOneSuffix(s string, suffixes []string) boolHasOneSuffix the string end withs one of the subs
func HasPrefix
func HasPrefix(s string, prefix string) boolHasPrefix substr in the given string.
func HasSuffix
func HasSuffix(s string, suffix string) boolHasSuffix substr in the given string.
func IContains
func IContains(s, sub string) boolIContains ignore case check substr in the given string.
func IEqual
func IEqual(s1, s2 string) boolIEqual ignore case check given two string is equals.
func Implode
func Implode(sep string, ss ...string) stringImplode alias of strings.Join
func Indent
func Indent(s, prefix string) stringIndent inserts prefix at the beginning of each non-empty line of s. The end-of-line marker is NL.
func IndentBytes
func IndentBytes(b, prefix []byte) []byteIndentBytes inserts prefix at the beginning of each non-empty line of b. The end-of-line marker is NL.
func Int
func Int(s string) (int, error)Int convert string to int, alias of ToInt()
func Int32
func Int32(s string) (int32, error)Int32 convert string to int32, alias of ToInt32()
func Int32Or
func Int32Or(s string, defVal int32) int32Int32Or convert string to int32, return default value on fail
func Int32OrDefault
func Int32OrDefault(s string, defVal int32) int32Int32OrDefault convert string to int32, return default value on fail
func Int32OrPanic
func Int32OrPanic(s string) int32Int32OrPanic convert value to int32, will panic on error
func Int64
func Int64(s string) int64Int64 convert string to int, will ignore error
func Int64Or
func Int64Or(s string, defVal int64) int64Int64Or convert string to int, return default value on fail
func Int64OrDefault
func Int64OrDefault(s string, defVal int64) int64Int64OrDefault convert string to int, return default value on fail
func Int64OrErr
func Int64OrErr(s string) (int64, error)Int64OrErr convert string to int, return error on fail
func Int64OrPanic
func Int64OrPanic(s string) int64Int64OrPanic convert value to int, will panic on error
func IntOr
func IntOr(s string, defVal int) intIntOr convert string to int, return default value on fail
func IntOrDefault
func IntOrDefault(s string, defVal int) intIntOrDefault convert string to int, return default value on fail
func IntOrPanic
func IntOrPanic(s string) intIntOrPanic convert value to int, will panic on error
func Ints
func Ints(s string, sep ...string) []intInts alias of the ToIntSlice(). default sep is comma(,)
func IsAllEmpty
func IsAllEmpty(ss ...string) boolIsAllEmpty for input strings
func IsAlphaNum
func IsAlphaNum(c uint8) boolIsAlphaNum reports whether the byte is an ASCII letter, number, or underscore
func IsAlphabet
func IsAlphabet(char uint8) boolIsAlphabet char
func IsBlank
func IsBlank(s string) boolIsBlank returns true if the given string is all space characters.
func IsBlankBytes
func IsBlankBytes(bs []byte) boolIsBlankBytes returns true if the given []byte is all space characters.
func IsEmpty
func IsEmpty(s string) boolIsEmpty returns true if the given string is empty.
func IsEndOf
func IsEndOf(s, suffix string) boolIsEndOf alias of the strings.HasSuffix
func IsNotBlank
func IsNotBlank(s string) boolIsNotBlank returns true if the given string is not blank.
func IsNumChar
func IsNumChar(c byte) boolIsNumChar returns true if the given character is a numeric, otherwise false.
func IsNumeric
func IsNumeric(s string) boolIsNumeric returns true if the given string is a numeric, otherwise false.
func IsPlural
func IsPlural(word string) boolIsPlural -- Check if a word is plural.
func IsSingular
func IsSingular(word string) boolIsSingular -- Check if a word is singular.
func IsSpace
func IsSpace(c byte) boolIsSpace returns true if the given character is a space, otherwise false.
func IsSpaceRune
func IsSpaceRune(r rune) boolIsSpaceRune returns true if the given rune is a space, otherwise false.
func IsStartOf
func IsStartOf(s, prefix string) boolIsStartOf alias of the strings.HasPrefix
func IsStartsOf
func IsStartsOf(s string, prefixes []string) boolIsStartsOf alias of the HasOnePrefix
func IsSymbol
func IsSymbol(r rune) boolIsSymbol reports whether the rune is a symbolic character.
func IsValidUtf8
func IsValidUtf8(s string) boolIsValidUtf8 valid utf8 string check
func IsVersion
func IsVersion(s string) boolIsVersion number. eg: 1.2.0
func Join
func Join(sep string, ss ...string) stringJoin alias of strings.Join
func JoinAny
func JoinAny(sep string, parts ...any) stringJoinAny type to string
func JoinList
func JoinList(sep string, ss []string) stringJoinList alias of strings.Join
func LTrim
func LTrim(s string, cutSet ...string) stringLTrim alias of TrimLeft
func LikeMatch
func LikeMatch(pattern, s string) boolLikeMatch simple check for a string match the pattern. pattern like the SQL LIKE.
func Lower
func Lower(s string) stringLower alias of the strings.ToLower()
func LowerFirst
func LowerFirst(s string) stringLowerFirst lower first char
func Lowercase
func Lowercase(s string) stringLowercase alias of the strings.ToLower()
func Ltrim
func Ltrim(s string, cutSet ...string) stringLtrim alias of TrimLeft
func MatchNodePath
func MatchNodePath(pattern, s string, sep string) boolMatchNodePath check for a string match the pattern.
Use on pattern:
- `*` match any to sep
- `**` match any to end. only allow at start or end on pattern.
Example:
string_util.MatchNodePath()func MaybeWildcard
func MaybeWildcard(str string) boolMatch returns true if the pattern matches the s string. The pattern can contain the wildcard characters '?' and '*'.
func MicroTimeHexID
func MicroTimeHexID() stringMicroTimeHexID generate. return like: 5b5f0588af1761ad3(len: 16-17)
func MicroTimeID
func MicroTimeID() stringMicroTimeID generate. return like: 16074145697981929446(len: 20)
func MustBool
func MustBool(s string) boolMustBool convert to bool, will panic on error
func MustCut
func MustCut(s, sep string) (before string, after string)MustCut always returns two substring.
func MustFloat32
func MustFloat32(s string) float32MustFloat32 convert value to float32, will panic on error
func MustFloat64
func MustFloat64(s string) float64MustFloat64 convert value to float64, will panic on error
func MustInt
func MustInt(s string) intMustInt convert string to int, will panic on error
func MustInt32
func MustInt32(s string) int32MustInt32 convert string to int32, will panic on error
func MustInt64
func MustInt64(s string) int64MustInt64 convert value to int, will panic on error
func MustString
func MustString(val any) stringMustString convert value to string, will panic on error
func MustToTime
func MustToTime(s string, layouts ...string) time.TimeMustToTime convert date string to time.Time
func MustUint
func MustUint(s string) uint64MustUint convert value to uint, will panic on error. alias of UintOrPanic()
func NewReplacer
func NewReplacer(pairs map[string]string) *strings.ReplacerNewReplacer instance
func NewShortUUID
func NewShortUUID() stringNewShortUUID returns a new short UUID (22 chars).
func NewULID
func NewULID() stringNewULID returns a new ULID (26 chars).
func NewUUID
func NewUUID() stringNewUUID returns a new UUID Version 4 (36 chars).
func NoCaseEq
func NoCaseEq(s, t string) boolNoCaseEq check two strings is equals and case-insensitivity
func OrCond
func OrCond(cond bool, s1, s2 string) stringOrCond return s1 on cond is True, OR return s2. Like: cond ? s1 : s2
func OrElse
func OrElse(s, orVal string) stringOrElse return default value on val is zero, else return s
func OrHandle
func OrHandle(s string, fn com_def.StringHandleFunc) stringOrHandle return fn(s) on s is not empty.
func PadBytes
func PadBytes(bs []byte, pad byte, length int, pos PosFlag) []bytePadBytes padding a byte to want length and with position flag
func PadBytesLeft
func PadBytesLeft(bs []byte, pad byte, length int) []bytePadBytesLeft a byte to want length
func PadBytesRight
func PadBytesRight(bs []byte, pad byte, length int) []bytePadBytesRight a byte to want length
func PadChars
func PadChars[T byte | rune](cs []T, pad T, length int, pos PosFlag) []TPadChars padding a rune/byte to want length and with position flag
func PadLeft
func PadLeft(s, pad string, length int) stringPadLeft a string.
func PadRight
func PadRight(s, pad string, length int) stringPadRight a string.
func PadRunes
func PadRunes(rs []rune, pad rune, length int, pos PosFlag) []runePadRunes padding a rune to want length and with position flag
func PadRunesLeft
func PadRunesLeft(rs []rune, pad rune, length int) []runePadRunesLeft a rune to want length
func PadRunesRight
func PadRunesRight(rs []rune, pad rune, length int) []runePadRunesRight a rune to want length
func Padding
func Padding(s, pad string, length int, pos PosFlag) stringPadding a string.
func ParseSizeRange
func ParseSizeRange(expr string, opt *ParseSizeOpt) (min, max uint64, err error)ParseSizeRange parse range size expression to min and max size.
Expression format:
"1KB~2MB" => 1KB to 2MB
"-1KB" => <1KB
"~1MB" => <1MB
"< 1KB" => <1KB
"1KB" => >1KB
"1KB~" => >1KB
">1KB" => >1KB
"+1KB" => >1KBfunc PathMatch
func PathMatch(pattern, s string) boolPathMatch check for a string match the pattern. alias of the path.Match()
TIP: `*` can match any char, not contain `/`.
func Plural
func Plural(word string) stringPlural -- Pluralize a word.
func Pluralize
func Pluralize(word string, count int, inclusive bool) stringPluralize -- Pluralize or singularize a word based on the passed in count.
word: the word to pluralize
count: how many of the word exist
inclusive: whether to prefix with the number (e.g. 3 ducks)func QuickMatch
func QuickMatch(pattern, s string) boolQuickMatch check for a string. pattern can be a sub string.
func QuietBool
func QuietBool(s string) boolQuietBool convert to bool, will ignore error
func QuietCut
func QuietCut(s, sep string) (before string, after string)QuietCut always returns two substring.
func QuietFloat32
func QuietFloat32(s string) float32QuietFloat64 convert string to float32, will ignore error
func QuietFloat64
func QuietFloat64(s string) float64QuietFloat64 convert string to float64, will ignore error
func QuietInt
func QuietInt(s string) intQuietInt convert string to int, will ignore error
func QuietInt32
func QuietInt32(s string) int32QuietInt32 convert string to int32, will ignore error
func QuietInt64
func QuietInt64(s string) int64QuietInt64 convert string to int, will ignore error
func QuietString
func QuietString(val any) stringQuietString convert value to string, will ignore error. same as SafeString()
func Quote
func Quote(s string) stringQuote alias of strings.Quote
func RTrim
func RTrim(s string, cutSet ...string) stringRTrim alias of TrimRight
func RandWithTpl
func RandWithTpl(n int, letters string) stringRandWithTpl generate random string with give template
func RandomBytes
func RandomBytes(length int) ([]byte, error)RandomBytes generate
func RandomChars
func RandomChars(ln int) stringRandomChars generate give length random chars at `a-z`
func RandomCharsV2
func RandomCharsV2(ln int) stringRandomCharsV2 generate give length random chars in `0-9a-z`
func RandomCharsV3
func RandomCharsV3(ln int) stringRandomCharsV3 generate give length random chars in `0-9a-zA-Z`
func RandomString
func RandomString(length int) (string, error)RandomString generate.
Example:
// this will give us a 44 byte, base64 encoded output
token, err := RandomString(32)
if err != nil {
// Serve an appropriately vague error to the
// user, but log the details internally.
}func RemoveDiacritics
func RemoveDiacritics(s string) stringfunc RenderTemplate
func RenderTemplate(input string, data any, fns template.FuncMap, isFile ...bool) stringRenderTemplate quickly render text template.
Deprecated: please use text_util.RenderTpl() instead it
func RenderText
func RenderText(input string, data any, fns template.FuncMap, isFile ...bool) stringRenderText quickly render text template
Deprecated: please use text_util.RenderTpl() instead it
func Repeat
func Repeat(s string, times int) stringRepeat a string by given times.
func RepeatBytes
func RepeatBytes(char byte, times int) []byteRepeatBytes repeat a byte char.
func RepeatChars
func RepeatChars[T byte | rune](char T, times int) []TRepeatChars repeat a byte char.
func RepeatRune
func RepeatRune(char rune, times int) []runeRepeatRune repeat a rune char.
func ReplaceAll
func ReplaceAll(s string, old string, new string) stringReplaceAll thay thế tất cả các lần xuất hiện của chuỗi con cũ bằng chuỗi con mới trong chuỗi s cho đến khi chuỗi con cũ không còn tồn tại trong s.
Tham số:
- s: Chuỗi gốc trong đó sẽ thực hiện thay thế.
- old: Chuỗi con cần thay thế.
- new: Chuỗi con thay thế cho chuỗi con cũ.
Trả về:
Chuỗi mới với tất cả các lần xuất hiện của chuỗi con cũ được thay thế bằng chuỗi con mới.func Replaces
func Replaces(str string, pairs map[string]string) stringReplaces replace multi strings
pairs: {old1: new1, old2: new2, ...}Can also use:
strings.NewReplacer("old1", "new1", "old2", "new2").Replace(str)func ReplacesAll
func ReplacesAll(s string, new string, olds ...string) stringReplacesAll thay thế tất cả các chuỗi con trong s bằng chuỗi new. Các chuỗi con cần thay thế được cung cấp trong olds. Lưu ý: Vị trí của new và olds ngược so với ReplaceAll. Thứ tự thay thế sẽ theo thứ tự các chuỗi con trong olds.
Usage:
ReplaceAll(ReplaceAll(ReplaceAll(s, "old3", "new"), "old2", "new"), "old1", "new")
// Or
ReplacesAll(s, "new, "old3", "old2", "old1")func Resize
func Resize(s string, length int, align PosFlag) stringResize a string by given length and align settings. padding space.
func Rtrim
func Rtrim(s string, cutSet ...string) stringRtrim alias of TrimRight
func RuneCount
func RuneCount(s string) intRuneCount of the string
func RuneIsLower
func RuneIsLower(c rune) boolRuneIsLower char
func RuneIsUpper
func RuneIsUpper(c rune) boolRuneIsUpper char
func RuneIsWord
func RuneIsWord(c rune) boolRuneIsWord char: a-zA-Z
func RunePos
func RunePos(s string, ru rune) intRunePos alias of the strings.IndexRune
func RuneWidth
func RuneWidth(r rune) intRuneWidth of the rune.
Example:
RuneWidth('你') // 2
RuneWidth('a') // 1
RuneWidth('\n') // 0func RunesWidth
func RunesWidth(rs []rune) (w int)RunesWidth utf8 runes string width.
Examples:
str := "hi,你好"
len(str) // 9
string_util.Utf8Width(str) // 7
len([]rune(str)) = utf8.RuneCountInString(s) // 5func SafeBool
func SafeBool(s string) boolSafeBool convert to bool, will ignore error
func SafeByteSize
func SafeByteSize(sizeStr string) uint64SafeByteSize converts size string like 1GB/1g or 12mb/12M into an unsigned integer number of bytes
func SafeFloat32
func SafeFloat32(s string) float32SafeFloat64 convert string to float32, will ignore error
func SafeFloat64
func SafeFloat64(s string) float64SafeFloat64 convert string to float64, will ignore error
func SafeInt
func SafeInt(s string) intSafeInt convert string to int, will ignore error
func SafeInt32
func SafeInt32(s string) int32SafeInt32 convert string to int32, will ignore error
func SafeInt64
func SafeInt64(s string) int64SafeInt64 convert string to int, will ignore error
func SafeString
func SafeString(in any) stringSafeString convert value to string, will ignore error
func SafeUint
func SafeUint(s string) uint64SafeUint convert string to uint, will ignore error
func Similarity
func Similarity(s, t string, rate float32) (float32, bool)Similarity calc for two string.
Usage:
rate, ok := Similarity("hello", "he")func SimpleMatch
func SimpleMatch(s string, keywords []string) boolSimpleMatch all sub-string in the give text string.
Difference the ContainsAll:
- start with ^ for exclude contains check.
- end with $ for check end with keyword.
func Singular
func Singular(word string) stringSingular -- Singularize a word.
func SnakeCase
func SnakeCase(s string, sep ...string) stringSnakeCase convert. eg "RangePrice" -> "range_price"
func Split
func Split(s, sep string) (ss []string)Split string to slice. will trim each item and filter empty string node.
func SplitInlineComment
func SplitInlineComment(val string, strict ...bool) (string, string)SplitInlineComment for an inline text string.
func SplitKV
func SplitKV(s, sep string) (string, string)SplitKV split string to key and value.
func SplitN
func SplitN(s, sep string, n int) (ss []string)SplitN string to slice. will filter empty string node.
func SplitNTrimmed
func SplitNTrimmed(s, sep string, n int) (ss []string)SplitNTrimmed split string to slice. will trim space for each node, but not filter empty
func SplitNValid
func SplitNValid(s, sep string, n int) (ss []string)SplitNValid string to slice. will filter empty string node.
func SplitTrimmed
func SplitTrimmed(s, sep string) (ss []string)SplitTrimmed split string to slice. will trim space for each node, but not filter empty
func SplitValid
func SplitValid(s, sep string) (ss []string)SplitValid string to slice. will trim each item and filter empty string node.
func StandardizedCapitalizeCamel
func StandardizedCapitalizeCamel(input string) stringfunc StandardizedCapitalizeWords
func StandardizedCapitalizeWords(input string) stringfunc StandardizedNumber
func StandardizedNumber(number, lenNumber int) stringfunc StrPos
func StrPos(s, sub string) intStrPos alias of the strings.Index
func String
func String(val any) (string, error)String convert value to string, return error on failed
func StringOr
func StringOr(val any, defVal string) stringStringOr convert any value to string, return default value on failed
func StringOrDefault
func StringOrDefault(val any, defVal string) stringStringOrDefault convert any value to string, return default value on failed
func StringOrErr
func StringOrErr(val any) (string, error)StringOrErr convert value to string, return error on failed
func StringOrPanic
func StringOrPanic(val any) stringStringOrPanic convert value to string, will panic on error
func Strings
func Strings(s string, sep ...string) []stringStrings alias of the ToSlice()
func StripSlashes
func StripSlashes(s string) stringStripSlashes strip slashes for the string.
func Substr
func Substr(s string, pos, length int) stringSubstr for a string. if length <= 0, return pos to end.
func SubstrCount
func SubstrCount(s, substr string, params ...uint64) (int, error)SubstrCount returns the number of times the substr substring occurs in the s string. Actually, it comes from strings.Count().
- s The string to search in
- substr The substring to search for
- params[0] The offset where to start counting.
- params[1] The maximum length after the specified offset to search for the substring.
func TextSplit
func TextSplit(s string, w int) []stringTextSplit alias of the Utf8Split()
func TextTruncate
func TextTruncate(s string, w int, tail string) stringTextTruncate alias of the Utf8Truncate()
func TextWidth
func TextWidth(s string) intTextWidth utf8 string width. alias of RunesWidth()
func TextWrap
func TextWrap(s string, w int) stringTextWrap a string by "\n"
func Title
func Title(s string) stringTitle alias of the strings.ToTitle()
func ToArray
func ToArray(s string, sep ...string) []stringToArray alias of the ToSlice()
func ToBool
func ToBool(s string) (bool, error)ToBool convert string to bool
func ToByteSize
func ToByteSize(sizeStr string) (uint64, error)ToByteSize converts size string like 1GB/1g or 12mb/12M into an unsigned integer number of bytes
func ToBytes
func ToBytes(s string) (b []byte)ToBytes converts a string to a byte slice without copy.
func ToDuration
func ToDuration(s string) (time.Duration, error)ToDuration parses a duration string. such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
func ToFloat32
func ToFloat32(s string) (float32, error)ToFloat32 convert string to float32, return error on fail
func ToFloat64
func ToFloat64(s string) (float64, error)ToFloat64 convert string to float64, return error on fail
func ToInt
func ToInt(s string) (int, error)ToInt convert string to int, return error on fail
func ToInt32
func ToInt32(s string) (int32, error)ToInt32 convert string to int32, return error on fail
func ToInt64
func ToInt64(s string) (int64, error)ToInt64 convert string to int, return error on fail
func ToIntSlice
func ToIntSlice(s string, sep ...string) (ints []int, err error)ToIntSlice split string to slice and convert item to int.
Default sep is comma
func ToInts
func ToInts(s string, sep ...string) ([]int, error)ToInts alias of the ToIntSlice(). default sep is comma(,)
func ToSlice
func ToSlice(s string, sep ...string) []stringToSlice split string to array.
func ToString
func ToString(val any) (string, error)ToString convert value to string, return error on failed
func ToStringWithFunc
func ToStringWithFunc(val any, fbFn com_def.ToStringFunc) (str string, err error)ToStringWithFunc convert value to string, with a func to fallback handle.
On not convert:
- If fbFn is nil, will return com_def.ErrConvType.
- If fbFn is not nil, will call it to convert.
func ToStrings
func ToStrings(s string, sep ...string) []stringToStrings alias of the ToSlice()
func ToTime
func ToTime(s string, layouts ...string) (t time.Time, err error)ToTime convert date string to time.Time
func ToUint
func ToUint(s string) (uint64, error)ToUint convert string to uint, return error on fail. alias of UintOrErr()
func Trim
func Trim(s string, cutSet ...string) stringTrim string. if cutSet is empty, will trim SPACE.
func TrimCut
func TrimCut(s, sep string) (string, string)TrimCut always returns two substring and trim space for items.
func TrimLeft
func TrimLeft(s string, cutSet ...string) stringTrimLeft char in the string. if cutSet is empty, will trim SPACE.
func TrimRight
func TrimRight(s string, cutSet ...string) stringTrimRight char in the string. if cutSet is empty, will trim SPACE.
func Truncate
func Truncate(s string, w int, tail string) stringTruncate alias of the Utf8Truncate()
func URLDecode
func URLDecode(s string) stringURLDecode decode url string.
func URLEncode
func URLEncode(s string) stringURLEncode encode url string.
func Uint
func Uint(s string) uint64Uint convert string to uint, will ignore error
func UintOr
func UintOr(s string, defVal uint64) uint64UintOr convert string to uint, return default value on fail
func UintOrDefault
func UintOrDefault(s string, defVal uint64) uint64UintOrDefault convert string to uint, return default value on fail
func UintOrErr
func UintOrErr(s string) (uint64, error)UintOrErr convert string to uint, return error on fail
func UintOrPanic
func UintOrPanic(s string) uint64UintOrPanic convert value to uint, will panic on error
func Unquote
func Unquote(s string) stringUnquote remove start and end quotes by single-quote or double-quote
tip: strconv.Unquote cannot unquote single-quote
func Upper
func Upper(s string) stringUpper alias of the strings.ToUpper()
func UpperFirst
func UpperFirst(s string) stringUpperFirst upper first char
func UpperWord
func UpperWord(s string) stringUpperWord Change the first character of each word to uppercase
func Uppercase
func Uppercase(s string) stringUppercase alias of the strings.ToUpper()
func Utf8Len
func Utf8Len(s string) intUtf8Len count of the string
func Utf8Split
func Utf8Split(s string, w int) []stringUtf8Split split a string by width.
func Utf8Truncate
func Utf8Truncate(s string, w int, tail string) stringUtf8Truncate a string with given width.
func Utf8Width
func Utf8Width(s string) intUtf8Width utf8 string width. alias of RunesWidth
func Utf8len
func Utf8len(s string) intUtf8len of the string
func Valid
func Valid(ss ...string) stringValid return first not empty element.
func VersionCompare
func VersionCompare(v1, v2, op string) boolVersionCompare for two version string.
func WidthWrap
func WidthWrap(s string, w int) stringWidthWrap a string by "\n"
func WildcardMatch
func WildcardMatch(pattern, str string) boolMatch returns true if str matches pattern. This is a very simple wildcard match where '*' matches on any number characters and '?' matches on any one character.
pattern:
{ term }term:
'*' matches any sequence of non-Separator characters
'?' matches any single non-Separator character
c matches character c (c != '*', '?', '\\')
'\\' c matches character cfunc WildcardMatchLimit
func WildcardMatchLimit(pattern, str string, maxcomp int) (matched, stopped bool)MatchLimit is the same as Match but will limit the complexity of the match operation. This is to avoid long running matches, specifically to avoid ReDos attacks from arbritary inputs.
How it works: The underlying match routine is recursive and may call itself when it encounters a sandwiched wildcard pattern, such as: `user:*:name`. Everytime it calls itself a counter is incremented. The operation is stopped when counter > maxcomp*len(str).
func WordWrap
func WordWrap(s string, w int) stringWordWrap text string and limit width.
func WrapTag
func WrapTag(s, tag string) stringWrapTag for given string.
func ZeroOr
func ZeroOr[T ~string](val, defVal T) TZeroOr return default value on val is zero, else return val. same of OrElse()
type BaseEncoder
BaseEncoder interface
type BaseEncoder interface {
Encode(dst []byte, src []byte)
EncodeToString(src []byte) string
Decode(dst []byte, src []byte) (n int, err error)
DecodeString(s string) ([]byte, error)
}func Encoding
func Encoding(base int, typ BaseType) BaseEncoderEncoding instance. base: 32 or 64, typ: 0 - 4
Usage:
codec := string_util.Encoding(32, string_util.HexEncoding)
codec := string_util.Encoding(32, string_util.StdEncoding)
codec := string_util.Encoding(64, string_util.URLEncoding)
codec := string_util.Encoding(64, string_util.RawURLEncoding)
codec := string_util.Encoding(64, string_util.RawStdEncoding)
codec := string_util.Encoding(64, string_util.StdEncoding)type BaseType
BaseType for base encoding
type BaseType uint8const (
KBaseTypeStd BaseType = iota
KBaseTypeHex
KBaseTypeURL
KBaseTypeRawStd
KBaseTypeRawURL
)type Buffer
Buffer wrap and extends the bytes.Buffer
type Buffer = byte_util.Bufferfunc NewBuffer
func NewBuffer() *BufferNewBuffer instance
type Builder
Builder struct
type Builder struct {
strings.Builder
}func (*Builder) ResetGet
func (b *Builder) ResetGet() stringResetGet return current string and reset builder
func (*Builder) Write
func (b *Builder) Write(p []byte)Write bytes and no error report
func (*Builder) WriteAny
func (b *Builder) WriteAny(v any)WriteAny write any type value.
func (*Builder) WriteAnys
func (b *Builder) WriteAnys(vs ...any)WriteAnys write any type values.
func (*Builder) WriteByteNE
func (b *Builder) WriteByteNE(c byte)WriteByteNE write byte and no error report
func (*Builder) WriteMulti
func (b *Builder) WriteMulti(bs ...byte)WriteMulti write multi byte at once.
func (*Builder) WriteRune
func (b *Builder) WriteRune(r rune)WriteRune and no error report
func (*Builder) WriteString
func (b *Builder) WriteString(s string)WriteString to builder
func (*Builder) WriteStrings
func (b *Builder) WriteStrings(ss ...string)WriteStrings write multi string at once.
func (*Builder) Writef
func (b *Builder) Writef(tpl string, vs ...any)Writef write string by fmt.Sprintf formatted
func (*Builder) Writeln
func (b *Builder) Writeln(s string)Writeln write string with newline.
type ByteChanPool
ByteChanPool struct
Usage:
bp := string_util.NewByteChanPool(500, 1024, 1024)
buf:=bp.Get()
defer bp.Put(buf)
// use buf do something ...type ByteChanPool = byte_util.ChanPoolfunc NewByteChanPool
func NewByteChanPool(maxSize, width, capWidth int) *ByteChanPoolNewByteChanPool instance
type ParseSizeOpt
ParseSizeOpt parse size expression options
type ParseSizeOpt struct {
// OneAsMax if only one size value, use it as max size. default is false
OneAsMax bool
// SepChar is the separator char for time range string. default is '~'
SepChar byte
// KeywordFn is the function for parse keyword time string.
KeywordFn func(string) (min, max uint64, err error)
}type PosFlag
PosFlag type
type PosFlag uint8Position for padding/resize string
const (
KPosLeft PosFlag = iota
KPosRight
KPosMiddle
)type Rule
Rule -- pluralize rule expression and replacement value.
type Rule struct {
// contains filtered or unexported fields
}type Runes
Runes data slice
type Runes []runefunc (Runes) PadLeft
func (rs Runes) PadLeft(pad rune, length int) []runePadLeft a rune to want length
func (Runes) PadRight
func (rs Runes) PadRight(pad rune, length int) []runePadRight a rune to want length
func (Runes) Padding
func (rs Runes) Padding(pad rune, length int, pos PosFlag) []runePadding a rune to want length and with position
type SimilarComparator
SimilarComparator definition
links:
https://github.com/mkideal/cli/blob/master/fuzzy.gotype SimilarComparator struct {
// contains filtered or unexported fields
}func NewComparator
func NewComparator(src, dst string) *SimilarComparatorNewComparator create
func (*SimilarComparator) Similar
func (c *SimilarComparator) Similar(minDifferRate float32) (float32, bool)Similar by minDifferRate
Usage:
c := NewComparator("hello", "he")
rate, ok :c.Similar(0.3)type StrVal
StrVal string. alias of Value
type StrVal = Valuetype Value
Value string
type Value stringfunc (Value) Bool
func (s Value) Bool() boolBool convert
func (Value) Bytes
func (s Value) Bytes() []byteBytes string to bytes
func (Value) HasPrefix
func (s Value) HasPrefix(sub string) boolHasPrefix prefix
func (Value) HasSuffix
func (s Value) HasSuffix(sub string) boolHasSuffix suffix
func (Value) Int
func (s Value) Int() intInt convert
func (Value) Int64
func (s Value) Int64() int64Int64 convert
func (Value) IsBlank
func (s Value) IsBlank() boolIsBlank check
func (Value) IsEmpty
func (s Value) IsEmpty() boolIsEmpty check
func (Value) IsEndWith
func (s Value) IsEndWith(sub string) boolIsEndWith suffix
func (Value) IsStartWith
func (s Value) IsStartWith(sub string) boolIsStartWith prefix
func (Value) OrElse
func (s Value) OrElse(or string) stringOrElse string
func (*Value) Set
func (s *Value) Set(val string) errorSet value
func (Value) Split
func (s Value) Split(sep string) []stringSplit string
func (Value) SplitN
func (s Value) SplitN(sep string, n int) []stringSplitN string
func (Value) String
func (s Value) String() stringValue string
func (Value) Val
func (s Value) Val() stringVal string
func (Value) WithTrimSpace
func (s Value) WithTrimSpace() ValueWithTrimSpace string and return new
Generated by gomarkdoc