mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Add replaceMatches
This commit is contained in:
parent
15f20ffaeb
commit
5a38c8dd2f
@ -389,6 +389,7 @@ The following helper functions provided by Glance are available:
|
|||||||
- `trimSuffix(suffix string, str string) string`: Trims the suffix from a string.
|
- `trimSuffix(suffix string, str string) string`: Trims the suffix from a string.
|
||||||
- `trimSpace(str string) string`: Trims whitespace from a string on both ends.
|
- `trimSpace(str string) string`: Trims whitespace from a string on both ends.
|
||||||
- `replaceAll(old string, new string, str string) string`: Replaces all occurrences of a string in a string.
|
- `replaceAll(old string, new string, str string) string`: Replaces all occurrences of a string in a string.
|
||||||
|
- `replaceMatches(pattern string, replacement string, str string) string`: Replaces all occurrences of a regular expression in a string.
|
||||||
- `findMatch(pattern string, str string) string`: Finds the first match of a regular expression in a string.
|
- `findMatch(pattern string, str string) string`: Finds the first match of a regular expression in a string.
|
||||||
- `findSubmatch(pattern string, str string) string`: Finds the first submatch of a regular expression in a string.
|
- `findSubmatch(pattern string, str string) string`: Finds the first submatch of a regular expression in a string.
|
||||||
- `sortByString(key string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by a string key in either ascending or descending order.
|
- `sortByString(key string, order string, arr []JSON): []JSON`: Sorts an array of JSON objects by a string key in either ascending or descending order.
|
||||||
|
@ -468,16 +468,15 @@ var customAPITemplateFuncs = func() template.FuncMap {
|
|||||||
return strings.TrimSuffix(s, suffix)
|
return strings.TrimSuffix(s, suffix)
|
||||||
},
|
},
|
||||||
"trimSpace": strings.TrimSpace,
|
"trimSpace": strings.TrimSpace,
|
||||||
"replaceAll": func(oldOrPattern, new, s string) string {
|
"replaceAll": func(old, new, s string) string {
|
||||||
|
return strings.ReplaceAll(s, old, new)
|
||||||
|
},
|
||||||
|
"replaceMatches": func(pattern, replacement, s string) string {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
regex := getCachedRegexp(oldOrPattern)
|
return getCachedRegexp(pattern).ReplaceAllString(s, replacement)
|
||||||
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