str

package
v0.0.0-...-4873089 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: Apache-2.0 Imports: 9 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyOf

func AnyOf(x interface{}, any ...interface{}) bool

AnyOf 给定x是否在any中

func ContainsIgnoreCase

func ContainsIgnoreCase(a, b string) bool

ContainsIgnoreCase ...

func ContainsWord

func ContainsWord(s, sep, word string) bool

ContainsWord contains word or not.

func Decode

func Decode(target interface{}, decodeVars ...interface{}) interface{}

Decode acts like oracle decode.

func EmptyThen

func EmptyThen(s, then string) string

EmptyThen ...

func Error

func Error(err error) string

Error truns err to string

func ExpandRange

func ExpandRange(f string) []string

ExpandRange expands a string like 1-3 to [1,2,3]

func Fields

func Fields(s string, count int) []string

Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space. The count determines the number of substrings to return:

n > 0: at most n substrings; the last substring will be the unsplit remainder.
n == 0: the result is nil (zero substrings)
n < 0: all substrings

Code are copy from strings.Fields and add count parameter to control the max fields.

func FieldsFunc

func FieldsFunc(s string, count int, f func(rune) bool) []string

FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned. FieldsFunc makes no guarantees about the order in which it calls f(c). If f does not return consistent results for a given c, FieldsFunc may crash.

func FieldsFuncX

func FieldsFuncX(s, keepStart, keepEnd string, count int, f func(rune) bool) []string

FieldsFuncX splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned. FieldsFunc makes no guarantees about the order in which it calls f(c). If f does not return consistent results for a given c, FieldsFunc may crash.

func FieldsX

func FieldsX(s, keepStart, keepEnd string, count int) []string

FieldsX splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space. The count determines the number of substrings to return:

n > 0: at most n substrings; the last substring will be the unsplit remainder.
n == 0: the result is nil (zero substrings)
n < 0: all substrings

Code are copy from strings.Fields and add count parameter to control the max fields.

func FirstWord

func FirstWord(value string) string

FirstWord find the first word of value.

func Has

func Has(str string, predicates ...func(rune) bool) bool

Has test if any rune which predicates tells it it true.

func HasPrefix

func HasPrefix(s string, p ...string) bool

HasPrefix tells s has any prefix of p...

func HasSpaces

func HasSpaces(str string) bool

HasSpaces test if any spaces in the string.

func If

func If(c bool, a, b string) string

If 代替三元表达式 c ? a : b

func IndexOf

func IndexOf(word string, data ...string) int

IndexOf find the index of word in data slice.

func Join

func Join(x ...string) string

Join 组合x

func JoinNonEmpty

func JoinNonEmpty(sep string, x ...string) string

JoinNonEmpty 组合x

func MapOf

func MapOf(arr ...string) map[string]string

MapOf composites arr to a map.

func MapToString

func MapToString(m map[string]string) string

MapToString joins map to a string.

func NoneOf

func NoneOf(x interface{}, any ...interface{}) bool

NoneOf 给定x是否不在所有的any中

func Not

func Not(p func(rune) bool) func(rune) bool

func ParseBool

func ParseBool(s string) bool

ParseBool returns the boolean value represented by the string. It accepts 1, t, true, y, yes, on with camel case incentive.

func ParseBoolE

func ParseBoolE(s string) (bool, error)

ParseBoolE returns the boolean value represented by the string. It accepts 1, t, true, y, yes, on as true with camel case incentive and accepts 0, f false, n, no, off as false with camel case incentive Any other value returns an error.

func ParseDuration

func ParseDuration(s string) time.Duration

ParseDuration ...

func ParseDurationE

func ParseDurationE(s string) (time.Duration, error)

ParseDurationE ...

func ParseFloat32

func ParseFloat32(s string) float32

ParseFloat32 ...

func ParseFloat32E

func ParseFloat32E(s string) (float32, error)

ParseFloat32E ...

func ParseFloat64

func ParseFloat64(s string) float64

ParseFloat64 ...

func ParseFloat64E

func ParseFloat64E(s string) (float64, error)

ParseFloat64E ...

func ParseInt

func ParseInt(s string) int

ParseInt ...

func ParseInt16

func ParseInt16(s string) int16

ParseInt16 ...

func ParseInt16E

func ParseInt16E(s string) (int16, error)

ParseInt16E ...

func ParseInt32

func ParseInt32(s string) int32

ParseInt32 ...

func ParseInt32E

func ParseInt32E(s string) (int32, error)

ParseInt32E ...

func ParseInt64

func ParseInt64(s string) int64

ParseInt64 ...

func ParseInt64E

func ParseInt64E(s string) (int64, error)

ParseInt64E ...

func ParseInt8

func ParseInt8(s string) int8

ParseInt8 ...

func ParseInt8E

func ParseInt8E(s string) (int8, error)

ParseInt8E ...

func ParseIntE

func ParseIntE(s string) (int, error)

ParseIntE ...

func ParseMapString

func ParseMapString(str string, separator, keyValueSeparator string) map[string]string

ParseMapString parses str to a map.

func ParseUint

func ParseUint(s string) uint

ParseUint ...

func ParseUint16

func ParseUint16(s string) uint16

ParseUint16 ...

func ParseUint16E

func ParseUint16E(s string) (uint16, error)

ParseUint16E ...

func ParseUint32

func ParseUint32(s string) uint32

ParseUint32 ...

func ParseUint32E

func ParseUint32E(s string) (uint32, error)

ParseUint32E ...

func ParseUint64

func ParseUint64(s string) uint64

ParseUint64 ...

func ParseUint64E

func ParseUint64E(s string) (uint64, error)

ParseUint64E ...

func ParseUint8

func ParseUint8(s string) uint8

ParseUint8 ...

func ParseUint8E

func ParseUint8E(s string) (uint8, error)

ParseUint8E ...

func ParseUintE

func ParseUintE(s string) (uint, error)

ParseUintE ...

func PickFirst

func PickFirst(s string, _ interface{}) string

PickFirst ignores the error and returns s

func Repeat

func Repeat(s, sep string, times int) string

Repeat repeat s with times with separator.

func ReplacePrefix

func ReplacePrefix(s, prefix, replace string) string

ReplacePrefix replace s that starts with prefix to replace. eg . ReplacePrefix("/abc/efg", "/abc", "#") => #/efg eg . ReplacePrefix("/abc/efg", "/efg", "#") => /abc/efg

func SingleLine

func SingleLine(s string) string

SingleLine 替换s中的换行以及连续空白,为单个空白

func Split1

func Split1(s, sep string, trimSpace, ignoreEmpty bool) (s0 string)

Split1 将s按分隔符sep分成x份,取第1份

func Split2

func Split2(s, sep string, trimSpace, ignoreEmpty bool) (s0, s1 string)

Split2 将s按分隔符sep分成x份,取第1、2份

func Split3

func Split3(s, sep string, trimSpace, ignoreEmpty bool) (s0, s1, s2 string)

Split3 将s按分隔符sep分成x份,取第1、2、3份

func Split4

func Split4(s, sep string, trimSpace, ignoreEmpty bool) (s0, s1, s2, s3 string)

Split4 将s按分隔符sep分成x份,取第x份,取第1、2、3、4份

func Split5

func Split5(s, sep string, trimSpace, ignoreEmpty bool) (s0, s1, s2, s3, s4 string)

Split5 将s按分隔符sep分成x份,取第x份,取第1、2、3、4、5份 nolint gomnd

func SplitN

func SplitN(s, sep string, trimSpace, ignoreEmpty bool) []string

SplitN splits N with trimSpace and ignoreEmpty

func SplitToMap

func SplitToMap(s string, kvSep, kkSep string) map[string]string

SplitToMap 将字符串s分割成map,其中key和value之间的间隔符是kvSep, kv和kv之间的分隔符是kkSep

func SplitTrim

func SplitTrim(str, sep string) []string

SplitTrim splits and trims.

func SplitX

func SplitX(s string, separate string, ocs ...OpenClose) []string

SplitX splits s by separate (not in (),[],{})

func StringContains

func StringContains(container, item, sep, absolute string) bool

StringContains detects an item contained in container in whole word mode separated by sep but if the absolute is specified and the container == absolute, true should always returned

func Strip

func Strip(str string, predicates ...func(rune) bool) string

Strip strips runes that predicates returns true.

func StripSpaces

func StripSpaces(str string) string

StripSpaces strips all spaces from the string.

func Tpl

func Tpl(tpl string, vars map[string]interface{}) string

Tpl 模板替换

func TryQuote

func TryQuote(s string, chars string) string

TryQuote tries to quote the string if there is control characters or non-printable characters as defined by IsPrint.

Types

type Expand

type Expand struct {
	// contains filtered or unexported fields
}

Expand structured a expandable unit.

func MakeExpand

func MakeExpand(s string) Expand

MakeExpand makes an expand by s.

func (Expand) MakeExpand

func (f Expand) MakeExpand() []string

MakeExpand makes a expanded string slice of expand.

func (Expand) MakePart

func (f Expand) MakePart() Part

MakePart makes a part of expand.

func (Expand) MaxLen

func (f Expand) MaxLen() int

MaxLen returns the max length among the inner parts.

type Expandable

type Expandable interface {
	// MakePart returns i'th item.
	Part(i int) string
	// Len returns the length of part items.
	Len() int
}

Expandable abstract a thing that can be expanded to parts.

type OpenClose

type OpenClose struct {
	Open  string
	Close string
}

OpenClose stands for open-close strings like ()[]{} and etc.

func (OpenClose) IsSame

func (o OpenClose) IsSame() bool

IsSame tells the open and close is same of not.

type Part

type Part struct {
	// contains filtered or unexported fields
}

Part as a part of something.

func MakeExpandPart

func MakeExpandPart(s string) Part

MakeExpandPart makes an expanded part.

func MakeFixedPart

func MakeFixedPart(s string) Part

MakeFixedPart make a fixed part by s.

func MakePart

func MakePart(s []string) Part

MakePart make a direct part by s.

func (Part) Len

func (f Part) Len() int

Len returns the length of part items.

func (Part) Part

func (f Part) Part(i int) string

Part returns i'th item.

type Tag

type Tag struct {
	Raw  string
	Main string
	Opts map[string]string
}

Tag represents tag of the struct field

func DecodeTag

func DecodeTag(rawTag string) Tag

DecodeTag decode tag values

func (Tag) GetOpt

func (t Tag) GetOpt(optName string) string

GetOpt gets opt's value by its name

Jump to

Keyboard shortcuts

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