hugo: Index | Files

package strings

import ""

Package strings provides template functions for manipulating strings.


Package Files

init.go regexp.go strings.go truncate.go

type Namespace Uses

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 New Uses

func New(d *deps.Deps) *Namespace

New returns a new instance of the strings-namespaced template functions.

func (*Namespace) Chomp Uses

func (ns *Namespace) Chomp(s interface{}) (interface{}, error)

Chomp returns a copy of s with all trailing newline characters removed.

func (*Namespace) Contains Uses

func (ns *Namespace) Contains(s, substr interface{}) (bool, error)

Contains reports whether substr is in s.

func (*Namespace) ContainsAny Uses

func (ns *Namespace) ContainsAny(s, chars interface{}) (bool, error)

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

func (*Namespace) CountRunes Uses

func (ns *Namespace) CountRunes(s interface{}) (int, error)

CountRunes returns the number of runes in s, excluding whitepace.

func (*Namespace) CountWords Uses

func (ns *Namespace) CountWords(s interface{}) (int, error)

CountWords returns the approximate word count in s.

func (*Namespace) FindRE Uses

func (ns *Namespace) FindRE(expr string, content interface{}, limit ...interface{}) ([]string, error)

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) FirstUpper Uses

func (ns *Namespace) FirstUpper(s interface{}) (string, error)

FirstUpper returns a string with the first character as upper case.

func (*Namespace) HasPrefix Uses

func (ns *Namespace) HasPrefix(s, prefix interface{}) (bool, error)

HasPrefix tests whether the input s begins with prefix.

func (*Namespace) HasSuffix Uses

func (ns *Namespace) HasSuffix(s, suffix interface{}) (bool, error)

HasSuffix tests whether the input s begins with suffix.

func (*Namespace) Repeat Uses

func (ns *Namespace) Repeat(n, s interface{}) (string, error)

Repeat returns a new string consisting of count copies of the string s.

func (*Namespace) Replace Uses

func (ns *Namespace) Replace(s, old, new interface{}) (string, error)

Replace returns a copy of the string s with all occurrences of old replaced with new.

func (*Namespace) ReplaceRE Uses

func (ns *Namespace) ReplaceRE(pattern, repl, s interface{}) (_ string, err error)

ReplaceRE returns a copy of s, replacing all matches of the regular expression pattern with the replacement text repl.

func (*Namespace) RuneCount Uses

func (ns *Namespace) RuneCount(s interface{}) (int, error)

RuneCount returns the number of runes in s.

func (*Namespace) SliceString Uses

func (ns *Namespace) SliceString(a interface{}, startEnd ...interface{}) (string, error)

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) Split Uses

func (ns *Namespace) Split(a interface{}, delimiter string) ([]string, error)

Split slices an input string into all substrings separated by delimiter.

func (*Namespace) Substr Uses

func (ns *Namespace) Substr(a interface{}, nums ...interface{}) (string, error)

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, if length is given and is negative, then that many characters will be omitted from the end of string.

func (*Namespace) Title Uses

func (ns *Namespace) Title(s interface{}) (string, error)

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

func (*Namespace) ToLower Uses

func (ns *Namespace) ToLower(s interface{}) (string, error)

ToLower returns a copy of the input s with all Unicode letters mapped to their lower case.

func (*Namespace) ToUpper Uses

func (ns *Namespace) ToUpper(s interface{}) (string, error)

ToUpper returns a copy of the input s with all Unicode letters mapped to their upper case.

func (*Namespace) Trim Uses

func (ns *Namespace) Trim(s, cutset interface{}) (string, error)

Trim returns a string with all leading and trailing characters defined contained in cutset removed.

func (*Namespace) TrimLeft Uses

func (ns *Namespace) TrimLeft(cutset, s interface{}) (string, error)

TrimLeft returns a slice of the string s with all leading characters contained in cutset removed.

func (*Namespace) TrimPrefix Uses

func (ns *Namespace) TrimPrefix(prefix, s interface{}) (string, error)

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

func (*Namespace) TrimRight Uses

func (ns *Namespace) TrimRight(cutset, s interface{}) (string, error)

TrimRight returns a slice of the string s with all trailing characters contained in cutset removed.

func (*Namespace) TrimSuffix Uses

func (ns *Namespace) TrimSuffix(suffix, s interface{}) (string, error)

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

func (*Namespace) Truncate Uses

func (ns *Namespace) Truncate(a interface{}, options ...interface{}) (template.HTML, error)

Truncate truncates a given string to the specified length.

Package strings imports 14 packages (graph) and is imported by 43 packages. Updated 2019-12-12. Refresh now. Tools for package owners.