Documentation ¶
Overview ¶
Package text contains a single Text type with functions from caps and strings as methods.
All methods return new values and do not mutate the existing Text.
Index ¶
- type Text
- func (t Text) Append(elems ...Text) Text
- func (t Text) AppendRune(elems ...rune) Text
- func (t Text) Clone() Text
- func (t Text) Compare(other string) int
- func (t Text) Contains(substr string) bool
- func (t Text) ContainsAny(chars string) bool
- func (t Text) ContainsRune(r rune) bool
- func (t Text) Count(substr string) int
- func (t Text) Cut(sep string) (before, after Text, found bool)
- func (t Text) EqualFold(v string) bool
- func (t Text) Fields() []Text
- func (t Text) FieldsFunc(f func(rune) bool) []Text
- func (t Text) HasPrefix(prefix string) bool
- func (t Text) HasSuffix(suffix string) bool
- func (t Text) Index(substr string) int
- func (t Text) IndexByte(c byte) int
- func (t Text) IndexFunc(fn func(r rune) bool) int
- func (t Text) IndexRune(r rune) int
- func (t Text) LastIndex(substr string) int
- func (t Text) LastIndexAny(chars string) int
- func (t Text) LastIndexByte(b byte) int
- func (t Text) LastIndexFunc(f func(rune) bool) int
- func (t Text) LastIndexRune(r rune) int
- func (t Text) Map(f func(r rune) rune) Text
- func (t Text) Repeat(count int) Text
- func (t Text) Replace(old, new string, n int) Text
- func (t Text) ReplaceAll(old string, new string) Text
- func (t Text) Split(sep string) []Text
- func (t Text) SplitAfter(sep string) []Text
- func (t Text) SplitAfterN(sep string, n int) []Text
- func (t Text) SplitN(sep string, n int) []Text
- func (t Text) String() string
- func (t Text) Title() Text
- func (t Text) ToCamel(opts ...caps.Opts) Text
- func (t Text) ToDelimited(delimiter rune, lowercase bool, opts ...caps.Opts) Text
- func (t Text) ToDotNotation(opts ...caps.Opts) Text
- func (t Text) ToKebab(opts ...caps.Opts) Text
- func (t Text) ToLower() Text
- func (t Text) ToLowerCamel(opts ...caps.Opts) Text
- func (t Text) ToLowerSpecial(c unicode.SpecialCase) Text
- func (t Text) ToScreamingDotNotation(opts ...caps.Opts) Text
- func (t Text) ToScreamingKebab(opts ...caps.Opts) Text
- func (t Text) ToScreamingSnake(opts ...caps.Opts) Text
- func (t Text) ToSnake(opts ...caps.Opts) Text
- func (t Text) ToTitle(opts ...caps.Opts) Text
- func (t Text) ToUpper(caser ...token.Caser) Text
- func (t Text) ToUpperSpecial(c unicode.SpecialCase) Text
- func (t Text) ToValidUTF8(replacement string) Text
- func (t Text) Trim(cutset string) Text
- func (t Text) TrimLeft(cutset string) Text
- func (t Text) TrimLeftFunc(f func(r rune) bool) Text
- func (t Text) TrimPrefix(prefix string) Text
- func (t Text) TrimRight(cutset string) Text
- func (t Text) TrimRightFunc(f func(r rune) bool) Text
- func (t Text) TrimSpace() Text
- func (t Text) TrimSuffix(suffix string) Text
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Text ¶
type Text string
func (Text) AppendRune ¶
AppendRune append each rune in elem to a copy t and returns the result.
func (Text) Clone ¶
Clone returns a fresh copy of t. It guarantees to make a copy of t into a new allocation, which can be important when retaining only a small substring of a much larger string. Using Clone can help such programs use less memory. Of course, since using Clone makes a copy, overuse of Clone can make programs use more memory. Clone should typically be used only rarely, and only when profiling indicates that it is needed. For strings of length zero the string "" will be returned and no allocation is made.
func (Text) Compare ¶
Compare returns an integer comparing two Texts lexicographically. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
Compare is included only for symmetry with package bytes. It is usually clearer and always faster to use the built-in string comparison operators ==, <, >, and so on.
func (Text) ContainsAny ¶
ContainsAny reports whether any Unicode code points in chars are within t.
func (Text) ContainsRune ¶
ContainsRune reports whether the Unicode code point r is within t.
func (Text) Cut ¶
Cut slices t around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in t. If sep does not appear in t, cut returns t, "", false.
func (Text) EqualFold ¶
EqualFold reports whether t and v, interpreted as UTF-8 strings, are equal under simple Unicode case-folding, which is a more general form of case-insensitivity.
func (Text) Fields ¶
Fields splits the Text t around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of t or an empty slice if t contains only white space.
func (Text) FieldsFunc ¶
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 (Text) Index ¶
Index returns the index of the first instance of substr in t, or -1 if substr is not present in t.
func (Text) IndexByte ¶
IndexByte returns the index of the first instance of c in t, or -1 if c is not present in t.
func (Text) IndexFunc ¶
IndexRune returns the index of the first instance of the Unicode code point r, or -1 if rune is not present in t. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence.
func (Text) IndexRune ¶
IndexRune returns the index of the first instance of the Unicode code point r, or -1 if rune is not present in t. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence.
func (Text) LastIndex ¶
LastIndex returns the index of the last instance of substr in t, or -1 if substr is not present in t.
func (Text) LastIndexAny ¶
LastIndexAny returns the index of the last instance of any Unicode code point from chars in t, or -1 if no Unicode code point from chars is present in t.
func (Text) LastIndexByte ¶
LastIndexByte returns the index of the last instance of c in t, or -1 if c is not present in t.
func (Text) LastIndexFunc ¶
LastIndexFunc returns the index into t of the last Unicode code point satisfying f(c), or -1 if none do.
func (Text) LastIndexRune ¶
LastIndexByte returns the index of the last instance of r in t, or -1 if r is not present in t.
func (Text) Map ¶
Map returns a copy of the Text t 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 (Text) Repeat ¶
Repeat returns a new Text consisting of count copies of the Text t.
It panics if count is negative or if the result of (len(t) * count) overflows.
func (Text) Replace ¶
Replace returns a copy of the Text t 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 (Text) ReplaceAll ¶
ReplaceAll returns a copy of the Text t 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 (Text) Split ¶
Split slices t into all substrings separated by sep and returns a slice of the substrings between those separators.
If t does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is t.
If sep is empty, Split splits after each UTF-8 sequence. If both t and sep are empty, Split returns an empty slice.
func (Text) SplitAfter ¶
SplitAfter slices t into all substrings after each instance of sep and returns a slice of those substrings.
If t does not contain sep and sep is not empty, SplitAfter returns a slice of length 1 whose only element is t.
If sep is empty, SplitAfter splits after each UTF-8 sequence. If both t and sep are empty, SplitAfter returns an empty slice.
It is equivalent to SplitAfterN with a count of -1.
func (Text) SplitAfterN ¶
SplitAfterN slices t 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 t and sep (for example, empty strings) are handled as described in the documentation for SplitAfter.
func (Text) SplitN ¶
SplitN slices t 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 t 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 (Text) Title ¶
Title returns a copy of the Text t with all Unicode letters that begin words mapped to their title case.
func (Text) ToCamel ¶
ToCamel transforms the case of the Text t into Camel Case (e.g. AnExampleString) using either the provided Converter or the DefaultConverter otherwise.
The default Converter detects case so that "AN_EXAMPLE_STRING" becomes "AnExampleString". It also has a configurable set of replacements, such that "some_json" becomes "SomeJSON" so long as opts.ReplacementStyle is set to ReplaceStyleScreaming. A ReplaceStyle of ReplaceStyleCamel would result in "SomeJson".
func (Text) ToDelimited ¶
ToDelimited transforms the case of t into Text separated by delimiter, using either the provided Converter or the DefaultConverter otherwise.
If lowercase is false, the output will be all uppercase.
func (Text) ToDotNotation ¶
ToDotNotation transforms the case of the Text t into Lower Dot Notation Case (e.g. an.example.string) using either the provided Converter or the DefaultConverter otherwise.
func (Text) ToKebab ¶
ToKebab transforms the case of Text t into Lower Kebab Case (e.g. an-example-string) using either the provided Converter or the DefaultConverter otherwise.
func (Text) ToLowerCamel ¶
ToLowerCamel transforms the case of the Text t into Lower Camel Case (e.g. anExampleString) using either the provided Converter or the DefaultConverter otherwise.
The default Converter detects case so that "AN_EXAMPLE_STRING" becomes "anExampleString". It also has a configurable set of replacements, such that "some_json" becomes "someJSON" so long as opts.ReplacementStyle is set to ReplaceStyleScreaming. A ReplaceStyle of ReplaceStyleCamel would result in "someJson".
func (Text) ToLowerSpecial ¶
func (t Text) ToLowerSpecial(c unicode.SpecialCase) Text
ToLowerSpecial returns a copy of the Text t with all Unicode letters mapped to their lower case using the case mapping specified by c.
func (Text) ToScreamingDotNotation ¶
ToScreamingKebab transforms the case of the Text t into Screaming Dot Notation Case (e.g. AN.EXAMPLE.STRING) using either the provided Converter or the DefaultConverter otherwise.
func (Text) ToScreamingKebab ¶
ToScreamingKebab transforms the case of the Text t into Screaming Kebab Snake (e.g. AN-EXAMPLE-STRING) using either the provided Converter or the DefaultConverter otherwise.
func (Text) ToScreamingSnake ¶
ToScreamingSnake transforms the case of the Text t into Screaming Snake Case (e.g. AN_EXAMPLE_STRING) using either the provided Converter or the DefaultConverter otherwise.
func (Text) ToSnake ¶
ToSnake transforms the case of the Text t into Lower Snake Case (e.g. an_example_string) using either the provided Converter or the DefaultConverter otherwise.
func (Text) ToTitle ¶
ToTitle transforms the case of t into Title Case (e.g. An Example String) using either the provided Converter or the DefaultConverter otherwise.
func (Text) ToUpperSpecial ¶
func (t Text) ToUpperSpecial(c unicode.SpecialCase) Text
ToUpperSpecial returns a copy of the Text t with all Unicode letters mapped to their upper case using the case mapping specified by c.
func (Text) ToValidUTF8 ¶
ToValidUTF8 returns a copy of the Text t with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty.
func (Text) Trim ¶
Trim returns a slice of the Text t with all leading and trailing Unicode code points contained in cutset removed.
func (Text) TrimLeft ¶
TrimLeft returns a slice of the Text t with all leading Unicode code points contained in cutset removed.
To remove a prefix, use TrimPrefix instead.
func (Text) TrimLeftFunc ¶
TrimLeftFunc returns a slice of the Text t with all leading Unicode code points c satisfying f(c) removed.
func (Text) TrimPrefix ¶
TrimPrefix returns t without the provided leading prefix string. If t doesn't start with prefix, t is returned unchanged.
func (Text) TrimRight ¶
TrimRight returns a slice of the Te t, with all trailing Unicode code points contained in cutset removed.
To remove a suffix, use TrimSuffix instead.
func (Text) TrimRightFunc ¶
TrimRightFunc returns a slice of the Text t with all trailing Unicode code points c satisfying f(c) removed.
func (Text) TrimSpace ¶
TrimSpace returns a slice of the Text t, with all leading and trailing white space removed, as defined by Unicode.
func (Text) TrimSuffix ¶
TrimSuffix returns t without the provided trailing suffix string. If t doesn't end with suffix, t is returned unchanged.