New ScanExt() function allowing the introductory character to be chosen

This commit is contained in:
Celestino Amoroso 2024-02-25 07:01:04 +01:00
parent d297530309
commit ccdd5c5cdb
3 changed files with 8 additions and 3 deletions

View File

@ -10,8 +10,6 @@ import (
"git.portale-stac.it/go-pkg/golang" "git.portale-stac.it/go-pkg/golang"
) )
const varIntro = '$'
type ExpanderFunc func(ctx ExpanderContext, varValue string, args []string) (result string, err error) type ExpanderFunc func(ctx ExpanderContext, varValue string, args []string) (result string, err error)
type ExpanderFuncBlock struct { type ExpanderFuncBlock struct {

View File

@ -17,11 +17,18 @@ const (
// Flags symbols in the abova iota order // Flags symbols in the abova iota order
const flagSymbols = "!=*" const flagSymbols = "!=*"
const defaultVarIntro = '$'
type VariableHandler interface { type VariableHandler interface {
Handle(varSpec string, flags ScannerFlag) (value string, err error) Handle(varSpec string, flags ScannerFlag) (value string, err error)
} }
func Scan(handler VariableHandler, source string) (result string, err error) { func Scan(handler VariableHandler, source string) (result string, err error) {
return ScanExt(defaultVarIntro, handler, source)
}
func ScanExt(varIntro byte, handler VariableHandler, source string) (result string, err error) {
var spec, value string var spec, value string
var flags ScannerFlag var flags ScannerFlag
var backSlash bool var backSlash bool

View File

@ -6,5 +6,5 @@ import (
) )
func Var(name string) string { func Var(name string) string {
return fmt.Sprintf("%c{%s}", varIntro, name) return fmt.Sprintf("%c{%s}", defaultVarIntro, name)
} }