chore: move internal util function.

This commit is contained in:
Alexandre Pujol 2024-03-21 18:54:52 +00:00
parent dbb0d76e52
commit 662dd1c6dc
Failed to generate hash of commit

View file

@ -16,6 +16,28 @@ type RegexRepl struct {
Repl string
}
// ToRegexRepl convert slice of regex into a slice of RegexRepl
func ToRegexRepl(in []string) RegexReplList {
out := make([]RegexRepl, 0)
idx := 0
for idx < len(in)-1 {
regex, repl := in[idx], in[idx+1]
out = append(out, RegexRepl{
Regex: regexp.MustCompile(regex),
Repl: repl,
})
idx = idx + 2
}
return out
}
func (rr RegexReplList) Replace(str string) string {
for _, aa := range rr {
str = aa.Regex.ReplaceAllLiteralString(str, aa.Repl)
}
return str
}
// DecodeHexInString decode and replace all hex value in a given string constitued of "key=value".
func DecodeHexInString(str string) string {
toDecode := []string{"name", "comm", "profile"}
@ -45,25 +67,3 @@ func RemoveDuplicate[T comparable](inlist []T) []T {
}
return list
}
// ToRegexRepl convert slice of regex into a slice of RegexRepl
func ToRegexRepl(in []string) RegexReplList {
out := make([]RegexRepl, 0)
idx := 0
for idx < len(in)-1 {
regex, repl := in[idx], in[idx+1]
out = append(out, RegexRepl{
Regex: regexp.MustCompile(regex),
Repl: repl,
})
idx = idx + 2
}
return out
}
func (rr RegexReplList) Replace(str string) string {
for _, aa := range rr {
str = aa.Regex.ReplaceAllLiteralString(str, aa.Repl)
}
return str
}