Skip to content

Commit

Permalink
querylog: repl with golibs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Aug 13, 2021
1 parent 8459208 commit 7cc1235
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 163 deletions.
4 changes: 0 additions & 4 deletions internal/aghos/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ func sendProcessSignal(pid int, sig syscall.Signal) error {
return syscall.Kill(pid, sig)
}

func isActuallyOpenWrt() (ok bool) {
return false
}

func isOpenWrt() (ok bool) {
var err error
ok, err = FileWalker(func(r io.Reader) (_ []string, ok bool, err error) {
Expand Down
44 changes: 6 additions & 38 deletions internal/querylog/searchcriterion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package querylog

import (
"strings"
"unicode"
"unicode/utf8"

"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/stringutil"
)

type criterionType int
Expand Down Expand Up @@ -69,37 +68,6 @@ func ctDomainOrClientCaseStrict(
strings.EqualFold(name, term)
}

// containsFold reports whehter s contains, ignoring letter case, substr.
//
// TODO(a.garipov): Move to aghstrings if needed elsewhere.
func containsFold(s, substr string) (ok bool) {
sLen, substrLen := len(s), len(substr)
if sLen < substrLen {
return false
}

if sLen == substrLen {
return strings.EqualFold(s, substr)
}

first, _ := utf8.DecodeRuneInString(substr)
firstFolded := unicode.SimpleFold(first)

for i := 0; i != -1 && len(s) >= len(substr); {
if strings.EqualFold(s[:substrLen], substr) {
return true
}

i = strings.IndexFunc(s[1:], func(r rune) (eq bool) {
return r == first || r == firstFolded
})

s = s[1+i:]
}

return false
}

func ctDomainOrClientCaseNonStrict(
term string,
asciiTerm string,
Expand All @@ -108,11 +76,11 @@ func ctDomainOrClientCaseNonStrict(
host string,
ip string,
) (ok bool) {
return containsFold(clientID, term) ||
containsFold(host, term) ||
(asciiTerm != "" && containsFold(host, asciiTerm)) ||
containsFold(ip, term) ||
containsFold(name, term)
return stringutil.ContainsFold(clientID, term) ||
stringutil.ContainsFold(host, term) ||
(asciiTerm != "" && stringutil.ContainsFold(host, asciiTerm)) ||
stringutil.ContainsFold(ip, term) ||
stringutil.ContainsFold(name, term)
}

// quickMatch quickly checks if the line matches the given search criterion.
Expand Down
121 changes: 0 additions & 121 deletions internal/querylog/searchcriterion_test.go

This file was deleted.

0 comments on commit 7cc1235

Please sign in to comment.