feat(aa-log): minor structure improvments.

This commit is contained in:
Alexandre Pujol 2023-07-23 17:00:52 +01:00
parent 85e7832f0b
commit 6325314825
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
2 changed files with 34 additions and 20 deletions

View file

@ -11,6 +11,11 @@ import (
var isHexa = regexp.MustCompile("^[0-9A-Fa-f]+$")
type RegexRepl struct {
Regex *regexp.Regexp
Repl string
}
// DecodeHex decode a string if it is hexa.
func DecodeHex(str string) string {
if isHexa.MatchString(str) {
@ -34,3 +39,18 @@ func RemoveDuplicate[T comparable](inlist []T) []T {
}
return list
}
// ToRegexRepl convert slice of regex into a slice of RegexRepl
func ToRegexRepl(in []string) []RegexRepl {
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
}