Documentation ¶
Overview ¶
Package stringex of the Tideland Go Library helps when working with strings.
Index ¶
- func SplitFilter(s, sep string, f func(p string) bool) []string
- func SplitMap(s, sep string, m func(p string) (string, bool)) []string
- type Defaulter
- type Processor
- type ProcessorFunc
- func NewChainProcessor(processors ...Processor) ProcessorFunc
- func NewConditionProcessor(decider, affirmer, negater Processor) ProcessorFunc
- func NewLoopProcessor(processor Processor) ProcessorFunc
- func NewLowerProcessor() ProcessorFunc
- func NewMatchProcessor(pattern string) ProcessorFunc
- func NewSplitMapProcessor(sep string, mapper Processor) ProcessorFunc
- func NewSubstringProcessor(index, length int) ProcessorFunc
- func NewTrimFuncProcessor(f func(r rune) bool) ProcessorFunc
- func NewTrimPrefixProcessor(prefix string) ProcessorFunc
- func NewTrimSuffixProcessor(prefix string) ProcessorFunc
- func NewUpperProcessor() ProcessorFunc
- func WrapProcessorFunc(f func(fin string) string) ProcessorFunc
- type StringValuer
- type Valuer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SplitFilter ¶
SplitFilter splits the string s by the separator sep and then filters the parts. Only those where f returns true will be part of the result. So it even cout be empty.
Types ¶
type Defaulter ¶
type Defaulter interface { fmt.Stringer // AsString returns the value itself, only an error will // return the default. AsString(v Valuer, dv string) string // AsStringSlice returns the value as slice of strings // separated by the passed separator. AsStringSlice(v Valuer, sep string, dv []string) []string // AsStringMap returns the value as map of strings to strings. // The rows are separated by the rsep, the key/values per // row with kvsep. AsStringMap(v Valuer, rsep, kvsep string, dv map[string]string) map[string]string // AsBool returns the value interpreted as bool. Here the // strings 1, t, T, TRUE, true, True are interpreted as // true, the strings 0, f, F, FALSE, false, False as false. AsBool(v Valuer, dv bool) bool // AsInt returns the value interpreted as int. AsInt(v Valuer, dv int) int // AsInt64 returns the value interpreted as int64. AsInt64(v Valuer, dv int64) int64 // AsUint returns the value interpreted as uint. AsUint(v Valuer, dv uint) uint // AsUint64 returns the value interpreted as uint64. AsUint64(v Valuer, dv uint64) uint64 // AsFloat64 returns the value interpreted as float64. AsFloat64(v Valuer, dv float64) float64 // AsTime returns the value interpreted as time in // the given layout. AsTime(v Valuer, layout string, dv time.Time) time.Time // AsDuration returns the value interpreted as duration. AsDuration(v Valuer, dv time.Duration) time.Duration }
Defaulter provides an access to valuers interpreting the strings as types. In case of access or conversion errors these errors will be logged and the passed default values are returned.
func NewDefaulter ¶
NewDefaulter creates a defaulter with the given settings.
type Processor ¶
type Processor interface { // Process takes a string and processes it. If the result is to // be ignored the bool has to be false. Process(in string) (string, bool) }
Processor defines a type able to process strings.
type ProcessorFunc ¶
ProcessorFunc describes functions processing a string and returning the new one. A returned false means to ignore the result.
func NewChainProcessor ¶
func NewChainProcessor(processors ...Processor) ProcessorFunc
NewChainProcessor creates a processor chaning the passed processors.
func NewConditionProcessor ¶
func NewConditionProcessor(decider, affirmer, negater Processor) ProcessorFunc
NewConditionProcessor creates a processor taking the first processor for creating a temporary result and a decision. Based on the decision the temporary result is passed to an affirmer or a negater.
func NewLoopProcessor ¶
func NewLoopProcessor(processor Processor) ProcessorFunc
NewLoopProcessor creates a processor letting the processor function work on the input until it returns false (aka while true). Itself then will return the processed sting and always true.
func NewLowerProcessor ¶
func NewLowerProcessor() ProcessorFunc
NewLowerProcessor returns a processor converting the input to lower-case.
func NewMatchProcessor ¶
func NewMatchProcessor(pattern string) ProcessorFunc
NewMatchProcessor returns a processor evaluating the input against a given pattern and returns the input and true when it is matching.
func NewSplitMapProcessor ¶
func NewSplitMapProcessor(sep string, mapper Processor) ProcessorFunc
NewSplitMapProcessor creates a processor splitting the input and mapping the parts. It will only contain those where the mapper returns true. So it can be used as a filter too. Afterwards the collected mapped parts are joined again.
func NewSubstringProcessor ¶
func NewSubstringProcessor(index, length int) ProcessorFunc
NewSubstringProcessor returns a processor slicing the input based on the index and length.
func NewTrimFuncProcessor ¶
func NewTrimFuncProcessor(f func(r rune) bool) ProcessorFunc
NewTrimFuncProcessor returns a processor trimming prefix and suffix of the input based on the return value of the passed function checking each rune.
func NewTrimPrefixProcessor ¶
func NewTrimPrefixProcessor(prefix string) ProcessorFunc
NewTrimPrefixProcessor returns a processor trimming a prefix of the input as long as it can find it.
func NewTrimSuffixProcessor ¶
func NewTrimSuffixProcessor(prefix string) ProcessorFunc
NewTrimSuffixProcessor returns a processor trimming a prefix of the input as long as it can find it.
func NewUpperProcessor ¶
func NewUpperProcessor() ProcessorFunc
NewUpperProcessor returns a processor converting the input to upper-case.
func WrapProcessorFunc ¶
func WrapProcessorFunc(f func(fin string) string) ProcessorFunc
WrapProcessorFunc takes a standard string processing function and returns it as a ProcessorFunc.
type StringValuer ¶
type StringValuer string
StringValuer implements the Valuer interface for simple strings.
func (StringValuer) Value ¶
func (sv StringValuer) Value() (string, error)
Value implements the Valuer interface.