mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-02-20 08:55:34 +01:00
chore: move internal util function.
This commit is contained in:
parent
dbb0d76e52
commit
662dd1c6dc
1 changed files with 22 additions and 22 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue