Documentation
¶
Overview ¶
Utilities for converting and manipulating data to and from strings
Index ¶
- Constants
- Variables
- func Autotype(in interface{}) interface{}
- func Camelize(in interface{}) string
- func ConvertTo(toType ConvertType, inI interface{}) (interface{}, error)
- func ConvertToBool(in interface{}) (bool, error)
- func ConvertToBytes(in interface{}) ([]byte, error)
- func ConvertToFloat(in interface{}) (float64, error)
- func ConvertToInteger(in interface{}) (int64, error)
- func ConvertToString(in interface{}) (string, error)
- func ConvertToTime(in interface{}) (time.Time, error)
- func DetectTimeFormat(in string) string
- func Elide(in string, charcount int, trailer ...string) string
- func ElideRight(in string, charcount int, leader ...string) string
- func ElideWords(in string, wordcount int) string
- func ExpandEnv(in string) string
- func HasAnyPrefix(s string, prefixes ...string) bool
- func HasAnySuffix(s string, suffixes ...string) bool
- func Hyphenate(in interface{}) string
- func IsBoolean(in interface{}) bool
- func IsBooleanFalse(in interface{}) bool
- func IsBooleanTrue(in interface{}) bool
- func IsFloat(in interface{}) bool
- func IsHexadecimal(in string, length int) bool
- func IsInteger(in interface{}) bool
- func IsMixedCase(in string) bool
- func IsNumeric(in interface{}) bool
- func IsSeparator(r rune) bool
- func IsSurroundedBy(inI interface{}, prefix string, suffix string) bool
- func IsTime(in interface{}) bool
- func LongestCommonPrefix(inputs []string) string
- func MustBool(in interface{}, fallbackOpt ...bool) bool
- func MustFloat(in interface{}, fallbackOpt ...float64) float64
- func MustInteger(in interface{}, fallbackOpt ...int64) int64
- func MustString(in interface{}, fallbackOpt ...string) string
- func MustTime(in interface{}, fallbackOpt ...time.Time) time.Time
- func PrefixEach(in []string, prefix string) []string
- func PrefixIf(in string, prefix string) string
- func PrefixLines(in interface{}, prefix string) string
- func RelaxedEqual(first interface{}, second interface{}) (bool, error)
- func Snakeify(in interface{}, separator rune) string
- func SoftEqual(first interface{}, second interface{}) bool
- func SplitLines(in interface{}, delimiter string) []string
- func SplitPair(in string, delimiter string) (string, string)
- func SplitPairAuto(in string, delimiter string) (string, interface{})
- func SplitPairRight(in string, delimiter string) (string, string)
- func SplitPairRightTrailing(in string, delimiter string) (string, string)
- func SplitPairTrailing(in string, delimiter string) (string, string)
- func SplitPairTrimSpace(in string, delimiter string) (string, string)
- func SplitPairTrimSpaceAuto(in string, delimiter string) (string, interface{})
- func SplitTrim(s string, sep string, cutset string) []string
- func SplitTrimSpace(s string, sep string) []string
- func SplitTriple(in string, delimiter string) (string, string, string)
- func SplitTripleTrimSpace(in string, delimiter string) (string, string, string)
- func SplitWords(in string) []string
- func Squeeze(in string) string
- func SqueezeFunc(in string, fn OnlySqueezeFunc) string
- func SqueezeSpace(in string) string
- func SuffixEach(in []string, prefix string, suffix string) []string
- func SuffixIf(in string, suffix string) string
- func SuffixLines(in interface{}, suffix string) string
- func Thousandify(in interface{}, separator string, decimal string) string
- func ToByteString(in interface{}, formatString ...string) (string, error)
- func ToBytes(input string) (float64, error)
- func ToString(in interface{}) (string, error)
- func ToStringSlice(in interface{}) ([]string, error)
- func TokenizeFunc(in string, tokenizer func(rune) bool, partfn func(part string) []string) []string
- func Underscore(in interface{}) string
- func Unwrap(in string, prefix string, suffix string) string
- func Wrap(in string, prefix string, suffix string) string
- func WrapEach(in []string, prefix string, suffix string) []string
- func WrapIf(in string, prefix string, suffix string) string
- type ConvertType
- type InterceptFunc
- type OnlySqueezeFunc
- type ScanInterceptor
- type SiPrefix
- type Uuid
Constants ¶
const ( None SiPrefix = 0 Kilo = 1 Mega = 2 Giga = 3 Tera = 4 Peta = 5 Exa = 6 Zetta = 7 Yotta = 8 )
Variables ¶
var BooleanFalseValues = utils.BooleanFalseValues
var BooleanTrueValues = utils.BooleanTrueValues
var DefaultDecimalSeparator = `.`
var DefaultThousandsSeparator = `,`
var ExpandEnvPreserveIfEmpty = false
If set to true, ExpandEnv() will preserve ${...} sequences whose resulting value would yield an empty string. Fallback and formatting values are still supported, as the determination of value emptiness is made after parsing the sequence. This is to avoid unset environment variables resulting in the escape sequences being erased, which is often the case when running ExpandEnv() against various shell languages (Bash, et. al)
var ExpandEnvTempDelimiterClose = "\u3019" // RIGHT WHITE TORTOISE SHELL BRACKET (U+3019, Pe): 〙
var ExpandEnvTempDelimiterOpen = "\u3018" // LEFT WHITE TORTOISE SHELL BRACKET (U+3018, Ps): 〘
var NilStrings = utils.NilStrings
var TimeFormats = utils.TimeFormats
Functions ¶
func ConvertTo ¶
func ConvertTo(toType ConvertType, inI interface{}) (interface{}, error)
func ConvertToBool ¶
func ConvertToBytes ¶
func ConvertToFloat ¶
func ConvertToInteger ¶
func ConvertToString ¶
func ConvertToTime ¶
func DetectTimeFormat ¶
func ElideRight ¶ added in v1.8.31
Truncate the given string to a certain number of characters from the end.
func ElideWords ¶
Truncate the given string to a certain number of words.
func ExpandEnv ¶ added in v1.7.16
Return the given string with environment variable substitution sequences expanded and (optionally) formatted. This function operates similarly to os.ExpandEnv, but accepts custom fmt.Printf formatting directives.
func HasAnyPrefix ¶ added in v1.8.46
HasPrefix tests whether the string s begins with any prefix in prefixes.
func HasAnySuffix ¶ added in v1.8.46
HasSuffix tests whether the string s begins with any suffix in suffixes.
func IsBooleanFalse ¶
func IsBooleanFalse(in interface{}) bool
func IsBooleanTrue ¶
func IsBooleanTrue(in interface{}) bool
func IsHexadecimal ¶
Returns whether the given string is a hexadecimal number. If the string is prefixed with "0x", the prefix is removed first. If length is greater than 0, the length of the input (excluding prefix) is checked as well.
func IsMixedCase ¶
Returns whether the letters (Unicode Catgeory 'L') in a given string are homogenous in case (all upper-case or all lower-case).
func IsSeparator ¶
func IsSurroundedBy ¶
func LongestCommonPrefix ¶
func MustInteger ¶
func MustString ¶
func PrefixEach ¶
Prefix each element in the given string slice with prefix.
func PrefixLines ¶ added in v1.8.10
Takes the given string, splits it into lines, and prefixes each line with the given prefix string.
func RelaxedEqual ¶
func SoftEqual ¶ added in v1.9.7
func SoftEqual(first interface{}, second interface{}) bool
A case insensitive, single return version of RelaxedEqual that trims leading and trailing whitespace from strings before comparison.
func SplitLines ¶ added in v1.7.12
Split the given input into lines.
func SplitPair ¶
Split the given string into two parts. If there is only one resulting part, that part will be the first return value and the second return value will be empty.
func SplitPairAuto ¶ added in v1.9.6
Identical to SplitPair, but returns the result of passing the second value in the pair to Autotype()
func SplitPairRight ¶
Split the given string into two parts from the right. If there is only one resulting part, that part will be the first return value and the second return value will be empty.
func SplitPairRightTrailing ¶
Split the given string into two parts. If there is only one resulting part, that part will be the second return value and the first return value will be empty.
func SplitPairTrailing ¶
Split the given string into two parts. If there is only one resulting part, that part will be the second return value and the first return value will be empty.
func SplitPairTrimSpace ¶ added in v1.8.89
Identical to SplitPair, but trims any leading and trailing whitespace from each output value.
func SplitPairTrimSpaceAuto ¶ added in v1.9.6
Identical to SplitPairTrimSpace, but returns the result of passing the second value in the pair to Autotype()
func SplitTrim ¶ added in v1.10.0
Identical to strings.Split, but trims any leading and trailing whitespace from each element using strings.Trim.
func SplitTrimSpace ¶ added in v1.10.0
Identical to strings.Split, but trims any leading and trailing whitespace from each element.
func SplitTripleTrimSpace ¶ added in v1.8.89
Identical to SplitPair, but trims any leading and trailing whitespace from each output value.
func Squeeze ¶ added in v1.6.19
Return the given string with sequences repeating character replaced with a single instance of that character.
func SqueezeFunc ¶ added in v1.6.19
func SqueezeFunc(in string, fn OnlySqueezeFunc) string
Return the given string with sequences of characters matching the given function replaced with a single instance of that character.
func SqueezeSpace ¶ added in v1.6.19
Return the given string with sequences of whitespace characters replaced with a single instance of that character.
func SuffixEach ¶
Suffix each element in the given string slice with suffix.
func SuffixLines ¶ added in v1.8.10
Takes the given string, splits it into lines, and suffixes each line with the given suffix string.
func Thousandify ¶
func ToByteString ¶
func ToStringSlice ¶
func TokenizeFunc ¶
func Underscore ¶
func Underscore(in interface{}) string
Types ¶
type ConvertType ¶
type ConvertType = utils.ConvertType
func ParseType ¶
func ParseType(name string) ConvertType
type InterceptFunc ¶
type InterceptFunc func(seq []byte)
type OnlySqueezeFunc ¶ added in v1.6.19
type ScanInterceptor ¶
type ScanInterceptor struct { Disabled bool // contains filtered or unexported fields }
A ScanInterceptor is used as a SplitFunc on a bufio.Scanner. It will look at the stream of bytes being scanned for specific substrings. The registered handler function associated with a substring will be called whenever it is seen in the stream. The passthrough SplitFunc is called as normal. This allows for a stream to be split and processed while also being inspected for specific content, allowing the user to react to that content as it comes by.
func NewScanInterceptor ¶
func NewScanInterceptor(passthrough bufio.SplitFunc, intercepts ...map[string]InterceptFunc) *ScanInterceptor
func (*ScanInterceptor) BytesScanned ¶
func (self *ScanInterceptor) BytesScanned() int64
Return the total number of bytes this scanner has scanned.
func (*ScanInterceptor) Intercept ¶
func (self *ScanInterceptor) Intercept(sequence string, handler InterceptFunc)
Add an intercept sequence and handler. If the sequence is already registered, its handler function will be replaced with this one.
func (*ScanInterceptor) InterceptCounts ¶
func (self *ScanInterceptor) InterceptCounts() map[string]int64
Returns a map of intercept sequences and the number of times each one was fired.