Documentation ¶
Index ¶
- Constants
- func BuildFQDN(namelets ...string) string
- func BuildFQDN2(delimiter string, namelets ...string) string
- func BuildFQDNWithEsc(namelets ...string) string
- func ByteIndexWithEsc(s, delim, esc []byte) int
- func ByteLenOfRunes(rs []rune) int
- func ByteSplitWithEsc(s, delim, esc []byte, cap int) [][]byte
- func ByteUnescape(b, esc []byte, inPlace bool) []byte
- func CopySlice(src []string) []string
- func CopyStrPtr(sp *string) *string
- func FirstNonBlank(strs ...string) string
- func HasDup(src []string) bool
- func IndexWithEsc(s, delim string, esc string) int
- func IsStrNonBlank(s string) bool
- func IsStrPtrNonBlank(sp *string) bool
- func LastNameletOfFQDN(fqdn string) string
- func LastNameletOfFQDN2(delimiter, fqdn string) string
- func LastNameletOfFQDNWithEsc(fqdn string) string
- func MapSlice(src []string, f func(string) (string, error)) ([]string, error)
- func MergeSlices(a, b []string) []string
- func NoErrMapSlice(src []string, f func(string) string) []string
- func RunePtr(r rune) *rune
- func SplitWithEsc(s, delim string, esc string) []string
- func StrPtr(s string) *string
- func StrPtrOrElse(sp *string, orElse string) string
- func Unescape(s, esc string) string
- type KeyMapper
- type RuneTrie
Constants ¶
const ( // FQDNDelimiter is the default FQDN delimiter. FQDNDelimiter = "." // FQDNEsc is the default escape char for FQDN. Esc is used for escaping "." and itself. FQDNEsc = "%" )
Variables ¶
This section is empty.
Functions ¶
func BuildFQDN2 ¶
BuildFQDN2 builds an FQDN from a slice of namelet strings and a given delimiter.
func BuildFQDNWithEsc ¶ added in v0.0.14
BuildFQDNWithEsc builds an FQDN (dot delimited) from a slice of namelet strings with proper escaping. e.g. If namelets are 'a.b', 'c%d', it will return 'a%.b.c%%d'. Note this function isn't optimized for alloc/perf.
func ByteIndexWithEsc ¶ added in v0.0.8
ByteIndexWithEsc searches for 'delim' inside 's' with escaping sequence taking into account. Note 'delim' must not contain 'esc', or if it does, 'esc' inside 'delim' will be treated as regular bytes.
func ByteLenOfRunes ¶ added in v0.0.7
ByteLenOfRunes returns byte length of a rune slice.
func ByteSplitWithEsc ¶ added in v0.0.6
ByteSplitWithEsc is similar to SplitWithEsc but operating on []byte. 'cap' is just an indicator to the function that what the initial cap the returned split slice should be pre-allocated.
func ByteUnescape ¶ added in v0.0.8
ByteUnescape unescapes a []byte sequence with an escape []byte sequence. If 'inPlace' is true, the unescaping modification is taking place inside the original 'b' and 'b' will be returned with length properly adjusted. If 'inPlace' is false, the unescaping is taking place inside a new []byte, the new []byte will be returned and the original 'b' is untouched.
func CopySlice ¶
CopySlice copies a string slice. The returned slice is guaranteed to be a different slice (thus the name Copy) so modifying the src from the caller side won't affect the returned slice.
func CopyStrPtr ¶
CopyStrPtr copies a string pointer and its underlying string value, if set, into a new string pointer.
func FirstNonBlank ¶
FirstNonBlank returns the first non-blank string value of the input strings, if any; or "" is returned.
func IndexWithEsc ¶
IndexWithEsc searches for 'delim' inside 's' with escaping sequence taking into account. Note 'delim' must not contain 'esc', or if it does, 'esc' inside 'delim' will be treated as regular string.
func IsStrNonBlank ¶
IsStrNonBlank checks if a string is blank or not.
func IsStrPtrNonBlank ¶
IsStrPtrNonBlank checks if the value represented by a string pointer is blank or not.
func LastNameletOfFQDN ¶
LastNameletOfFQDN returns the last namelet of an FQDN delimited by default delimiter. If there is no delimiter in the FQDN, then the FQDN itself is returned.
func LastNameletOfFQDN2 ¶
LastNameletOfFQDN2 returns the last namelet of an FQDN delimited by given delimiter. If there is no delimiter in the FQDN, then the FQDN itself is returned.
func LastNameletOfFQDNWithEsc ¶ added in v0.0.14
LastNameletOfFQDNWithEsc returns the last namelet of an FQDN delimited by default delimiter, with escaping considered. If there is no delimiter in the FQDN, then the FQDN itself is returned. Note this function isn't optimized for alloc/perf.
func MapSlice ¶
MapSlice returns a new string slice whose element is transformed from input slice's corresponding element by a transform func. If any error occurs during any transform, returned slice will be nil together with the error.
func MergeSlices ¶
MergeSlices returns a new slice with two input slice content merged together. The result is guaranteed to be a new slice thus modifying a or b from the caller side won't affect the returned slice.
func NoErrMapSlice ¶
NoErrMapSlice returns a new string slice whose element is transformed from input slice's corresponding element by a transform func. The transform func must not fail and NoErrMapSlice guarantees to succeed.
func SplitWithEsc ¶
SplitWithEsc is similar to strings.Split but taking escape sequence into consideration. For example, SplitWithEsc("abc%|efg|xyz", "|", "%") would return []string{"abc%|efg", "xyz"}.
func StrPtrOrElse ¶
StrPtrOrElse returns the string value of the string pointer if non-nil, or the default string value.
Types ¶
type KeyMapper ¶
KeyMapper maps one rune or a segment of consecutive runes into a key for inserting into RuneTrie, and returns how many bytes needs to be advanced
type RuneTrie ¶
type RuneTrie struct {
// contains filtered or unexported fields
}
RuneTrie is a trie of strings. By default, each trie node corresponds to a rune in a string, however, user of RuneTrie can provide a custom mapper that can map one or multiple consecutive runes into a trie key.
func NewRuneTrie ¶
NewRuneTrie creates a new RuneTrie.
func (*RuneTrie) Add ¶
Add inserts a string and its associated value into RuneTrie and returns true if the value is added; false if an existing value is replaced.
func (*RuneTrie) MarshalJSON ¶
MarshalJSON json marshals a RuneTrie. Should only be used in tests.