stringutil

package
v0.1.41 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownCase   = errUnknownCase{}
	ErrUnknownPrefix = errUnknownPrefix{}
)

Functions

func BoolToString

func BoolToString(b bool) string

BoolToString converts a bool to a string.

func InArray

func InArray[T comparable](needle T, haystack []T) bool

InArray checks if a string is in a slice of haystack.

func IsEmpty

func IsEmpty(s string) bool

IsEmpty checks if a string is empty.

func IsNotEmpty

func IsNotEmpty(s string) bool

IsNotEmpty checks if a string is not empty.

func LastFromSplit

func LastFromSplit(input, split string) string

LastFromSplit returns the last part of a string split by a separator.

func LcFirst

func LcFirst(s string) string

LcFirst returns a copy of s with each word lowercased.

func Reverse

func Reverse(s string) string

Reverse returns its argument string reversed rune-wise left to right.

func Substring

func Substring(s string, start, end int) (string, error)

Substring returns a substring of a string.

func ToBool

func ToBool(str string) bool

ToBool converts a string to a bool.

func ToBoolE

func ToBoolE(str string) (bool, error)

ToBoolE converts a string to a bool. If the string is not a valid bool, it returns an error.

func ToCamel

func ToCamel(s string) string

func ToDelimited

func ToDelimited(s string, delim uint8) string

func ToFloat32

func ToFloat32(str string) float32

ToFloat32 converts a string to float32

func ToFloat32E

func ToFloat32E(str string) (float32, error)

ToFloat32E converts a string to float32. If the string is not a valid float32, it returns an error.

func ToFloat64

func ToFloat64(str string) float64

ToFloat64 converts a string to a float64.

func ToFloat64E

func ToFloat64E(str string) (float64, error)

ToFloat64E converts a string to a float64. If the string is not a valid float64, it returns an error.

func ToInt

func ToInt(str string) int

ToInt converts a string to an int.

func ToInt32

func ToInt32(str string) int32

ToInt32 converts a string to an int32.

func ToInt32E

func ToInt32E(str string) (int32, error)

ToInt32E converts a string to an int32. If the string is not a valid int32, it returns an error.

func ToInt64

func ToInt64(str string) int64

ToInt64 converts a string to int64

func ToInt64E

func ToInt64E(str string) (int64, error)

ToInt64E converts a string to int64. If the string is not a valid int64, it returns an error.

func ToInt8

func ToInt8(str string) int8

ToInt8 converts a string to int8

func ToInt8E

func ToInt8E(str string) (int8, error)

ToInt8E converts a string to int8. If the string is not a valid int8, it returns an error.

func ToIntE

func ToIntE(str string) (int, error)

ToIntE converts a string to an int.

func ToKebab

func ToKebab(s string) string

func ToLowerCamel

func ToLowerCamel(s string) string

func ToScreamingDelimited

func ToScreamingDelimited(s string, delimiter uint8, ignore string, screaming bool) string

func ToScreamingKebab

func ToScreamingKebab(s string) string

func ToSnake

func ToSnake(s string) string

func ToSnakeWithIgnore

func ToSnakeWithIgnore(s, ignore string) string

func ToString

func ToString(v interface{}) string

ToString converts any value to a string.

func ToUint

func ToUint(str string) uint

ToUint converts a string to uint, if the string is not a valid uint, it returns an error. this functionx is based on

func ToUint8

func ToUint8(str string) uint8

ToUint8 converts a string to uint8

func UcFirst

func UcFirst(s string) string

UcFirst returns a copy of s with each word capitalized.

Types

type RegisteredCases added in v0.1.31

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

func SwitchExact added in v0.1.31

func SwitchExact(actual string) *RegisteredCases

func (*RegisteredCases) AddCase added in v0.1.31

func (r *RegisteredCases) AddCase(cases ...string) bool

func (*RegisteredCases) String added in v0.1.31

func (r *RegisteredCases) String() string

func (*RegisteredCases) ToUnknownCaseErr added in v0.1.31

func (r *RegisteredCases) ToUnknownCaseErr() error

type RegisteredPrefixes added in v0.1.31

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

func SwitchPrefix added in v0.1.31

func SwitchPrefix(actual string) *RegisteredPrefixes

func (*RegisteredPrefixes) HasPrefix added in v0.1.31

func (r *RegisteredPrefixes) HasPrefix(prefixes ...string) bool

func (*RegisteredPrefixes) String added in v0.1.31

func (r *RegisteredPrefixes) String() string

func (*RegisteredPrefixes) ToUnknownPrefixErr added in v0.1.31

func (r *RegisteredPrefixes) ToUnknownPrefixErr() error

type StringSet added in v0.1.33

type StringSet map[string]struct{}

func NewStringSet added in v0.1.33

func NewStringSet(sl ...string) StringSet

func (StringSet) Add added in v0.1.33

func (set StringSet) Add(s string)

func (StringSet) ApplyFunc added in v0.1.33

func (set StringSet) ApplyFunc(applyFn func(string) string) StringSet

func (StringSet) Clear added in v0.1.39

func (set StringSet) Clear()

func (StringSet) Clone added in v0.1.33

func (set StringSet) Clone() StringSet

func (StringSet) Contains added in v0.1.33

func (set StringSet) Contains(s string) bool

func (StringSet) Difference added in v0.1.33

func (set StringSet) Difference(o StringSet) StringSet

func (StringSet) Equals added in v0.1.33

func (set StringSet) Equals(o StringSet) bool

func (StringSet) FuncMatch added in v0.1.33

func (set StringSet) FuncMatch(matchFn func(string, string) bool, matchString string) StringSet

func (StringSet) Intersection added in v0.1.33

func (set StringSet) Intersection(o StringSet) StringSet

func (StringSet) IsEmpty added in v0.1.33

func (set StringSet) IsEmpty() bool

func (StringSet) Len added in v0.1.36

func (set StringSet) Len() int

func (StringSet) MarshalJSON added in v0.1.33

func (set StringSet) MarshalJSON() ([]byte, error)

func (StringSet) MarshalYAML added in v0.1.37

func (set StringSet) MarshalYAML() (interface{}, error)

func (StringSet) Remove added in v0.1.33

func (set StringSet) Remove(s string)

func (StringSet) String added in v0.1.33

func (set StringSet) String() string

func (StringSet) ToSlice added in v0.1.33

func (set StringSet) ToSlice() []string

func (StringSet) Union added in v0.1.33

func (set StringSet) Union(o StringSet) StringSet

func (*StringSet) UnmarshalJSON added in v0.1.33

func (set *StringSet) UnmarshalJSON(data []byte) error

func (*StringSet) UnmarshalYAML added in v0.1.37

func (set *StringSet) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

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