MCPcopy Create free account
hub / github.com/foxcpp/maddy / expandSingleValueMacro

Method expandSingleValueMacro

framework/cfgparser/imports.go:158–176  ·  view source on GitHub ↗
(arg string)

Source from the content-addressed store, hash-verified

156var macroRe = regexp.MustCompile(`\$\(([^\$]+)\)`)
157
158func (ctx *parseContext) expandSingleValueMacro(arg string) (string, error) {
159 matches := macroRe.FindAllStringSubmatch(arg, -1)
160 for _, match := range matches {
161 macroName := match[1]
162 if len(ctx.macros[macroName]) > 1 {
163 return "", ctx.Err("can't expand macro with multiple arguments inside a string")
164 }
165
166 var value string
167 if ctx.macros[macroName] != nil {
168 // Macros have at least one argument.
169 value = ctx.macros[macroName][0]
170 }
171
172 arg = strings.ReplaceAll(arg, "$("+macroName+")", value)
173 }
174
175 return arg, nil
176}

Callers 1

expandMacrosMethod · 0.95

Calls 1

ErrMethod · 0.80

Tested by

no test coverage detected