strings

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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 New

func New(d *deps.Deps) *Namespace

Creates a new strings Namespace

func (*Namespace) Ellipsis

func (ns *Namespace) Ellipsis(str string, length interface{}) string

Ellipsis

Returns a ellipsis (...) string from the given length.

Example: {{ ellipsis "hello verbis cms!" 11 } Returns: `hello verbis...`}

func (*Namespace) Find

func (ns *Namespace) Find(regex, str string) string

Find

Return the first (left most) match of the regular expression in the input string

Example: {{ regexFind "verbis.?" "verbiscms" }} Returns `verbisc`

func (*Namespace) FindAll

func (ns *Namespace) FindAll(regex, str string, i int) []string

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

func (ns *Namespace) Match(regex, str string) bool

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

func (ns *Namespace) QuoteMeta(str string) string

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

func (ns *Namespace) Replace(old, new, src string) string

Replace

Returns new replaced string with all matches.

Example: {{ replace " " "-" "hello verbis cms" }} Returns: `hello-verbis-cms`

func (*Namespace) ReplaceAll

func (ns *Namespace) ReplaceAll(regex, str, repl string) string

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

func (ns *Namespace) ReplaceAllLiteral(regex, str, repl string) string

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

func (ns *Namespace) Split(regex, str string, i int) []string

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]`

func (*Namespace) Substr

func (ns *Namespace) Substr(str string, start, end interface{}) string

Substr

Returns new substring of the given string.

Example: {{ substr "hello verbis" 0 5 }} Returns: `hello`

func (*Namespace) Trunc

func (ns *Namespace) Trunc(str string, a interface{}) string

Trunc

Returns a truncated string with no suffix, negatives apply.

Example: {{ trunc "hello verbis" -5 }} Returns: `verbis`

Jump to

Keyboard shortcuts

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