string_utils

package
v1.206.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NonOfficialWhitespaceChars = []string{

	"\u180E",
	"\u200B",
	"\u200C",
	"\u200D",
	"\u200E",
	"\u2060",
	"\u202C",
	"\uFEFF",
	"\u00AD",
}
View Source
var WhitespaceChars = []string{

	"\u0009",
	"\u000A",
	"\u000B",
	"\u000C",
	"\u000D",
	"\u0020",
	"\u0085",
	"\u00A0",
	"\u1680",
	"\u2000",
	"\u2001",
	"\u2002",
	"\u2003",
	"\u2004",
	"\u2005",
	"\u2006",
	"\u2007",
	"\u2008",
	"\u2009",
	"\u200A",
	"\u2028",
	"\u2029",
	"\u202F",
	"\u205F",
	"\u3000",
}

Functions

func Capitalize added in v1.130.0

func Capitalize(s string) string

func Concat added in v1.111.0

func Concat(args []string, separator string) string

Concat concatenates all specified non-empty strings with ", " separators

func ConcatP

func ConcatP(args ...*string) string

ConcatP concatenates all specified non-empty strings with ", " separators

func Equal

func Equal(a string, b string) bool

func Float64ToString

func Float64ToString(number float64, precision int) string

func Float64ToStringWithPrec

func Float64ToStringWithPrec(number float64, prec int) string

func HTMLStringToTextBytes added in v1.205.0

func HTMLStringToTextBytes(html string) ([]byte, error)

func HTMLStringToTextString added in v1.205.0

func HTMLStringToTextString(html string) (string, error)

func HumanReadableToKey added in v1.148.0

func HumanReadableToKey(s string, separator string) string

func Int64SliceToString

func Int64SliceToString(numbers []int64) string

func Int64SliceToStringSlice

func Int64SliceToStringSlice(numbers []int64) []string

func Int64ToString

func Int64ToString(number int64) string

func IntToString

func IntToString(number int) string

func IsAlphaNumeric

func IsAlphaNumeric(str string) bool

func IsAlphaNumericOrDash

func IsAlphaNumericOrDash(str string) bool

func IsEmpty

func IsEmpty(sp *string) bool

func IsNumericString

func IsNumericString(s string) bool

IsNumericString returns true if the string can be converted to a float without error

func IsSnakeCase

func IsSnakeCase(name string) bool

func KeyToHumanReadable

func KeyToHumanReadable(s string) string

func LimitStringToMaxLength

func LimitStringToMaxLength(str string, maxLen int) string

func PascalCaseToSentence

func PascalCaseToSentence(pascal string) string

func PrettyJSON added in v1.101.0

func PrettyJSON(jsonString string) (validJson bool, prettyString string)

func RemoveAllWhiteSpaces

func RemoveAllWhiteSpaces(s string) string

func ReplaceAllRegexStringSubmatch added in v1.169.0

func ReplaceAllRegexStringSubmatch(re *regexp.Regexp, s string, replaceWith string) string

ReplaceAllRegexStringSubmatch finds the submatches for a regular expression that has a single capturing group and replaces all the submatches (i.e. the part that matches the capturing group) with replaceWith. E.g. the regular expression re = a(x*)b captures any number of x's that are between an a and b. ReplaceAllRegexStringSubmatch(re, "-axxb-ab-axb-x-ax-xb-ba-", "?") will result in "-a?b-a?b-a?b-x-ax-xb-ba-"

func ReplaceCaseInsensitive

func ReplaceCaseInsensitive(string, toReplace, replaceWith string) string

func ReplaceNonSpacingMarks

func ReplaceNonSpacingMarks(str string) string

ReplaceNonSpacingMarks removes diacritics e.g. êžů becomes ezu

func SentenceCase

func SentenceCase(str string) string

func SnakeToKebabString

func SnakeToKebabString(s string) string

func SplitString

func SplitString(str string, sep []rune) []string

SplitString separates a string on any character in the list of sep

func StringContainsNumbers added in v1.201.0

func StringContainsNumbers(s string) bool

func StringContainsOnlyNumbers added in v1.201.0

func StringContainsOnlyNumbers(s string) bool

func StringTrimQuotes

func StringTrimQuotes(stringToTrim string) string

StringTrimQuotes - trims quotes from a string (ie: "foo" will return foo)

func ToJSONString

func ToJSONString(object interface{}) (string, error)

func TrimAndToLower added in v1.199.0

func TrimAndToLower(s string) string

TrimAndToLower trims the whitespace from a string and converts it to lowercase

func TrimP

func TrimP(sp *string) *string

TrimP trims specified strings, replacing empty string with nil

func TrimQuotes

func TrimQuotes(stringToTrim string) string

TrimQuotes - trims quotes from a string (ie: "foo" will return foo)

func TrimSpaceForPointer added in v1.151.0

func TrimSpaceForPointer(s *string) *string

func ValidateStringAsInt64

func ValidateStringAsInt64(stringValue string) error

Types

type KeyReader

type KeyReader interface {
	Keys(prefix string) []string
	GetString(key string) (value string, ok bool)
}

KeyReader is an interface to read string "<key>":"<value>" pairs which is common to read from the environment it is abstracted so the same interface can be implemented for reading for example from REDIS and other sources

func EnvironmentKeyReader

func EnvironmentKeyReader() KeyReader

Jump to

Keyboard shortcuts

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