interpolate

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parsed

type Parsed []part

Parsed is a parsed string.

func Parse

func Parse(s string) Parsed

Parse parses the string and returns a parsed representation. The variables may be interpolated later using the Interpolate method.

The syntax is similar to shell variable expansion. The following rules apply:

- Variables are enclosed in ${...} and may contain any character.

- Variables may have a default value separated by -, eq. ${VAR-default}.

- To include a literal $, escape it with a backslash, eq. \$.

- If a variable is not closed, it is treated as a literal.

func ParsePercent

func ParsePercent(s string) Parsed

ParsePercent parses the string and returns a parsed representation. The variables may be interpolated later using the Interpolate method.

The syntax is similar to shell variable expansion. The following rules apply:

- Variables are enclosed in %{...} and may contain any character.

- Variables may have a default value separated by -, eq. %{VAR-default}.

- To include a literal %, escape it with a backslash, eq. \%.

- If a variable is not closed, it is treated as a literal.

func (Parsed) HasVars

func (s Parsed) HasVars() bool

HasVars returns true if the string contain at least one variable.

func (Parsed) Interpolate

func (s Parsed) Interpolate(mapping func(variable Variable) string) string

Interpolate replaces variables in the string based on the mapping function.

type Variable

type Variable struct {
	Name       string // Name of the variable.
	Default    string // Default value if the variable is not set.
	HasDefault bool   // True if the variable has a default value.
}

Jump to

Keyboard shortcuts

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