strfn

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package strfn provides curried functional versions of the functions provided by the "strings" package so they can be more easily used within "enum" and "maps" functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(b string) func(a string) int

Compare returns an integer comparing two strings lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func Contains

func Contains(substr string) func(s string) bool

Contains reports whether substr is within s.

func ContainsAny

func ContainsAny(chars string) func(s string) bool

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

func ContainsRune

func ContainsRune(r rune) func(s string) bool

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

func Count

func Count(substr string) func(s string) int

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

func EqualFold

func EqualFold(t string) func(s string) bool

EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.

func FieldsFunc

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

FieldsFunc splits the string 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 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 First

func First(s string) string

First returns the first character (as a string) of the provided string or "".

func HasPrefix

func HasPrefix(prefix string) func(s string) bool

HasPrefix tests whether the string s begins with prefix.

func HasSuffix

func HasSuffix(suffix string) func(s string) bool

HasSuffix tests whether the string s ends with suffix.

func Index

func Index(substr string) func(s string) 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(chars string) func(s 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(c byte) func(s string) 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(f func(rune) bool) func(s string) 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(r rune) func(s string) int

IndexRune returns the index of the first instance of the Unicode code point 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 Join

func Join(sep string) func(elems []string) string

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

func Last

func Last(s string) string

Last returns the last character (as a string) of the provided string or "".

func LastIndex

func LastIndex(substr string) func(s string) 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(chars string) func(s string) 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 LastIndexByte

func LastIndexByte(c byte) func(s string) int

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

func LastIndexFunc

func LastIndexFunc(f func(rune) bool) func(s string) int

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

func Length

func Length(s string) int

Length returns the length of the provided string.

func Map

func Map(mapping func(rune) rune) func(s string) string

Map returns a copy of the string s 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 Repeat

func Repeat(count int) func(s string) string

Repeat returns a new string consisting of count copies of the string s.

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

func Replace

func Replace(old, new string, n int) func(s string) string

Replace returns a copy of the string s 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 ReplaceAll

func ReplaceAll(old, new string) func(s string) string

ReplaceAll returns a copy of the string s 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.

func RunesWithIndex

func RunesWithIndex(s string, f func(i int, value rune))

RunesWithIndex iterates over a string and calls the provided function with its index and rune. This is because I couldn't figure out how to make WithIndex work with a string and its runes.

func Split

func Split(sep string) func(s string) []string

Split slices s into all substrings separated by sep and returns a slice of the substrings 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.

func SplitAfter

func SplitAfter(sep string) func(s string) []string

SplitAfter slices s into all substrings after each instance of sep and returns a slice of those substrings.

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(sep string, n int) func(s string) []string

SplitAfterN slices s 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 s and sep (for example, empty strings) are handled as described in the documentation for SplitAfter.

func SplitN

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

SplitN slices s 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 s and sep (for example, empty strings) are handled as described in the documentation for Split.

func Substr

func Substr(start, end int) func(string) string

Substr returns a function that returns a substring from [start, end) (just like s[start:end]).

If start >= len(s), "" is returned. If end >= len(s), s[start:] is returned.

func ToLowerSpecial

func ToLowerSpecial(c unicode.SpecialCase) func(s string) string

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

func ToTitleSpecial

func ToTitleSpecial(c unicode.SpecialCase) func(s string) string

ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their Unicode title case, giving priority to the special casing rules.

func ToUpperSpecial

func ToUpperSpecial(c unicode.SpecialCase) func(s string) string

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

func ToValidUTF8

func ToValidUTF8(replacement string) func(s string) string

ToValidUTF8 returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty.

func Trim

func Trim(cutset string) func(s string) string

Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.

func TrimFunc

func TrimFunc(f func(rune) bool) func(s string) string

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

func TrimLeft

func TrimLeft(cutset string) func(s string) string

TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.

To remove a prefix, use TrimPrefix instead.

func TrimLeftFunc

func TrimLeftFunc(f func(rune) bool) func(s string) string

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

func TrimPrefix

func TrimPrefix(prefix string) func(s string) string

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

func TrimRight

func TrimRight(cutset string) func(s string) string

TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

func TrimRightFunc

func TrimRightFunc(f func(rune) bool) func(s string) string

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

func TrimSuffix

func TrimSuffix(suffix string) func(s string) string

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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