Documentation
¶
Overview ¶
package String provides a custom String type with chainable methods with API similar to that of the standard library's strings package.
Index ¶
- type String
- func (self String) Contains(substr string) bool
- func (self String) ContainsAny(chars string) bool
- func (self String) ContainsFunc(f func(rune) bool) bool
- func (self String) ContainsRune(r rune) bool
- func (self String) Count(substr string) int
- func (self String) Cut(sep string) (before, after String, found bool)
- func (self String) CutPrefix(prefix string) (after String, found bool)
- func (self String) CutSuffix(suffix string) (before String, found bool)
- func (self String) EqualFold(t string) bool
- func (self String) Fields() Slice.Slice[String]
- func (self String) FieldsFunc(f func(rune) bool) Slice.Slice[String]
- func (self String) FieldsFuncSeq(f func(rune) bool) iter.Seq[String]
- func (self String) FieldsSeq() iter.Seq[String]
- func (self String) HasPrefix(prefix string) bool
- func (self String) HasSuffix(suffix string) bool
- func (self String) Index(substr string) int
- func (self String) IndexAny(chars string) int
- func (self String) IndexByte(c byte) int
- func (self String) IndexFunc(f func(rune) bool) int
- func (self String) IndexRune(r rune) int
- func (self String) Join(elems Slice.Slice[any]) String
- func (self String) LastIndex(substr string) int
- func (self String) LastIndexAny(chars string) int
- func (self String) LastIndexByte(c byte) int
- func (self String) LastIndexFunc(f func(rune) bool) int
- func (self String) Length() int
- func (self String) Lines() iter.Seq[String]
- func (self String) Map(mapping func(rune) rune) String
- func (self String) Repeat(count int) String
- func (self String) Replace(old, new string, n int) String
- func (self String) ReplaceAll(old, new string) String
- func (self String) Split(sep string) Slice.Slice[String]
- func (self String) SplitAfter(sep string) Slice.Slice[String]
- func (self String) SplitAfterN(sep string, n int) Slice.Slice[String]
- func (self String) SplitAfterSeq(sep string) iter.Seq[String]
- func (self String) SplitN(sep string, n int) Slice.Slice[String]
- func (self String) SplitSeq(sep string) iter.Seq[String]
- func (self String) ToLower() String
- func (self String) ToLowerSpecial(c unicode.SpecialCase) String
- func (self String) ToTitle() String
- func (self String) ToTitleSpecial(c unicode.SpecialCase) String
- func (self String) ToUpper() String
- func (self String) ToUpperSpecial(c unicode.SpecialCase) String
- func (self String) ToValidUTF8(replacement string) String
- func (self String) Trim(cutset string) String
- func (self String) TrimFunc(f func(rune) bool) String
- func (self String) TrimLeft(cutset string) String
- func (self String) TrimLeftFunc(f func(rune) bool) String
- func (self String) TrimPrefix(prefix string) String
- func (self String) TrimRight(cutset string) String
- func (self String) TrimRightFunc(f func(rune) bool) String
- func (self String) TrimSpace() String
- func (self String) Value() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type String ¶
type String string
type String is alias for native string
func (String) ContainsAny ¶
ContainsAny reports whether any character in chars is within self
func (String) ContainsFunc ¶
ContainsFunc reports if any character c in self satisfy f(c)
func (String) ContainsRune ¶
ContainsRune reports whether character r is within self
func (String) Count ¶
Count counts the number of non-overlapping instances of substr in self. If substr is an empty string, Count returns 1 + the number of characters in self.
func (String) Cut ¶
Cut slices self around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in self. If sep does not appear in self, Cut returns self, "", false.
func (String) CutPrefix ¶
CutPrefix returns self without the provided leading prefix string and reports whether it found the prefix. If self doesn't start with prefix, CutPrefix returns self, false. If prefix is the empty string, CutPrefix returns self, true.
func (String) CutSuffix ¶
CutSuffix returns self without the provided ending suffix string and reports whether it found the suffix. If self doesn't end with suffix, CutSuffix returns self, false. If suffix is the empty string, CutSuffix returns self, true.
func (String) EqualFold ¶
EqualFold reports whether self and t, interpreted as UTF-8 strings, are equal under simple Unicode case-folding, which is a more general form of case-insensitivity.
func (String) Fields ¶
Fields splits the String self around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of self or an empty slice if self contains only white space.
func (String) FieldsFunc ¶
FieldsFunc splits self at each run of character c satisfying f(c) and returns an array of Slices of String. If all characters in self 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 (String) FieldsFuncSeq ¶
FieldsFuncSeq returns an iterator over substrings of self split around runs of characters satisfying f(c). The iterator yields the same strings that would be returned by self.[FieldsFunc](), but without constructing the slice.
func (String) FieldsSeq ¶
FieldsSeq returns an iterator over substrings of self split around runs of whitespace characters, as defined by unicode.IsSpace. The iterator yields the same strings that would be returned by self.[Fields](), but without constructing the slice.
func (String) Index ¶
Index returns the index of the first instance of substr in self, or -1 if substr is not present in self.
func (String) IndexAny ¶
IndexAny returns the index of the first instance of any character from chars in self or -1 if no character from chars is present in self
func (String) IndexByte ¶
IndexByte returns the index of the first instance of c in self, or -1 if c is not present in self.
func (String) IndexFunc ¶
IndexFunc returns the index into self of the first character satisfying f(c), or -1 if none do.
func (String) IndexRune ¶
IndexRune returns the index of the first instance of the character 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 (String) Join ¶
Join stringifies each element in elems and joins it using self Works similar to Python's str.join method
func (String) LastIndex ¶
LastIndex returns the index of the last instance of substr in self, or -1 if substr is not present in self.
func (String) LastIndexAny ¶
LastIndexAny returns the index of the last instance of any character from chars in self, or -1 if no character from chars is present in self.
func (String) LastIndexByte ¶
LastIndexByte returns the index of the last instance of c in self, or -1 if c is not present in self.
func (String) LastIndexFunc ¶
LastIndexFunc returns the index into self of the last character satisfying f(c), or -1 if none do.
func (String) Lines ¶
Lines returns an iterator over the newline-terminated lines in the string self. The lines yielded by the iterator include their terminating newlines. If self is empty, the iterator yields no lines at all. If self does not end in a newline, the final yielded line will not end in a newline. It returns a single-use iterator.
func (String) Map ¶
Map returns a copy of the string self 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 (String) Repeat ¶
Repeat returns a new string consisting of count copies of the string self.
It panics if count is negative or if the result of (len(self) * count) overflows.
func (String) Replace ¶
Replace returns a copy of the string self 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 (String) ReplaceAll ¶
ReplaceAll returns a copy of the string self 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.
Equivalent to self.[Replace](old, new, -1)
func (String) Split ¶
Split slices self into all substrings separated by sep and returns a slice of the substrings between those separators.
If self does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is self.
If sep is empty, Split splits after each UTF-8 sequence. If both self 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 (String) SplitAfter ¶
SplitAfter slices self into all substrings after each instance of sep and returns a Slice of those substrings.
If self does not contain sep and sep is not empty, SplitAfter returns a Slice of length 1 whose only element is self.
If sep is empty, SplitAfter splits after each UTF-8 sequence. If both self and sep are empty, SplitAfter returns an empty Slice.
It is equivalent to [SplitAfterN] with a count of -1.
func (String) SplitAfterN ¶
SplitAfterN slices self 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 self and sep (for example, empty strings) are handled as described in the documentation for [SplitAfter].
func (String) SplitAfterSeq ¶
SplitAfterSeq returns an iterator over substrings of self split after each instance of sep. The iterator yields the same strings that would be returned by self.[SplitAfter](sep), but without constructing the slice. It returns a single-use iterator.
func (String) SplitN ¶
SplitN slices self 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 self and sep (for example, empty strings) are handled as described in the documentation for [Split].
To split around the first instance of a separator, see [Cut].
func (String) SplitSeq ¶
SplitSeq returns an iterator over all substrings of self separated by sep. The iterator yields the same strings that would be returned by self.[Split](sep), but without constructing the slice. It returns a single-use iterator.
func (String) ToLowerSpecial ¶
func (self String) ToLowerSpecial(c unicode.SpecialCase) String
ToLowerSpecial returns a copy of self with all Unicode letters mapped to their lower case using the case mapping specified by c.
func (String) ToTitle ¶
ToTitle returns a copy of self with all Unicode letters mapped to their Unicode title case.
func (String) ToTitleSpecial ¶
func (self String) ToTitleSpecial(c unicode.SpecialCase) String
ToTitleSpecial returns a copy of self with all Unicode letters mapped to their Unicode title case, giving priority to the special casing rules.
func (String) ToUpperSpecial ¶
func (self String) ToUpperSpecial(c unicode.SpecialCase) String
ToUpperSpecial returns a copy of self with all Unicode letters mapped to their upper case using the case mapping specified by c.
func (String) ToValidUTF8 ¶
ToValidUTF8 returns a copy of self with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty.
func (String) Trim ¶
Trim return the sliced version of self with all leading and trailing characters in cutset removed
func (String) TrimFunc ¶
TrimFunc return the sliced version of self with all leading and trailing characters satisfying f(c) removed
func (String) TrimLeft ¶
TrimLeft return the sliced version of self with all leading characters in cutset removed
func (String) TrimLeftFunc ¶
TrimLeftFunc return the sliced version of self with all leading characters satisfying f(c) removed
func (String) TrimPrefix ¶
TrimPrefix returns the sliced version of self with given prefix removed. If the prefix is not found in self, it is returned as it is
func (String) TrimRight ¶
TrimRight return the sliced version of self with all leading characters in cutset removed
func (String) TrimRightFunc ¶
TrimRightFunc return the sliced version of self with all leading characters satisfying f(c) removed