mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
feat: custom-api's replaceAll with regex support
This commit is contained in:
parent
7f0e9b3289
commit
15f20ffaeb
@ -468,8 +468,16 @@ var customAPITemplateFuncs = func() template.FuncMap {
|
|||||||
return strings.TrimSuffix(s, suffix)
|
return strings.TrimSuffix(s, suffix)
|
||||||
},
|
},
|
||||||
"trimSpace": strings.TrimSpace,
|
"trimSpace": strings.TrimSpace,
|
||||||
"replaceAll": func(old, new, s string) string {
|
"replaceAll": func(oldOrPattern, new, s string) string {
|
||||||
return strings.ReplaceAll(s, old, new)
|
if s == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
regex := getCachedRegexp(oldOrPattern)
|
||||||
|
if regex == nil {
|
||||||
|
return strings.ReplaceAll(s, oldOrPattern, new)
|
||||||
|
}
|
||||||
|
return regex.ReplaceAllString(s, new)
|
||||||
},
|
},
|
||||||
"findMatch": func(pattern, s string) string {
|
"findMatch": func(pattern, s string) string {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user