Documentation ¶
Index ¶
- Constants
- type Namespace
- func (ns *Namespace) Ellipsis(str string, length interface{}) string
- func (ns *Namespace) Find(regex, str string) string
- func (ns *Namespace) FindAll(regex, str string, i int) []string
- func (ns *Namespace) Match(regex, str string) bool
- func (ns *Namespace) QuoteMeta(str string) string
- func (ns *Namespace) Replace(old, new, src string) string
- func (ns *Namespace) ReplaceAll(regex, str, repl string) string
- func (ns *Namespace) ReplaceAllLiteral(regex, str, repl string) string
- func (ns *Namespace) Split(regex, str string, i int) []string
- func (ns *Namespace) Substr(str string, start, end interface{}) string
- func (ns *Namespace) Trunc(str string, a interface{}) string
Constants ¶
const ( // The amount of characters to check before returning // an ellipsis. EllipsisCount = 4 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace defines the methods for slices to be used as template functions.
func (*Namespace) Ellipsis ¶
Ellipsis
Returns a ellipsis (...) string from the given length.
Example: {{ ellipsis "hello verbis cms!" 11 } Returns: `hello verbis...`}
func (*Namespace) Find ¶
Find
Return the first (left most) match of the regular expression in the input string
Example: {{ regexFind "verbis.?" "verbiscms" }} Returns `verbisc`
func (*Namespace) FindAll ¶
FindAll
Returns a slice of all matches of the regular expressions with the given input string.
Example: {{ regexFindAll "[1,3,5,7]" "123456789" -1 }} Returns: `[1 3 5 7]`
func (*Namespace) Match ¶
Match
Returns true if the input string contains and matches of the regular expression pattern.
Example: {{ regexMatch "^Verbis" "Verbis CMS" }} Returns `true`
func (*Namespace) QuoteMeta ¶
QuoteMeta
QuoteMeta returns a string that escapes all regular expression metacharacters inside the argument text; the returned string is a regular expression matching the literal text.
Example: {{ regexQuoteMeta "verbis+?" }} Returns: `verbis`
func (*Namespace) Replace ¶
Replace
Returns new replaced string with all matches.
Example: {{ replace " " "-" "hello verbis cms" }} Returns: `hello-verbis-cms`
func (*Namespace) ReplaceAll ¶
ReplaceAll
Returns a copy of the input string, replacing matches of the Regexp with the replacement string. Within the string replacement, $ signs are interpreted as in Expand, so for instance $1 represents the first submatch.
Example: {{ regexReplaceAll "a(x*)b" "-ab-axxb-" "\${1}W" }} Returns: `-W-xxW-`
func (*Namespace) ReplaceAllLiteral ¶
ReplaceAllLiteral
Returns a copy of the input string, replacing matches of the Regexp with the replacement string replacement. The replacement string is substituted directly, without using Expand.
Example: {{ regexReplaceAllLiteral "a(x*)b" "-ab-axxb-" "${1}" }} Returns: `-${1}-${1}-`
func (*Namespace) Split ¶
Split
Slices the input string into substrings separated by the expression and returns a slice of the substrings between expression matches. The last parameter `i` determines the number of substrings to return, where `-1` returns all matches.
Example: {{ regexSplit "b+" "verbis" -1 }} Returns: `[ver is]`