Documentation
¶
Index ¶
- Variables
- func Append[T ~[]S, S E](arr T, v S) (T, int)
- func Contains[T ~[]S, S E](s, sub T) bool
- func ContainsArray[T ~[]S, S E](s T, e S) bool
- func ContainsRune(s []rune, r rune) bool
- func CopyAt[T ~[]S, S E](s, t T, i int) T
- func Count[T ~[]S, S E](s, sub T) int
- func CountArray[T ~[]S, S E](ss T, s S) int
- func Cut[T ~[]S, S E](s, sep T) (before, after T, found bool)
- func Equal[T ~[]S, S E](a, b T) bool
- func EqualFoldRune(s, t []rune) bool
- func Fields[T ~[]S, S interface{ ... }](s T) []T
- func FieldsFunc[T ~[]S, S E](s T, f func(S) bool) []T
- func HasPrefix[T ~[]S, S E](s, prefix T) bool
- func HasSuffix[T ~[]S, S E](s, suffix T) bool
- func Index[T ~[]S, S E](s, sep T) int
- func IndexArray[T ~[]S, S E](s T, r S) int
- func IndexByteRune(s []rune, c byte) int
- func IndexFunc[T ~[]S, S E](s T, f func(S) bool) int
- func IndexRune(s []rune, r rune) int
- func InsertWith[T ~[]S, S E](s T, v S, fn func(a, b S) bool) T
- func IsSpace[S interface{ ... }](r S) bool
- func Join[T ~[]S, S E](s []T, sep T) T
- func LastIndex[T ~[]S, S E](s, sep T) int
- func LastIndexArray[T ~[]S, S E](s T, c S) int
- func LastIndexFunc[T ~[]S, S E](s T, f func(S) bool) int
- func MapRune(mapping func(rune) rune, s []rune) []rune
- func OverWithError[S any](s []S, err error) func(func(int, S) bool)
- func Read[T ~[]S, S E](arr T, offset int, limit int) T
- func RemoveWith[T ~[]S, S E](s T, fn func(a S) bool) T
- func Repeat[T ~[]S, S E](b T, count int) T
- func Replace[T ~[]S, S E](s, old, new T, n int) T
- func ReplaceAll[T ~[]S, S E](s, old, new T) T
- func Split[T ~[]S, S E](s, sep T) []T
- func SplitAfter[T ~[]S, S E](s, sep T) []T
- func SplitAfterN[T ~[]S, S E](s, sep T, n int) []T
- func SplitN[T ~[]S, S E](s, sep T, n int) []T
- func TitleRune(s []rune) []runedeprecated
- func ToLowerRune(s []rune) []rune
- func ToLowerSpecialRune(c unicode.SpecialCase, s []rune) []rune
- func ToTitleRune(s []rune) []rune
- func ToTitleSpecialRune(c unicode.SpecialCase, s []rune) []rune
- func ToUpperRune(s []rune) []rune
- func ToUpperSpecialRune(c unicode.SpecialCase, s []rune) []rune
- func ToValidUTF8Rune(s, replacement []rune) []rune
- func Trim[T ~[]S, S E](s T, cutset T) T
- func TrimFunc[T ~[]S, S E](s T, f func(S) bool) T
- func TrimLeft[T ~[]S, S E](s T, cutset T) T
- func TrimLeftFunc[T ~[]S, S E](s T, f func(S) bool) T
- func TrimPrefix[T ~[]S, S E](s, prefix T) T
- func TrimRight[T ~[]S, S E](s T, cutset T) T
- func TrimRightFunc[T ~[]S, S E](s T, f func(S) bool) T
- func TrimRightRune(s []rune, cutset string) []rune
- func TrimSpaceRune(s []rune) []rune
- func TrimSuffix[T ~[]S, S E](s, suffix T) T
- type Bytes
- type E
- type Runes
- func (r Runes) FindString(s string) int
- func (r Runes) Index(sub []rune) int
- func (r Runes) Map(mapping func(rune) rune) Runes
- func (r Runes) Read(offset int, limit int) Runes
- func (r Runes) ReadString(offset int, limit int) string
- func (r Runes) String() string
- func (r Runes) StringArray() []string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTooLarge is an error when number is too large than length ErrTooLarge = errors.New("slices.Array: number is too large than length") // ErrTooSmall is an error when number is too small than length ErrTooSmall = errors.New("slices.Array: number is too small than length") // ErrWrongIndex is an error when index is out of range ErrWrongIndex = errors.New("slices.Array: wrong index") )
Functions ¶
func ContainsArray ¶
ContainsArray 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 Array, Count returns 1 + the number of Unicode code points in s.
func CountArray ¶
CountArray counts the number of non-overlapping instances of c in s.
func Cut ¶
Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false.
func Equal ¶
Equal reports whether a and b are the same length and contain the same runes. A nil argument is equivalent to an empty slice.
func EqualFoldRune ¶
EqualFoldRune reports whether s and t, interpreted as UTF-8 []runes, are equal under simple Unicode case-folding, which is a more general form of case-insensitivity.
func Fields ¶
Fields splits the Array s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of subArrays of s or an empty slice if s contains only white space.
func FieldsFunc ¶
FieldsFunc splits the Array 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 Array 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 IndexArray ¶
IndexArray returns the index of the first instance of the runes point r, or -1 if rune is not present in s.
func IndexByteRune ¶
IndexByteRune 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 runes point r, or -1 if rune is not present in s.
func InsertWith ¶ added in v0.0.7
InsertWith inserts v into s at the first index where fn(a, b) is true.
func Join ¶
func Join[T ~[]S, S E](s []T, sep T) T
Join concatenates the elements of its first argument to create a single Array[S]. The separator Array[S] sep is placed between elements in the resulting Array[S].
func LastIndex ¶
LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
func LastIndexArray ¶
LastIndexArray 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 MapRune ¶
MapRune returns a copy of the []rune s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the []rune with no replacement.
func OverWithError ¶ added in v0.0.7
func Read ¶
Read returns a slice of the Array[S] s beginning at offset and length limit. If offset or limit is negative, it is treated as if it were zero.
func RemoveWith ¶ added in v0.0.7
RemoveWith removes the first index where fn(a, b) is true.
func Repeat ¶
Repeat returns a new Array[S] consisting of count copies of the Array[S] s.
It panics if count is negative or if the result of (len(s) * count) overflows.
func Replace ¶
Replace returns a copy of the Array s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the Array and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune Array. If n < 0, there is no limit on the number of replacements.
func ReplaceAll ¶
func ReplaceAll[T ~[]S, S E](s, old, new T) T
ReplaceAll returns a copy of the Array s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the Array and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune Array.
func Split ¶
func Split[T ~[]S, S E](s, sep T) []T
Split slices s into all sub arrays separated by sep and returns a slice of the sub arrays 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.
To split around the first instance of a separator, see Cut.
func SplitAfter ¶
func SplitAfter[T ~[]S, S E](s, sep T) []T
SplitAfter slices s into all sub arrays after each instance of sep and returns a slice of those sub arrays.
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 sub arrays after each instance of sep and returns a slice of those sub arrays.
The count determines the number of sub arrays to return:
n > 0: at most n sub arrays; the last subArray will be the unsplit remainder. n == 0: the result is nil (zero sub arrays) n < 0: all sub arrays
Edge cases for s and sep (for example, empty Arrays) are handled as described in the documentation for SplitAfter.
func SplitN ¶
SplitN slices s into sub arrays separated by sep and returns a slice of the sub arrays between those separators.
The count determines the number of sub arrays to return:
n > 0: at most n sub arrays; the last subArray will be the unsplit remainder. n == 0: the result is nil (zero sub arrays) n < 0: all sub arrays
Edge cases for s and sep (for example, empty Arrays) are handled as described in the documentation for Split.
To split around the first instance of a separator, see Cut.
func TitleRune
deprecated
func ToLowerRune ¶
ToLowerRune returns s with all Unicode letters mapped to their lower case.
func ToLowerSpecialRune ¶
func ToLowerSpecialRune(c unicode.SpecialCase, s []rune) []rune
ToLowerSpecialRune returns a copy of the []rune s with all Unicode letters mapped to their lower case using the case mapping specified by c.
func ToTitleRune ¶
ToTitleRune returns a copy of the []rune s with all Unicode letters mapped to their Unicode title case.
func ToTitleSpecialRune ¶
func ToTitleSpecialRune(c unicode.SpecialCase, s []rune) []rune
ToTitleSpecialRune returns a copy of the []rune s with all Unicode letters mapped to their Unicode title case, giving priority to the special casing rules.
func ToUpperRune ¶
ToUpperRune returns s with all Unicode letters mapped to their upper case.
func ToUpperSpecialRune ¶
func ToUpperSpecialRune(c unicode.SpecialCase, s []rune) []rune
ToUpperSpecialRune returns a copy of the []rune s with all Unicode letters mapped to their upper case using the case mapping specified by c.
func ToValidUTF8Rune ¶
ToValidUTF8Rune returns a copy of the []rune s with each run of invalid UTF-8 byte sequences replaced by the replacement []rune, which may be empty.
func Trim ¶
func Trim[T ~[]S, S E](s T, cutset T) T
Trim returns a sub slice of s by slicing off all leading and trailing UTF-8-encoded code points contained in cutset.
func TrimFunc ¶
TrimFunc returns a slice of the Array s with all leading and trailing Unicode code points c satisfying f(c) removed.
func TrimLeft ¶
func TrimLeft[T ~[]S, S E](s T, cutset T) T
TrimLeft returns a sub slice of s by slicing off all leading
func TrimLeftFunc ¶
TrimLeftFunc returns a slice of the Array s with all leading Unicode code points c satisfying f(c) removed.
func TrimPrefix ¶
func TrimPrefix[T ~[]S, S E](s, prefix T) T
TrimPrefix returns s without the provided leading prefix Array. If s doesn't start with prefix, s is returned unchanged.
func TrimRightFunc ¶
TrimRightFunc returns a slice of the Array s with all trailing Unicode code points c satisfying f(c) removed.
func TrimRightRune ¶
TrimRightRune returns a slice of the []rune s, with all trailing Unicode code points contained in cutset removed.
To remove a suffix, use TrimSuffix instead.
func TrimSpaceRune ¶
TrimSpaceRune returns a slice of the []rune s, with all leading and trailing white space removed, as defined by Unicode.
func TrimSuffix ¶
func TrimSuffix[T ~[]S, S E](s, suffix T) T
TrimSuffix returns s without the provided trailing suffix Array. If s doesn't end with suffix, s is returned unchanged.
Types ¶
type Bytes ¶
type Bytes []byte
func StringToBytes ¶
func (Bytes) FindString ¶
func (Bytes) StringArray ¶
type Runes ¶
type Runes []rune