strings

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

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 New

func New(d *deps.Deps) *Namespace

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

func (*Namespace) Chomp

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

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

func (*Namespace) Contains

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

Contains reports whether substr is in s.

func (*Namespace) ContainsAny

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

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

func (*Namespace) CountRunes

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

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

func (*Namespace) CountWords

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

CountWords returns the approximate word count in s.

func (*Namespace) FindRE

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

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

HasPrefix tests whether the input s begins with prefix.

func (*Namespace) HasSuffix

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

HasSuffix tests whether the input s begins with suffix.

func (*Namespace) Replace

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

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

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

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

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

func (*Namespace) Substr

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

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

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

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

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

func (ns *Namespace) TrimPrefix(s, prefix 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) TrimSuffix

func (ns *Namespace) TrimSuffix(s, suffix 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

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

Jump to

Keyboard shortcuts

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