Documentation ¶
Overview ¶
Package strfn provides curried functional versions of the functions provided by the "strings" package so they can be more easily used within "enum" and "maps" functions.
Index ¶
- func Compare(b string) func(a string) int
- func Contains(substr string) func(s string) bool
- func ContainsAny(chars string) func(s string) bool
- func ContainsRune(r rune) func(s string) bool
- func Count(substr string) func(s string) int
- func EqualFold(t string) func(s string) bool
- func FieldsFunc(f func(rune) bool) func(s string) []string
- func First(s string) string
- func HasPrefix(prefix string) func(s string) bool
- func HasSuffix(suffix string) func(s string) bool
- func Index(substr string) func(s string) int
- func IndexAny(chars string) func(s string) int
- func IndexByte(c byte) func(s string) int
- func IndexFunc(f func(rune) bool) func(s string) int
- func IndexRune(r rune) func(s string) int
- func Join(sep string) func(elems []string) string
- func Last(s string) string
- func LastIndex(substr string) func(s string) int
- func LastIndexAny(chars string) func(s string) int
- func LastIndexByte(c byte) func(s string) int
- func LastIndexFunc(f func(rune) bool) func(s string) int
- func Length(s string) int
- func Map(mapping func(rune) rune) func(s string) string
- func Repeat(count int) func(s string) string
- func Replace(old, new string, n int) func(s string) string
- func ReplaceAll(old, new string) func(s string) string
- func RunesWithIndex(s string, f func(i int, value rune))
- func Split(sep string) func(s string) []string
- func SplitAfter(sep string) func(s string) []string
- func SplitAfterN(sep string, n int) func(s string) []string
- func SplitN(sep string, n int) func(s string) []string
- func Substr(start, end int) func(string) string
- func ToLowerSpecial(c unicode.SpecialCase) func(s string) string
- func ToTitleSpecial(c unicode.SpecialCase) func(s string) string
- func ToUpperSpecial(c unicode.SpecialCase) func(s string) string
- func ToValidUTF8(replacement string) func(s string) string
- func Trim(cutset string) func(s string) string
- func TrimFunc(f func(rune) bool) func(s string) string
- func TrimLeft(cutset string) func(s string) string
- func TrimLeftFunc(f func(rune) bool) func(s string) string
- func TrimPrefix(prefix string) func(s string) string
- func TrimRight(cutset string) func(s string) string
- func TrimRightFunc(f func(rune) bool) func(s string) string
- func TrimSuffix(suffix string) func(s string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare returns an integer comparing two strings lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
func ContainsAny ¶
ContainsAny reports whether any Unicode code points in chars are within s.
func ContainsRune ¶
ContainsRune reports whether the Unicode code point r is within s.
func Count ¶
Count counts the number of non-overlapping instances of substr in s. If substr is an empty string, Count returns 1 + the number of Unicode code points in s.
func EqualFold ¶
EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.
func FieldsFunc ¶
FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned.
FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c.
func Index ¶
Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.
func IndexAny ¶
IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.
func IndexByte ¶
IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
func IndexFunc ¶
IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.
func IndexRune ¶
IndexRune returns the index of the first instance of the Unicode code point r, or -1 if rune is not present in s. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence.
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 LastIndex ¶
LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
func LastIndexAny ¶
LastIndexAny returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.
func LastIndexByte ¶
LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
func LastIndexFunc ¶
LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.
func Map ¶
Map returns a copy of the string s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement.
func Repeat ¶
Repeat returns a new string consisting of count copies of the string s.
It panics if count is negative or if the result of (len(s) * count) overflows.
func Replace ¶
Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new.
If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.
If n < 0, there is no limit on the number of replacements.
func ReplaceAll ¶
ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new.
If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.
func RunesWithIndex ¶
RunesWithIndex iterates over a string and calls the provided function with its index and rune. This is because I couldn't figure out how to make WithIndex work with a string and its runes.
func Split ¶
Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators.
If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s.
If sep is empty, Split splits after each UTF-8 sequence. If both s and sep are empty, Split returns an empty slice.
It is equivalent to SplitN with a count of -1.
func SplitAfter ¶
SplitAfter slices s into all substrings after each instance of sep and returns a slice of those substrings.
If s does not contain sep and sep is not empty, SplitAfter returns a slice of length 1 whose only element is s.
If sep is empty, SplitAfter splits after each UTF-8 sequence. If both s and sep are empty, SplitAfter returns an empty slice.
It is equivalent to SplitAfterN with a count of -1.
func SplitAfterN ¶
SplitAfterN slices s into substrings after each instance of sep and returns a slice of those substrings.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for SplitAfter.
func SplitN ¶
SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder. n == 0: the result is nil (zero substrings) n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled as described in the documentation for Split.
func Substr ¶
Substr returns a function that returns a substring from [start, end) (just like s[start:end]).
If start >= len(s), "" is returned. If end >= len(s), s[start:] is returned.
func ToLowerSpecial ¶
func ToLowerSpecial(c unicode.SpecialCase) func(s string) string
ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their lower case using the case mapping specified by c.
func ToTitleSpecial ¶
func ToTitleSpecial(c unicode.SpecialCase) func(s string) string
ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their Unicode title case, giving priority to the special casing rules.
func ToUpperSpecial ¶
func ToUpperSpecial(c unicode.SpecialCase) func(s string) string
ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their upper case using the case mapping specified by c.
func ToValidUTF8 ¶
ToValidUTF8 returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty.
func Trim ¶
Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.
func TrimFunc ¶
TrimFunc returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed.
func TrimLeft ¶
TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.
To remove a prefix, use TrimPrefix instead.
func TrimLeftFunc ¶
TrimLeftFunc returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed.
func TrimPrefix ¶
TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
func TrimRight ¶
TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.
func TrimRightFunc ¶
TrimRightFunc returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed.
func TrimSuffix ¶
TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.
Types ¶
This section is empty.