Documentation ¶
Overview ¶
Package strings provides template functions for manipulating strings.
Index ¶
- type Namespace
- func (ns *Namespace) Chomp(s any) (any, error)
- func (ns *Namespace) Contains(s, substr any) (bool, error)
- func (ns *Namespace) ContainsAny(s, chars any) (bool, error)
- func (ns *Namespace) ContainsNonSpace(s any) bool
- func (ns *Namespace) Count(substr, s any) (int, error)
- func (ns *Namespace) CountRunes(s any) (int, error)
- func (ns *Namespace) CountWords(s any) (int, error)
- func (ns *Namespace) FindRE(expr string, content any, limit ...any) ([]string, error)
- func (ns *Namespace) FindRESubmatch(expr string, content any, limit ...any) ([][]string, error)
- func (ns *Namespace) FirstUpper(s any) (string, error)
- func (ns *Namespace) HasPrefix(s, prefix any) (bool, error)
- func (ns *Namespace) HasSuffix(s, suffix any) (bool, error)
- func (ns *Namespace) Repeat(n, s any) (string, error)
- func (ns *Namespace) Replace(s, old, new any, limit ...any) (string, error)
- func (ns *Namespace) ReplaceRE(pattern, repl, s any, n ...any) (_ string, err error)
- func (ns *Namespace) RuneCount(s any) (int, error)
- func (ns *Namespace) SliceString(a any, startEnd ...any) (string, error)
- func (ns *Namespace) Split(a any, delimiter string) ([]string, error)
- func (ns *Namespace) Substr(a any, nums ...any) (string, error)
- func (ns *Namespace) Title(s any) (string, error)
- func (ns *Namespace) ToLower(s any) (string, error)
- func (ns *Namespace) ToUpper(s any) (string, error)
- func (ns *Namespace) Trim(s, cutset any) (string, error)
- func (ns *Namespace) TrimLeft(cutset, s any) (string, error)
- func (ns *Namespace) TrimPrefix(prefix, s any) (string, error)
- func (ns *Namespace) TrimRight(cutset, s any) (string, error)
- func (ns *Namespace) TrimSuffix(suffix, s any) (string, error)
- func (ns *Namespace) Truncate(s any, options ...any) (template.HTML, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace provides template functions for the "strings" namespace. Most functions mimic the Go stdlib, but the order of the parameters may be different to ease their use in the Go template system.
func (*Namespace) ContainsAny ¶
ContainsAny reports whether any Unicode code points in chars are within s.
func (*Namespace) ContainsNonSpace ¶
ContainsNonSpace reports whether s contains any non-space characters as defined by Unicode's White Space property, <docsmeta>{"newIn": "0.111.0" }</docsmeta>
func (*Namespace) Count ¶
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 (*Namespace) CountRunes ¶
CountRunes returns the number of runes in s, excluding whitespace.
func (*Namespace) CountWords ¶
CountWords returns the approximate word count in s.
func (*Namespace) FindRE ¶
FindRE returns a list of strings that match the regular expression. By default all matches will be included. The number of matches can be limited with an optional third parameter.
func (*Namespace) FindRESubmatch ¶
FindRESubmatch returns a slice of all successive matches of the regular expression in content. Each element is a slice of strings holding the text of the leftmost match of the regular expression and the matches, if any, of its subexpressions.
By default all matches will be included. The number of matches can be limited with the optional limit parameter. A return value of nil indicates no match.
func (*Namespace) FirstUpper ¶
FirstUpper converts s making the first character upper case.
func (*Namespace) Replace ¶
Replace returns a copy of the string s with all occurrences of old replaced with new. The number of replacements can be limited with an optional fourth parameter.
func (*Namespace) ReplaceRE ¶
ReplaceRE returns a copy of s, replacing all matches of the regular expression pattern with the replacement text repl. The number of replacements can be limited with an optional fourth parameter.
func (*Namespace) SliceString ¶
SliceString slices a string by specifying a half-open range with two indices, start and end. 1 and 4 creates a slice including elements 1 through 3. The end index can be omitted, it defaults to the string's length.
func (*Namespace) Substr ¶
Substr extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.
It normally takes two parameters: start and length. It can also take one parameter: start, i.e. length is omitted, in which case the substring starting from start until the end of the string will be returned.
To extract characters from the end of the string, use a negative start number.
In addition, borrowing from the extended behavior described at http://php.net/substr, if length is given and is negative, then that many characters will be omitted from the end of string.
func (*Namespace) Title ¶
Title returns a copy of the input s with all Unicode letters that begin words mapped to their title case.
func (*Namespace) ToLower ¶
ToLower returns a copy of the input s with all Unicode letters mapped to their lower case.
func (*Namespace) ToUpper ¶
ToUpper returns a copy of the input s with all Unicode letters mapped to their upper case.
func (*Namespace) Trim ¶
Trim returns converts the strings s removing all leading and trailing characters defined contained.
func (*Namespace) TrimLeft ¶
TrimLeft returns a slice of the string s with all leading characters contained in cutset removed.
func (*Namespace) TrimPrefix ¶
TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
func (*Namespace) TrimRight ¶
TrimRight returns a slice of the string s with all trailing characters contained in cutset removed.
func (*Namespace) TrimSuffix ¶
TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.