runes

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTooLarge = errors.New("runes.Runes: number is too large than length")

Functions

func Contains

func Contains(s, substr []rune) bool

Contains reports whether substr is within s.

func ContainsAny

func ContainsAny(s []rune, chars string) bool

ContainsAny reports whether any Unicode code points in chars are within s.

func ContainsRune

func ContainsRune(s []rune, r rune) bool

ContainsRune reports whether the Unicode code point r is within s.

func Count

func Count(s, substr []rune) int

Count counts the number of non-overlapping instances of substr in s. If substr is an empty []rune, Count returns 1 + the number of Unicode code points in s.

func Cut

func Cut(s, sep []rune) (before, after []rune, found bool)

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

func Equal(a, b []rune) bool

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 EqualFold

func EqualFold(s, t []rune) bool

EqualFold 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

func Fields(s []rune) [][]rune

Fields splits the []rune s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of sub[]runes of s or an empty slice if s contains only white space.

func FieldsFunc

func FieldsFunc(s []rune, f func(rune) bool) [][]rune

FieldsFunc splits the []rune 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 []rune 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 HasPrefix

func HasPrefix(s, prefix []rune) bool

HasPrefix tests whether the []rune s begins with prefix.

func HasSuffix

func HasSuffix(s, suffix []rune) bool

HasSuffix tests whether the []rune s ends with suffix.

func Index

func Index(s, sep []rune) int

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

func IndexAny

func IndexAny(s []rune, chars string) int

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

func IndexByte(s []rune, c byte) int

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

func IndexFunc

func IndexFunc(s []rune, f func(rune) bool) int

IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.

func IndexRune

func IndexRune(s []rune, r rune) int

IndexRune returns the index of the first instance of the runes point r, or -1 if rune is not present in s.

func Join

func Join(s [][]rune, sep []rune) []rune

Join concatenates the elements of its first argument to create a single []rune. The separator []rune sep is placed between elements in the resulting []rune.

func LastIndex

func LastIndex(s, sep []rune) int

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

func LastIndexAny

func LastIndexAny(s, chars []rune) int

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 LastIndexFunc

func LastIndexFunc(s []rune, f func(rune) bool) int

LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.

func LastIndexRune

func LastIndexRune(s []rune, c rune) int

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

func Map

func Map(mapping func(rune) rune, s []rune) []rune

Map 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 ReadString

func ReadString(runs []rune, offset int, limit int) (string, error)

func Repeat

func Repeat(b []rune, count int) []rune

Repeat returns a new []rune consisting of count copies of the []rune s.

It panics if count is negative or if the result of (len(s) * count) overflows.

func Replace

func Replace(s, old, new []rune, n int) []rune

Replace returns a copy of the []rune s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the []rune and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune []rune. If n < 0, there is no limit on the number of replacements.

func ReplaceAll

func ReplaceAll(s, old, new []rune) []rune

ReplaceAll returns a copy of the []rune s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the []rune and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune []rune.

func Split

func Split(s, sep []rune) [][]rune

Split slices s into all sub[]runes separated by sep and returns a slice of the sub[]runes 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(s, sep []rune) [][]rune

SplitAfter slices s into all sub[]runes after each instance of sep and returns a slice of those sub[]runes.

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

func SplitAfterN(s, sep []rune, n int) [][]rune

SplitAfterN slices s into sub[]runes after each instance of sep and returns a slice of those sub[]runes.

The count determines the number of sub[]runes to return:

n > 0: at most n sub[]runes; the last sub[]rune will be the unsplit remainder.
n == 0: the result is nil (zero sub[]runes)
n < 0: all sub[]runes

Edge cases for s and sep (for example, empty []runes) are handled as described in the documentation for SplitAfter.

func SplitN

func SplitN(s, sep []rune, n int) [][]rune

SplitN slices s into sub[]runes separated by sep and returns a slice of the sub[]runes between those separators.

The count determines the number of sub[]runes to return:

n > 0: at most n sub[]runes; the last sub[]rune will be the unsplit remainder.
n == 0: the result is nil (zero sub[]runes)
n < 0: all sub[]runes

Edge cases for s and sep (for example, empty []runes) are handled as described in the documentation for Split.

To split around the first instance of a separator, see Cut.

func Title deprecated

func Title(s []rune) []rune

Title returns a copy of the []rune s with all Unicode letters that begin words mapped to their Unicode title case.

Deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead.

func ToLower

func ToLower(s []rune) []rune

ToLower returns s with all Unicode letters mapped to their lower case.

func ToLowerSpecial

func ToLowerSpecial(c unicode.SpecialCase, s []rune) []rune

ToLowerSpecial returns a copy of the []rune s with all Unicode letters mapped to their lower case using the case mapping specified by c.

func ToTitle

func ToTitle(s []rune) []rune

ToTitle returns a copy of the []rune s with all Unicode letters mapped to their Unicode title case.

func ToTitleSpecial

func ToTitleSpecial(c unicode.SpecialCase, s []rune) []rune

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

func ToUpper(s []rune) []rune

ToUpper returns s with all Unicode letters mapped to their upper case.

func ToUpperSpecial

func ToUpperSpecial(c unicode.SpecialCase, s []rune) []rune

ToUpperSpecial returns a copy of the []rune s with all Unicode letters mapped to their upper case using the case mapping specified by c.

func ToValidUTF8

func ToValidUTF8(s, replacement []rune) []rune

ToValidUTF8 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(s []rune, cutset string) []rune

Trim returns a subslice of s by slicing off all leading and trailing UTF-8-encoded code points contained in cutset.

func TrimFunc

func TrimFunc(s []rune, f func(rune) bool) []rune

TrimFunc returns a slice of the []rune s with all leading and trailing Unicode code points c satisfying f(c) removed.

func TrimLeft

func TrimLeft(s []rune, cutset string) []rune

TrimLeft returns a subslice of s by slicing off all leading UTF-8-encoded code points contained in cutset.

func TrimLeftFunc

func TrimLeftFunc(s []rune, f func(rune) bool) []rune

TrimLeftFunc returns a slice of the []rune s with all leading Unicode code points c satisfying f(c) removed.

func TrimPrefix

func TrimPrefix(s, prefix []rune) []rune

TrimPrefix returns s without the provided leading prefix []rune. If s doesn't start with prefix, s is returned unchanged.

func TrimRight

func TrimRight(s []rune, cutset string) []rune

TrimRight 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 TrimRightFunc

func TrimRightFunc(s []rune, f func(rune) bool) []rune

TrimRightFunc returns a slice of the []rune s with all trailing Unicode code points c satisfying f(c) removed.

func TrimSpace

func TrimSpace(s []rune) []rune

TrimSpace returns a slice of the []rune s, with all leading and trailing white space removed, as defined by Unicode.

func TrimSuffix

func TrimSuffix(s, suffix []rune) []rune

TrimSuffix returns s without the provided trailing suffix []rune. If s doesn't end with suffix, s is returned unchanged.

Types

type Runes

type Runes []rune

func (Runes) FindString

func (r Runes) FindString(s string) int

func (Runes) Index

func (r Runes) Index(sub []rune) int

func (Runes) MustReadString

func (r Runes) MustReadString(offset int, limit int) string

func (Runes) ReadString

func (r Runes) ReadString(offset int, limit int) (string, error)

func (Runes) StringArray

func (r Runes) StringArray() []string

Jump to

Keyboard shortcuts

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