text

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: MIT Imports: 4 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Text

type Text string

func (Text) Append

func (t Text) Append(elems ...Text) Text

Append appends each elem to a copy of t and returns the result.

func (Text) AppendRune

func (t Text) AppendRune(elems ...rune) Text

AppendRune append each rune in elem to a copy t and returns the result.

func (Text) Clone

func (t Text) Clone() Text

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

func (t Text) Compare(other string) int

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

func (t Text) Contains(substr string) bool

Contains reports whether substr is within t.

func (Text) ContainsAny

func (t Text) ContainsAny(chars string) bool

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

func (Text) ContainsRune

func (t Text) ContainsRune(r rune) bool

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

func (Text) Count

func (t Text) Count(substr string) int

Count counts the number of non-overlapping instances of substr in t.

func (Text) Cut

func (t Text) Cut(sep string) (before, after Text, found bool)

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

func (t Text) EqualFold(v string) bool

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

func (t Text) Fields() []Text

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

func (t Text) FieldsFunc(f func(rune) bool) []Text

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

func (t Text) HasPrefix(prefix string) bool

HasPrefix tests whether the Text t begins with prefix.

func (Text) HasSuffix

func (t Text) HasSuffix(suffix string) bool

HasSuffix tests whether the Text t ends with suffix.

func (Text) Index

func (t Text) Index(substr string) int

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

func (Text) IndexByte

func (t Text) IndexByte(c byte) int

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

func (Text) IndexFunc

func (t Text) IndexFunc(fn func(r rune) bool) int

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

func (t Text) IndexRune(r rune) int

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

func (t Text) LastIndex(substr string) int

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

func (Text) LastIndexAny

func (t Text) LastIndexAny(chars string) int

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

func (t Text) LastIndexByte(b byte) int

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

func (Text) LastIndexFunc

func (t Text) LastIndexFunc(f func(rune) bool) int

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

func (Text) LastIndexRune

func (t Text) LastIndexRune(r rune) int

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

func (Text) Map

func (t Text) Map(f func(r rune) rune) Text

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

func (t Text) Repeat(count int) Text

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

func (t Text) Replace(old, new string, n int) Text

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

func (t Text) ReplaceAll(old string, new string) Text

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

func (t Text) Split(sep string) []Text

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

func (t Text) SplitAfter(sep string) []Text

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

func (t Text) SplitAfterN(sep string, n int) []Text

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

func (t Text) SplitN(sep string, n int) []Text

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

func (t Text) String() string

func (Text) Title

func (t Text) Title() Text

Title returns a copy of the Text t with all Unicode letters that begin words mapped to their title case.

func (Text) ToCamel

func (t Text) ToCamel(opts ...caps.Opts) Text

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

func (t Text) ToDelimited(delimiter rune, lowercase bool, opts ...caps.Opts) Text

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

func (t Text) ToDotNotation(opts ...caps.Opts) Text

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

func (t Text) ToKebab(opts ...caps.Opts) Text

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

func (t Text) ToLower() Text

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

func (Text) ToLowerCamel

func (t Text) ToLowerCamel(opts ...caps.Opts) Text

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

func (t Text) ToScreamingDotNotation(opts ...caps.Opts) Text

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

func (t Text) ToScreamingKebab(opts ...caps.Opts) Text

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

func (t Text) ToScreamingSnake(opts ...caps.Opts) Text

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

func (t Text) ToSnake(opts ...caps.Opts) Text

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

func (t Text) ToTitle(opts ...caps.Opts) Text

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

func (t Text) ToUpper(caser ...token.Caser) Text

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

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

func (t Text) ToValidUTF8(replacement string) Text

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

func (t Text) Trim(cutset string) Text

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

func (Text) TrimLeft

func (t Text) TrimLeft(cutset string) Text

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

func (t Text) TrimLeftFunc(f func(r rune) bool) Text

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

func (Text) TrimPrefix

func (t Text) TrimPrefix(prefix string) Text

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

func (Text) TrimRight

func (t Text) TrimRight(cutset string) Text

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

func (t Text) TrimRightFunc(f func(r rune) bool) Text

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

func (Text) TrimSpace

func (t Text) TrimSpace() Text

TrimSpace returns a slice of the Text t, with all leading and trailing white space removed, as defined by Unicode.

func (Text) TrimSuffix

func (t Text) TrimSuffix(suffix string) Text

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

Jump to

Keyboard shortcuts

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