Documentation
¶
Overview ¶
Package stringutils provides utilities for working with strings.
Index ¶
- func Contains(src string, inSlice []string) bool
- func ContainsAnySubstring(s string, subStrings []string) bool
- func DeDup(keys []string) []string
- func DeDupBig(keys []string) []string
- func Difference(a, b []string) []string
- func Filter(slice []string, predicate func(string) bool) []string
- func HasCommonElement(a, b []string) bool
- func HasPrefixSlice(prefix string, slice []string) bool
- func HasSuffixSlice(suffix string, slice []string) bool
- func IndexOf(slice []string, element string) int
- func Intersection(a, b []string) []string
- func IsBlank(s string) bool
- func LastIndexOf(slice []string, element string) int
- func Map(slice []string, transform func(string) string) []string
- func NormalizeWhitespace(s string) string
- func RandomWord(minLen, maxLen int) string
- func RemovePrefix(s, prefix string) string
- func RemoveSuffix(s, suffix string) string
- func Reverse(slice []string) []string
- func SliceToString(s []any) []string
- func Truncate(s string, maxLen int) string
- func TruncateWords(s string, maxWords int) string
- func Union(slices ...[]string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsAnySubstring ¶
ContainsAnySubstring checks if string contains any of provided substring
func DeDup ¶
DeDup remove duplicates from slice. This function is stable - it preserves the order of first occurrences.
func DeDupBig ¶
DeDupBig remove duplicates from slice. Deprecated: Use DeDup instead. This function now just calls DeDup for backwards compatibility.
func Difference ¶ added in v1.3.0
Difference returns elements that are in the first slice but not in the second
func Filter ¶ added in v1.3.0
Filter returns a new slice containing only elements that match the predicate
func HasCommonElement ¶
HasCommonElement checks if any element of the second slice is in the first slice
func HasPrefixSlice ¶ added in v1.1.0
HasPrefixSlice checks if any string in the slice starts with the given prefix
func HasSuffixSlice ¶ added in v1.1.0
HasSuffixSlice checks if any string in the slice ends with the given suffix
func IndexOf ¶ added in v1.3.0
IndexOf returns the index of the first occurrence of element in slice, or -1 if not found
func Intersection ¶ added in v1.3.0
Intersection returns elements that are present in both slices, preserving order from first slice
func LastIndexOf ¶ added in v1.3.0
LastIndexOf returns the index of the last occurrence of element in slice, or -1 if not found
func NormalizeWhitespace ¶ added in v1.3.0
NormalizeWhitespace replaces multiple whitespace characters with single space and trims
func RandomWord ¶ added in v1.2.0
RandomWord generates pronounceable random word with length between minLen and maxLen
func RemovePrefix ¶ added in v1.3.0
RemovePrefix removes the prefix from s if present, otherwise returns s unchanged
func RemoveSuffix ¶ added in v1.3.0
RemoveSuffix removes the suffix from s if present, otherwise returns s unchanged
func SliceToString ¶
SliceToString converts slice of any to slice of string
func Truncate ¶ added in v1.2.0
Truncate cuts string to the given length (in runes) and adds ellipsis if it was truncated if maxLen is less than 4 (3 chars for ellipsis + 1 rune from string), returns empty string
func TruncateWords ¶ added in v1.2.0
TruncateWords cuts string to the given number of words and adds ellipsis if it was truncated returns empty string if maxWords is 0
Types ¶
This section is empty.