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 SplitLines(in interface{}, delimiter string) []string
- func SplitPair(in string, delimiter string) (string, string)
- 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 SplitTriple(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 ¶
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 ¶
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 ¶
HasPrefix tests whether the string s begins with any prefix in prefixes.
func HasAnySuffix ¶
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 ¶
Takes the given string, splits it into lines, and prefixes each line with the given prefix string.
func RelaxedEqual ¶
func SplitLines ¶
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 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 Squeeze ¶
Return the given string with sequences repeating character replaced with a single instance of that character.
func SqueezeFunc ¶
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 ¶
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 ¶
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 ¶
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.