ss

package
v0.0.0-...-45da7de Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 5 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyOf

func AnyOf(s string, ss ...string) bool

func AnyOfFold

func AnyOfFold(s string, ss ...string) bool

func Contains

func Contains(s string, ss ...string) bool

func ContainsFold

func ContainsFold(s string, ss ...string) bool

func ExpandRange

func ExpandRange(f string) []string

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

func FieldsFuncN

func FieldsFuncN(s string, n int, f func(rune) bool) []string

FieldsFuncN 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. FieldsFuncN makes no guarantees about the order in which it calls f(c). If f does not return consistent results for a given c, FieldsFuncN 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. FieldsFuncN makes no guarantees about the order in which it calls f(c). If f does not return consistent results for a given c, FieldsFuncN may crash.

func FieldsN

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

FieldsN 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 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(s string) string

FirstWord returns the first word of the SQL statement s.

func FormatFloat

func FormatFloat(f float64) string

FormatFloat format a float64 to a string with the fewest digits necessary.

func FormatFloatOption

func FormatFloatOption(f float64, fns ...FormatFloatOptionConfigFn) string

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, ss ...string) bool

func HasSpaces

func HasSpaces(str string) bool

HasSpaces test if any spaces in the string.

func HasSuffix

func HasSuffix(s string, ss ...string) bool

func If

func If(b bool, s1, s2 string) string

func Ifi

func Ifi(b bool, s1, s2 int) int

func IsDigits

func IsDigits(s string) bool

func JoinMap

func JoinMap(m map[string]string, kvSep, kkSep string) (s string)

JoinMap 将 s 合成位 string,其中key和value之间的间隔符是kvSep, kv和kv之间的分隔符是kkSep

func Left

func Left(s string, n int) string

Left returns the left n runes of s at most.

func Not

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

func Or

func Or(a, b string) string

func Ori

func Ori(a, b int) int

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

func RemoveAll(s, old string) string

func Repeat

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

Repeat repeats s with separator seq for n times.

func Split

func Split(s string, options ...SplitOption) []string

func Split1

func Split1(s string, options ...SplitOption) (s0 string)

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

func Split2

func Split2(s string, options ...SplitOption) (s0, s1 string)

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

func Split3

func Split3(s string, options ...SplitOption) (s0, s1, s2 string)

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

func Split4

func Split4(s string, options ...SplitOption) (s0, s1, s2, s3 string)

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

func Split5

func Split5(s string, options ...SplitOption) (s0, s1, s2, s3, s4 string)

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

func SplitToMap

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

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

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 ToLowerKebab

func ToLowerKebab(name string) string

func ToSet

func ToSet(v []string) map[string]bool

Types

type Case

type Case int
const (
	CaseUnchanged Case = iota
	CaseLower
	CaseUpper
)

type FormatFloatOptionConfig

type FormatFloatOptionConfig struct {
	// Prec controls the number of digits (excluding the exponent)
	// printed by the 'e', 'E', 'f', 'g', 'G', 'x', and 'X' formats.
	// For 'e', 'E', 'f', 'x', and 'X', it is the number of digits after the decimal point.
	// For 'g' and 'G' it is the maximum number of significant digits (trailing zeros are removed).
	// The special precision -1 uses the smallest number of digits
	Prec                int
	RemoveTrailingZeros bool
}

type FormatFloatOptionConfigFn

type FormatFloatOptionConfigFn func(*FormatFloatOptionConfig)

func WithPrec

func WithPrec(prec int) FormatFloatOptionConfigFn

func WithRemoveTrailingZeros

func WithRemoveTrailingZeros(yes bool) FormatFloatOptionConfigFn

type SplitConfig

type SplitConfig struct {
	Separators  string
	IgnoreEmpty bool
	TrimSpace   bool
	Case        Case
	N           int
}

type SplitOption

type SplitOption func(*SplitConfig)

func WithCase

func WithCase(v Case) SplitOption

func WithConfig

func WithConfig(v SplitConfig) SplitOption

func WithIgnoreEmpty

func WithIgnoreEmpty(v bool) SplitOption

func WithN

func WithN(v int) SplitOption

func WithSeps

func WithSeps(v string) SplitOption

func WithTrimSpace

func WithTrimSpace(v bool) SplitOption

Jump to

Keyboard shortcuts

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