wdte: github.com/DeedleFake/wdte/std/strings Index | Files

package strings

import "github.com/DeedleFake/wdte/std/strings"

Package strings contains functions for dealing with strings.

Index

Package Files

format.go strings.go

Variables

var Scope = wdte.S().Map(map[wdte.ID]wdte.Func{
    "contains": wdte.GoFunc(Contains),
    "prefix":   wdte.GoFunc(Prefix),
    "suffix":   wdte.GoFunc(Suffix),
    "index":    wdte.GoFunc(Index),

    "upper":  wdte.GoFunc(Upper),
    "lower":  wdte.GoFunc(Lower),
    "repeat": wdte.GoFunc(Repeat),
    "split":  wdte.GoFunc(Split),
    "join":   wdte.GoFunc(Join),

    "read":   wdte.GoFunc(Read),
    "format": wdte.GoFunc(Format),
})

Scope is a scope containing the functions in this package.

func Contains Uses

func Contains(frame wdte.Frame, args ...wdte.Func) wdte.Func

Contains is a WDTE function with the following signatures:

contains outer inner
(contains inner) outer

Returns true if inner is a substring of outer.

func Format Uses

func Format(frame wdte.Frame, args ...wdte.Func) wdte.Func

Format is a WDTE function with the following signatures:

format tmpl ...

Format has some special rules for returning a partial function. For more information, see below.

This is the general-purpose string formatting function of the standard library, similar to Go's fmt.Sprintf(). Unlike fmt.Sprintf(), however, format uses a custom formatting specification. A format in the string tmpl is of the form {} with optional flags placed between them. Flags may be any combination of the following:

#<num> The zero-based index of the argument to be inserted.
       Subsequent formats will increment from here. In other
       words, '{2} {}' will yield the third and fourth
       arguments.
q      Place the value in quotes using strconv.Quote.
?      Mark the value with it's underlying Go type, such as
       wdte.Number(3).

Format's rules for returning a partial function are dependant on the value of the first argument. Specifically, if the first argument attempts to substitute in more arguments than were given, a partial function will be returned. For example,

format '' # Returns ''
format '{}' 3 # Returns '3'
format '{}' # Returns a partial function.
(format '{} {}' 3) 'example' # Returns '3 example'

Note that the total number of arguments required is the smallest number necessary to perform every substitution specified by the first argument. For example,

format '{3} {}'

will return a partial function that requires 5 arguments before it will return the formatted string.

TODO: Add more flags.

func Index Uses

func Index(frame wdte.Frame, args ...wdte.Func) wdte.Func

Index is a WDTE function with the following signatures:

index outer inner
(index inner) outer

It returns the index of the first character of the first instances of inner in outer. If inner is not a substring of outer, it returns -1.

func Join Uses

func Join(frame wdte.Frame, args ...wdte.Func) wdte.Func

Join is a WDTE function with the following signatures:

join strings sep
(join sep) strings

It returns a new string containing the strings in the provided array with sep inserted between each.

func Lower Uses

func Lower(frame wdte.Frame, args ...wdte.Func) wdte.Func

Lower is a WDTE function with the following signature:

lower s

It returns s converted to lowercase.

func Prefix Uses

func Prefix(frame wdte.Frame, args ...wdte.Func) wdte.Func

Prefix is a WDTE function with the following signatures:

prefix s p
(prefix p) s

Returns true if p is a prefix of s.

func Read Uses

func Read(frame wdte.Frame, args ...wdte.Func) wdte.Func

Read is a WDTE function with the following signature:

read s

Returns a reader which reads from the string s.

func Repeat Uses

func Repeat(frame wdte.Frame, args ...wdte.Func) wdte.Func

Repeat is a WDTE function with the following signatures:

repeat string times
(repeat string) times
repeat times string
(repeat times) string

It returns a new string containing the given string repeated the number of times specified.

func Split Uses

func Split(frame wdte.Frame, args ...wdte.Func) wdte.Func

Split is a WDTE function with the following signatures:

split string sep
(split sep) string
split string sep n
(split sep n) string
(split sep) string n

It splits the given string around instances of the given seperator string. If n is provided and is positive, the returned array of strings will have at most n elements. Note that this behavior differs from the Go standard library's string splitting function in that a zero value for n does not cause the function to return an empty array.

func Suffix Uses

func Suffix(frame wdte.Frame, args ...wdte.Func) wdte.Func

Suffix is a WDTE function with the following signatures:

suffix s p
(suffix p) s

Returns true if p is a suffix of s.

func Upper Uses

func Upper(frame wdte.Frame, args ...wdte.Func) wdte.Func

Upper is a WDTE function with the following signatures:

upper s

It returns s converted to uppercase.

Package strings imports 10 packages (graph) and is imported by 1 packages. Updated 2018-11-30. Refresh now. Tools for package owners.