text

package
v0.0.0-...-3fb1d06 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package text provides various utilities for working with text. Most APIs have both string and []byte versions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandVariables

func ExpandVariables(src []byte, mapping func(string) string) []byte

ExpandVariables replaces ${var} in the byte slice based on the mapping function. The returned byte slice is a copy of src with the replacements made, src is not modified. If src contains no variables, src is returned as is.

func ExpandVariablesString

func ExpandVariablesString(src string, mapping func(string) string) string

ExpandVariablesString replaces ${var} in the string based on the mapping function.

Types

type VariableMapper

type VariableMapper struct {
	// contains filtered or unexported fields
}

VariableMapper can be used to expand variables with ExpandVariables or ExpandVariablesString. It records any missing variables.

func NewVariableMapper

func NewVariableMapper(vars map[string]string) *VariableMapper

NewVariableMapper creates a new VariableMapper that uses vars as the values for expanded variables.

func (*VariableMapper) Map

func (vm *VariableMapper) Map(name string) string

Map maps a variable name to its value. It can be passed to ExpandVariables or ExpandVariablesString.

func (*VariableMapper) Missing

func (vm *VariableMapper) Missing() []string

Missing returns all missing variables that were encountered in order. A missing variable is only included once, duplicates are removed.

Jump to

Keyboard shortcuts

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