stringex

package
v4.21.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2017 License: BSD-3-Clause Imports: 6 Imported by: 2

Documentation

Overview

The Tideland Go Library stringex package helps when working with strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitFilter

func SplitFilter(s, sep string, f func(p string) bool) []string

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.

func SplitMap

func SplitMap(s, sep string, m func(p string) (string, bool)) []string

SplitMap splits the string s by the separator sep and then maps the parts by the function m. Only those where m also returns true will be part of the result. So it even could 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 seperator.
	AsStringSlice(v Valuer, sep string, dv []string) []string

	// AsStringMap returns the value as map of strings to strings.
	// The rows are seperated 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

func NewDefaulter(id string, log bool) Defaulter

NewDefaulter creates a defaulter with the given settings.

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.

type Valuer

type Valuer interface {
	// Value returns a string or a potential error during access.
	Value() (string, error)
}

Valuer describes returning a string value or an error if it does not exist are another access error happened.

Jump to

Keyboard shortcuts

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