std/strings
import "github.com/eugenioenko/goalchemy/std/strings"Package strings manipulates UTF-8 encoded strings.
Compare
Section titled “Compare”func Compare(a, b string) intCompare returns 0 if a == b, -1 if a < b, and +1 if a > b.
Contains
Section titled “Contains”func Contains(s, substr string) boolContains reports whether substr is within s.
ContainsAny
Section titled “ContainsAny”func ContainsAny(s, chars string) boolContainsAny reports whether any rune of chars is within s.
ContainsFunc
Section titled “ContainsFunc”func ContainsFunc(s string, f func(rune) bool) boolContainsFunc reports whether any rune of s satisfies f.
ContainsRune
Section titled “ContainsRune”func ContainsRune(s string, r rune) boolContainsRune reports whether r is within s.
func Count(s, substr string) intCount counts the non-overlapping instances of substr in s. An empty substr counts as one more than the number of runes in s.
func Cut(s, sep string) (before, after string, found bool)Cut slices s around the first instance of sep.
CutPrefix
Section titled “CutPrefix”func CutPrefix(s, prefix string) (after string, found bool)CutPrefix returns s without prefix and whether it was present.
CutSuffix
Section titled “CutSuffix”func CutSuffix(s, suffix string) (before string, found bool)CutSuffix returns s without suffix and whether it was present.
EqualFold
Section titled “EqualFold”func EqualFold(s, t string) boolEqualFold reports whether s and t are equal under simple Unicode case folding.
Fields
Section titled “Fields”func Fields(s string) []stringFields splits s around runs of white space.
FieldsFunc
Section titled “FieldsFunc”func FieldsFunc(s string, f func(rune) bool) []stringFieldsFunc splits s around runs of runes satisfying f.
HasPrefix
Section titled “HasPrefix”func HasPrefix(s, prefix string) boolHasPrefix reports whether s begins with prefix.
HasSuffix
Section titled “HasSuffix”func HasSuffix(s, suffix string) boolHasSuffix reports whether s ends with suffix.
func Index(s, substr string) intIndex returns the index of the first instance of substr in s, or -1.
IndexAny
Section titled “IndexAny”func IndexAny(s, chars string) intIndexAny returns the index of the first rune of s that is in chars, or -1.
IndexByte
Section titled “IndexByte”func IndexByte(s string, c byte) intIndexByte returns the index of the first instance of c in s, or -1.
IndexFunc
Section titled “IndexFunc”func IndexFunc(s string, f func(rune) bool) intIndexFunc returns the index of the first rune satisfying f, or -1.
IndexRune
Section titled “IndexRune”func IndexRune(s string, r rune) intIndexRune returns the index of the first instance of r in s, or -1. For utf8.RuneError it matches the first invalid byte or encoded U+FFFD.
func Join(elems []string, sep string) stringJoin concatenates elems with sep between them.
LastIndex
Section titled “LastIndex”func LastIndex(s, substr string) intLastIndex returns the index of the last instance of substr in s, or -1.
LastIndexAny
Section titled “LastIndexAny”func LastIndexAny(s, chars string) intLastIndexAny returns the index of the last rune of s that is in chars, or -1.
LastIndexByte
Section titled “LastIndexByte”func LastIndexByte(s string, c byte) intLastIndexByte returns the index of the last instance of c in s, or -1.
LastIndexFunc
Section titled “LastIndexFunc”func LastIndexFunc(s string, f func(rune) bool) intLastIndexFunc returns the index of the last rune satisfying f, or -1.
func Map(mapping func(rune) rune, s string) stringMap returns s with every rune mapped by mapping; runes mapped to a negative value are dropped. Invalid UTF-8 bytes are mapped as RuneError.
Repeat
Section titled “Repeat”func Repeat(s string, count int) stringRepeat returns count copies of s. It panics if count is negative.
Replace
Section titled “Replace”func Replace(s, old, new string, n int) stringReplace returns s with the first n non-overlapping instances of old replaced by new; n < 0 replaces all. An empty old matches before every rune and at the end.
ReplaceAll
Section titled “ReplaceAll”func ReplaceAll(s, old, new string) stringReplaceAll replaces every non-overlapping instance of old with new.
func Split(s, sep string) []stringSplit slices s into all substrings separated by sep.
SplitAfter
Section titled “SplitAfter”func SplitAfter(s, sep string) []stringSplitAfter slices s after each instance of sep.
SplitAfterN
Section titled “SplitAfterN”func SplitAfterN(s, sep string, n int) []stringSplitAfterN slices s after each instance of sep into at most n substrings.
SplitN
Section titled “SplitN”func SplitN(s, sep string, n int) []stringSplitN slices s into at most n substrings separated by sep; n < 0 means all.
ToLower
Section titled “ToLower”func ToLower(s string) stringToLower maps every rune of s to lower case.
ToTitle
Section titled “ToTitle”func ToTitle(s string) stringToTitle maps every rune of s to title case.
ToUpper
Section titled “ToUpper”func ToUpper(s string) stringToUpper maps every rune of s to upper case.
ToValidUTF8
Section titled “ToValidUTF8”func ToValidUTF8(s, replacement string) stringToValidUTF8 replaces each run of invalid UTF-8 bytes with replacement.
func Trim(s, cutset string) stringTrim removes leading and trailing runes contained in cutset.
TrimFunc
Section titled “TrimFunc”func TrimFunc(s string, f func(rune) bool) stringTrimFunc removes leading and trailing runes satisfying f.
TrimLeft
Section titled “TrimLeft”func TrimLeft(s, cutset string) stringTrimLeft removes leading runes contained in cutset.
TrimLeftFunc
Section titled “TrimLeftFunc”func TrimLeftFunc(s string, f func(rune) bool) stringTrimLeftFunc removes leading runes satisfying f.
TrimPrefix
Section titled “TrimPrefix”func TrimPrefix(s, prefix string) stringTrimPrefix removes prefix from s if present.
TrimRight
Section titled “TrimRight”func TrimRight(s, cutset string) stringTrimRight removes trailing runes contained in cutset.
TrimRightFunc
Section titled “TrimRightFunc”func TrimRightFunc(s string, f func(rune) bool) stringTrimRightFunc removes trailing runes satisfying f.
TrimSpace
Section titled “TrimSpace”func TrimSpace(s string) stringTrimSpace removes leading and trailing white space.
TrimSuffix
Section titled “TrimSuffix”func TrimSuffix(s, suffix string) stringTrimSuffix removes suffix from s if present.
type Builder
Section titled “type Builder”type Builder struct {}Builder builds a string with appends.
Builder.Cap
Section titled “Builder.Cap”func (b *Builder) Cap() intCap returns the capacity of the builder’s buffer.
Builder.Grow
Section titled “Builder.Grow”func (b *Builder) Grow(n int)Grow ensures space for another n bytes.
Builder.Len
Section titled “Builder.Len”func (b *Builder) Len() intLen returns the number of accumulated bytes.
Builder.Reset
Section titled “Builder.Reset”func (b *Builder) Reset()Reset empties the builder.
Builder.String
Section titled “Builder.String”func (b *Builder) String() stringString returns the accumulated string.
Builder.Write
Section titled “Builder.Write”func (b *Builder) Write(p []byte) (int, error)Write appends p and always returns len(p), nil.
Builder.WriteByte
Section titled “Builder.WriteByte”func (b *Builder) WriteByte(c byte) errorWriteByte appends c and always returns nil.
Builder.WriteRune
Section titled “Builder.WriteRune”func (b *Builder) WriteRune(r rune) (int, error)WriteRune appends the UTF-8 encoding of r and returns its length.
Builder.WriteString
Section titled “Builder.WriteString”func (b *Builder) WriteString(s string) (int, error)WriteString appends s and always returns len(s), nil.
type Reader
Section titled “type Reader”type Reader struct {}Reader implements io.Reader, io.ReaderAt, io.Seeker, io.WriterTo, io.ByteScanner and io.RuneScanner over a string. The zero value reads nothing.
NewReader
Section titled “NewReader”func NewReader(s string) *ReaderNewReader returns a Reader reading from s.
Reader.Len
Section titled “Reader.Len”func (r *Reader) Len() intLen returns the number of unread bytes.
Reader.Read
Section titled “Reader.Read”func (r *Reader) Read(b []byte) (n int, err error)Read implements io.Reader.
Reader.ReadAt
Section titled “Reader.ReadAt”func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)ReadAt implements io.ReaderAt. It does not change the read position.
Reader.ReadByte
Section titled “Reader.ReadByte”func (r *Reader) ReadByte() (byte, error)ReadByte implements io.ByteReader.
Reader.ReadRune
Section titled “Reader.ReadRune”func (r *Reader) ReadRune() (ch rune, size int, err error)ReadRune implements io.RuneReader.
Reader.Reset
Section titled “Reader.Reset”func (r *Reader) Reset(s string)Reset resets the Reader to read from s.
Reader.Seek
Section titled “Reader.Seek”func (r *Reader) Seek(offset int64, whence int) (int64, error)Seek implements io.Seeker. Seeking past the end is allowed.
Reader.Size
Section titled “Reader.Size”func (r *Reader) Size() int64Size returns the original length of the underlying string.
Reader.UnreadByte
Section titled “Reader.UnreadByte”func (r *Reader) UnreadByte() errorUnreadByte steps back one byte.
Reader.UnreadRune
Section titled “Reader.UnreadRune”func (r *Reader) UnreadRune() errorUnreadRune steps back over the rune returned by the previous ReadRune.
Reader.WriteTo
Section titled “Reader.WriteTo”func (r *Reader) WriteTo(w io.Writer) (n int64, err error)WriteTo implements io.WriterTo, writing the unread data to w.
type Replacer
Section titled “type Replacer”type Replacer struct {}Replacer replaces a list of strings with replacements.
NewReplacer
Section titled “NewReplacer”func NewReplacer(oldnew ...string) *ReplacerNewReplacer returns a Replacer from old, new string pairs. Replacements happen in target string order without overlapping; at the same position, earlier pairs win. It panics on an odd argument count.
Replacer.Replace
Section titled “Replacer.Replace”func (r *Replacer) Replace(s string) stringReplace returns s with all replacements performed.