Documentation ¶
Index ¶
- func CompareStringsShorterFirst[T ~string](a, b T) int
- func ConvertSlice[T, S ~string](s []S) []T
- func CutTrimSpace[S ~string](s, sep S) (before, after S, found bool)
- func DerefPtr(ptr *string) string
- func EmptyStringToNil(str string) any
- func EqualJSON(a, b any) bool
- func EqualPtrOrString(a, b *string) bool
- func HTMLEscapeSpecialRunes(str string) string
- func IndexInStrings(str string, slice []string) int
- func IsNorLetterOrDigit(r rune) bool
- func IsSpace(r rune) bool
- func IsWordSeparator(r rune) bool
- func Join[T ~string](elems []T, sep string) string
- func KeepRunes(str []byte, keepRunes ...IsRuneFunc) []byte
- func KeepRunesString(str string, keepRunes ...IsRuneFunc) string
- func MakeValidFileName(name string) string
- func MapRuneIsAfterWordSeparator(str string) []bool
- func NormalizeExt(ext string) string
- func ParseDomainName(word string) string
- func ParseDomainNameIndex(word string) (domain string, indices []int)
- func Ptr(str string) *string
- func RandomString(length int) string
- func RandomStringBytes(length int) []byte
- func RemoveRunes(str []byte, removeRunes ...IsRuneFunc) []byte
- func RemoveRunesString(str string, removeRunes ...IsRuneFunc) string
- func SanitizeFileName(name string) string
- func SanitizeLineEndings(text string) string
- func SanitizeLineEndingsBytes(text []byte) []byte
- func SplitAndTrimIndex(str []byte, isSplitRune, isTrimRune IsRuneFunc) (indices [][]int)
- func StringContainsAny(str string, subStrings []string) bool
- func StringToPtrEmptyToNil(str string) *string
- func SubStringIn(subString string, strs []string) bool
- func ToSnakeCase(s string) string
- func TransliterateSpecialCharacters(str string) string
- func TransliterateSpecialCharactersMaxLen(str string, maxLen int) string
- func TrimSpace[S ~string](s S) S
- func TrimSpaceBytes(s []byte) []byte
- func Truncate(s string, i int) string
- func TruncateWithEllipsis(s string, i int) string
- type IsRuneFunc
- type StrMutex
- type StringSet
- func (set StringSet) Add(str string)
- func (set StringSet) AddSet(other StringSet)
- func (set StringSet) AddSlice(s []string)
- func (set StringSet) Clear()
- func (set StringSet) Clone() StringSet
- func (set StringSet) Contains(str string) bool
- func (set StringSet) ContainsAny(strs ...string) bool
- func (set StringSet) Delete(str string)
- func (set StringSet) DeleteSet(other StringSet)
- func (set StringSet) DeleteSlice(s []string)
- func (set StringSet) Diff(other StringSet) StringSet
- func (set StringSet) Equal(other StringSet) bool
- func (set StringSet) Sorted() (s []string)
- func (set StringSet) String() string
- func (set StringSet) StringContainsAnyOfSet(str string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareStringsShorterFirst ¶
CompareStringsShorterFirst compares two strings by length first and then by lexicographical order.
func ConvertSlice ¶
func ConvertSlice[T, S ~string](s []S) []T
ConvertSlice converts a slice of one string type type to another string type. It does this by reinterpreting the slice's underlying memory using unsafe.Pointer.
func CutTrimSpace ¶
CutTrimSpace slices s around the first instance of sep, returning the text before and after sep with all leading and trailing white space removed, as defined by Unicode. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false.
func EmptyStringToNil ¶
EmptyStringToNil returns str or nil if it is empty.
func EqualJSON ¶
EqualJSON returns true a and b are equal on a value basis, or if their marshalled JSON representation is equal.
func EqualPtrOrString ¶
EqualPtrOrString returns if a and b are equal pointers or if the pointed to strings are equal
func HTMLEscapeSpecialRunes ¶
func IndexInStrings ¶
IndexInStrings returns the index of where str can be found in slice, or -1 if it was not found.
func IsNorLetterOrDigit ¶
func IsSpace ¶
IsSpace reports whether r is a space character as defined by Unicode or zero width space '\u200b'.
func IsWordSeparator ¶
func Join ¶
Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.
func KeepRunes ¶
func KeepRunes(str []byte, keepRunes ...IsRuneFunc) []byte
KeepRunes returns a copy of str where with all runes kept in it where any call to a keepRunes function reeturns true.
func KeepRunesString ¶
func KeepRunesString(str string, keepRunes ...IsRuneFunc) string
KeepRunesString returns a copy of str where with all runes kept in it where any call to a keepRunes function reeturns true.
func MakeValidFileName ¶
MakeValidFileName replaces invalid filename characters with '_'. See also SanitizeFileName that does more than just replacing characters.
func NormalizeExt ¶
func ParseDomainName ¶
func ParseDomainNameIndex ¶
func RandomString ¶
RandomString returns an URL compatible random string with the requested length.
func RandomStringBytes ¶
RandomStringBytes returns an URL compatible random string with the requested length as []byte slice, saving a string copy compared to RandomString.
func RemoveRunes ¶
func RemoveRunes(str []byte, removeRunes ...IsRuneFunc) []byte
RemoveRunes returns a copy of str with all runes removed where any call to a removeRunes function reeturns true.
func RemoveRunesString ¶
func RemoveRunesString(str string, removeRunes ...IsRuneFunc) string
RemoveRunesString returns a copy of str with all runes removed where any call to a removeRunes function reeturns true. If no rune was removed, the string is not copied.
func SanitizeFileName ¶
SanitizeFileName creates a nice sane filename. It does more than just replacing invalid characters.
func SanitizeLineEndings ¶
SanitizeLineEndings converts all line endings to just '\n'
func SanitizeLineEndingsBytes ¶
SanitizeLineEndingsBytes converts all line endings to just '\n'
func SplitAndTrimIndex ¶
func SplitAndTrimIndex(str []byte, isSplitRune, isTrimRune IsRuneFunc) (indices [][]int)
SplitAndTrimIndex first splits str into words not containing isSplitRune, then trims the words with isTrimRune.
func StringContainsAny ¶
StringContainsAny returns if str is a sub string in any of subStrings.
func StringToPtrEmptyToNil ¶
StringToPtrEmptyToNil returns the address of a string or nil if the string is empty.
func SubStringIn ¶
SubStringIn returns if subString is equal or a substring of any of strs.
func ToSnakeCase ¶
ToSnakeCase converts s to snake case by lower casing everything and inserting '_' before every new upper case character in s. Whitespace, symbol, and punctuation characters will be replace by '_'.
func TransliterateSpecialCharacters ¶
TransliterateSpecialCharacters returns the string sanitized as valid UTF-8 with common European special characters transliterated to single or multiple ANSI characters.
func TransliterateSpecialCharactersMaxLen ¶
TransliterateSpecialCharactersMaxLen returns the string sanitized as valid UTF-8 with common European special characters transliterated to single or multiple ANSI characters.
The maxLen argument limits the number of runes returned. A negative value means no limit.
func TrimSpace ¶
func TrimSpace[S ~string](s S) S
TrimSpace returns a slice of the string s, with all leading and trailing white space removed including zero width space '\u200b'.
func TrimSpaceBytes ¶
TrimSpaceBytes returns a slice of the bytes string s, with all leading and trailing white space removed including zero width space '\u200b'.
func TruncateWithEllipsis ¶
Types ¶
type IsRuneFunc ¶
IsRuneFunc is function pionter for specifying if a rune matches a criteria
func IsRune ¶
func IsRune(runes ...rune) IsRuneFunc
func IsRuneAll ¶
func IsRuneAll(isRune ...IsRuneFunc) IsRuneFunc
func IsRuneAny ¶
func IsRuneAny(isRune ...IsRuneFunc) IsRuneFunc
func IsRuneInverse ¶
func IsRuneInverse(isRune IsRuneFunc) IsRuneFunc
type StrMutex ¶
type StrMutex struct {
// contains filtered or unexported fields
}
StrMutex manages a unique mutex for every locked string key. The mutex for a key exists as long as there are any locks waiting to be unlocked. This is equivalent to declaring a mutex variable for every key, except that the key and the number of mutexes are dynamic.
type StringSet ¶
type StringSet map[string]struct{}
func NewStringSet ¶
func NewStringSetMergeSlices ¶
func (StringSet) ContainsAny ¶
func (StringSet) DeleteSlice ¶
func (StringSet) StringContainsAnyOfSet ¶
StringContainsAnyOfSet returns true if the passed string contains any of the strings of the StringSet.