2016-10-17 18:37:56 +01:00
|
|
|
package auto
|
|
|
|
|
|
2025-10-06 09:05:58 +02:00
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2016-10-17 18:37:56 +01:00
|
|
|
// rewriteToExpand rewrites our template string to one that we can give to regexp.ExpandString. This basically
|
|
|
|
|
// involves prefixing any '{' with a '$'.
|
|
|
|
|
func rewriteToExpand(s string) string {
|
|
|
|
|
// Pretty dumb at the moment, every { will get a $ prefixed.
|
|
|
|
|
// Also wasteful as we build the string with +=. This is OKish
|
|
|
|
|
// as we do this during config parsing.
|
|
|
|
|
|
2025-10-06 09:05:58 +02:00
|
|
|
var copySb strings.Builder
|
2016-10-17 18:37:56 +01:00
|
|
|
for _, c := range s {
|
|
|
|
|
if c == '{' {
|
2025-10-06 09:05:58 +02:00
|
|
|
copySb.WriteString("$")
|
2016-10-17 18:37:56 +01:00
|
|
|
}
|
2025-10-06 09:05:58 +02:00
|
|
|
copySb.WriteString(string(c))
|
2016-10-17 18:37:56 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-06 09:05:58 +02:00
|
|
|
return copySb.String()
|
2016-10-17 18:37:56 +01:00
|
|
|
}
|