Documentation
¶
Index ¶
- Variables
- func Echo(s string) string
- func Find(template []byte, opts ...Option) (places []int)
- func FindAndReplace(template []byte, wr io.Writer, repl Replacer, opts ...Option)
- func FindAndReplaceString(template string, wr io.Writer, repl Replacer, opts ...Option)
- func Positions(template []byte, places []int) (positions []string)
- func Replace(template []byte, wr io.Writer, places []int, repl Replacer)
- func ReplaceBytes(template []byte, wr io.Writer, places []int, replacements map[string][]byte)
- type Buffer
- type BytesMap
- type Cache
- type Empty
- type Option
- type ReadSeekerMap
- type ReplaceFunc
- type ReplaceStringFunc
- type Replacer
- type ReplacerMap
- type Self
- type String
- type StringMap
- type WriterToMap
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultStartDel is the default start delimiter (prefix of the position) DefaultStartDel = []byte("[@") // DefaultEndDel is the default end delimiter (postfix of the position) DefaultEndDel = []byte("@]") )
Functions ¶
func Find ¶
Find looks for positions written in the style "[@positionname@]" inside the given template. It returns a slice containing the positions of the positions that is meant to be passed to Replace or ReplaceString.
func FindAndReplace ¶
FindAndReplace finds positions and replaces them in one go.
func FindAndReplaceString ¶
FindAndReplaceString finds positions and replaces them in one go.
func Replace ¶
Replace replaces the positions at the given places inside the template by using the given Replacer. The given template must be the unchanged byte array that was passed to Find in order to get the places. For strings as replacements see the optimized ReplaceString function for bytes use ReplaceBytes.
Types ¶
type Buffer ¶
The Buffer interface is fullfilled by *bytes.Buffer. However since for performance reasons the errors from writing to the buffer are always ignored, you will need to write a buffer wrapper to capture them.
type Cache ¶ added in v1.2.1
type Cache struct {
// contains filtered or unexported fields
}
Cache is caching the template and the positions of the positions
func New ¶ added in v1.2.1
New parses the given bytes and returns a Cache to remember where the positions are inside the template
func NewString ¶ added in v1.3.0
NewString parses the given string and returns a Cache to remember where the positions are inside the template
type Empty ¶ added in v1.2.0
type Empty struct{}
Empty is a Replacer that always returns an empty string
type Option ¶ added in v1.1.0
type Option func(c *options)
Option is a parsing option
func WithDelimiter ¶ added in v1.1.0
WithDelimiter sets custom delimiters of the positions The starting and delimiters must be 2 bytes long and must not be equal. We panic, if these rules are not fullfilled.
type ReadSeekerMap ¶ added in v1.2.0
type ReadSeekerMap map[string]io.ReadSeeker
ReadSeekerMap is a readseeker map that implements Replacer
type ReplaceFunc ¶ added in v1.2.0
ReplaceFunc is a func implementing Replacer
type ReplaceStringFunc ¶ added in v1.2.0
ReplaceStringFunc is a func implementing Replacer
type Replacer ¶ added in v1.2.0
Replacer replaces the position with its value, by writing the value to the given io.Writer This is a core component that allows different sources for the replacement. Some implementations can be found in the replacer.go file. If you want to track errors around io then implement your own Replacer to track them.
func FromReadSeeker ¶ added in v1.2.0
func FromReadSeeker(rs io.ReadSeeker, errHandler func(error)) Replacer
FromReadSeeker returns a Replacer that is getting the data from the ReadSeeker
func FromReader ¶ added in v1.2.0
FromReader returns a Replacer that is getting the data from the Reader
type ReplacerMap ¶ added in v1.2.0
ReplacerMap is a string map that implements Replacer
type String ¶ added in v1.2.0
type String string
String is a Relacer that always returns the string itself