feat(aa-log): minor structure improvments.
This commit is contained in:
parent
85e7832f0b
commit
6325314825
2 changed files with 34 additions and 20 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue