From ccdd5c5cdbaafea68e85ed7122c45a3911983694 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Sun, 25 Feb 2024 07:01:04 +0100 Subject: [PATCH] New ScanExt() function allowing the introductory character to be chosen --- expander-context.go | 2 -- scanner.go | 7 +++++++ utils.go | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/expander-context.go b/expander-context.go index ff8997e..54759dc 100644 --- a/expander-context.go +++ b/expander-context.go @@ -10,8 +10,6 @@ import ( "git.portale-stac.it/go-pkg/golang" ) -const varIntro = '$' - type ExpanderFunc func(ctx ExpanderContext, varValue string, args []string) (result string, err error) type ExpanderFuncBlock struct { diff --git a/scanner.go b/scanner.go index e6b7b50..3a25e98 100644 --- a/scanner.go +++ b/scanner.go @@ -17,11 +17,18 @@ const ( // Flags symbols in the abova iota order const flagSymbols = "!=*" +const defaultVarIntro = '$' + + type VariableHandler interface { Handle(varSpec string, flags ScannerFlag) (value 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 flags ScannerFlag var backSlash bool diff --git a/utils.go b/utils.go index 01cc7c4..4513f8e 100644 --- a/utils.go +++ b/utils.go @@ -6,5 +6,5 @@ import ( ) func Var(name string) string { - return fmt.Sprintf("%c{%s}", varIntro, name) + return fmt.Sprintf("%c{%s}", defaultVarIntro, name) }