String

package
v0.0.0-...-52bf310 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 5 Imported by: 0

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

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 New

func New(s string) String

New return a new instance of the String type

func (String) Contains

func (self String) Contains(substr string) bool

Contains reports whether substr is within self

func (String) ContainsAny

func (self String) ContainsAny(chars string) bool

ContainsAny reports whether any character in chars is within self

func (String) ContainsFunc

func (self String) ContainsFunc(f func(rune) bool) bool

ContainsFunc reports if any character c in self satisfy f(c)

func (String) ContainsRune

func (self String) ContainsRune(r rune) bool

ContainsRune reports whether character r is within self

func (String) Count

func (self String) Count(substr string) int

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

func (self String) Cut(sep string) (before, after String, found bool)

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

func (self String) CutPrefix(prefix string) (after String, found bool)

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

func (self String) CutSuffix(suffix string) (before String, found bool)

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

func (self String) EqualFold(t string) bool

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

func (self String) Fields() Slice.Slice[String]

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

func (self String) FieldsFunc(f func(rune) bool) Slice.Slice[String]

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

func (self String) FieldsFuncSeq(f func(rune) bool) iter.Seq[String]

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

func (self String) FieldsSeq() iter.Seq[String]

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) HasPrefix

func (self String) HasPrefix(prefix string) bool

HasPrefix reports if self starts with prefix

func (String) HasSuffix

func (self String) HasSuffix(suffix string) bool

HasSuffix reports if self ends with suffix

func (String) Index

func (self String) Index(substr string) int

Index returns the index of the first instance of substr in self, or -1 if substr is not present in self.

func (String) IndexAny

func (self String) IndexAny(chars string) int

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

func (self String) IndexByte(c byte) int

IndexByte returns the index of the first instance of c in self, or -1 if c is not present in self.

func (String) IndexFunc

func (self String) IndexFunc(f func(rune) bool) int

IndexFunc returns the index into self of the first character satisfying f(c), or -1 if none do.

func (String) IndexRune

func (self String) IndexRune(r rune) int

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

func (self String) Join(elems Slice.Slice[any]) String

Join stringifies each element in elems and joins it using self Works similar to Python's str.join method

func (String) LastIndex

func (self String) LastIndex(substr string) int

LastIndex returns the index of the last instance of substr in self, or -1 if substr is not present in self.

func (String) LastIndexAny

func (self String) LastIndexAny(chars string) int

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

func (self String) LastIndexByte(c byte) int

LastIndexByte returns the index of the last instance of c in self, or -1 if c is not present in self.

func (String) LastIndexFunc

func (self String) LastIndexFunc(f func(rune) bool) int

LastIndexFunc returns the index into self of the last character satisfying f(c), or -1 if none do.

func (String) Length

func (self String) Length() int

Length return the length of underlying string

func (String) Lines

func (self String) Lines() iter.Seq[String]

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

func (self String) Map(mapping func(rune) rune) String

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

func (self String) Repeat(count int) String

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

func (self String) Replace(old, new string, n int) String

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

func (self String) ReplaceAll(old, new string) String

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

func (self String) Split(sep string) Slice.Slice[String]

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

func (self String) SplitAfter(sep string) Slice.Slice[String]

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

func (self String) SplitAfterN(sep string, n int) Slice.Slice[String]

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

func (self String) SplitAfterSeq(sep string) iter.Seq[String]

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

func (self String) SplitN(sep string, n int) Slice.Slice[String]

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

func (self String) SplitSeq(sep string) iter.Seq[String]

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) ToLower

func (self String) ToLower() String

ToLower returns the Lowercased version of self

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

func (self String) ToTitle() String

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) ToUpper

func (self String) ToUpper() String

ToUpper returns the Uppercased version of self

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

func (self String) ToValidUTF8(replacement string) String

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

func (self String) Trim(cutset string) String

Trim return the sliced version of self with all leading and trailing characters in cutset removed

func (String) TrimFunc

func (self String) TrimFunc(f func(rune) bool) String

TrimFunc return the sliced version of self with all leading and trailing characters satisfying f(c) removed

func (String) TrimLeft

func (self String) TrimLeft(cutset string) String

TrimLeft return the sliced version of self with all leading characters in cutset removed

func (String) TrimLeftFunc

func (self String) TrimLeftFunc(f func(rune) bool) String

TrimLeftFunc return the sliced version of self with all leading characters satisfying f(c) removed

func (String) TrimPrefix

func (self String) TrimPrefix(prefix string) String

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

func (self String) TrimRight(cutset string) String

TrimRight return the sliced version of self with all leading characters in cutset removed

func (String) TrimRightFunc

func (self String) TrimRightFunc(f func(rune) bool) String

TrimRightFunc return the sliced version of self with all leading characters satisfying f(c) removed

func (String) TrimSpace

func (self String) TrimSpace() String

TrimSpace return the sliced version of self with all leading and trailing whitespaces removed, as defined in Unicode

func (String) Value

func (self String) Value() string

Value return the original underlying string value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL