Skip to content

Commit 580826c

Browse files
committed
Simplified utils.Match function
1 parent 804b8d0 commit 580826c

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

Diff for: arduino/utils/search.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ func removeDiatrics(s string) (string, error) {
4747
// Both str and substrings are transforms to lower case and have their
4848
// accents and other unicode diatrics removed.
4949
// If strings transformation fails an error is returned.
50-
func Match(str string, substrings []string) (bool, error) {
51-
str, err := removeDiatrics(strings.ToLower(str))
52-
if err != nil {
53-
return false, err
50+
func Match(str string, substrings []string) bool {
51+
clean := func(s string) string {
52+
s = strings.ToLower(s)
53+
if s2, err := removeDiatrics(s); err == nil {
54+
return s2
55+
}
56+
return s
5457
}
5558

59+
str = clean(str)
5660
for _, sub := range substrings {
57-
cleanSub, err := removeDiatrics(strings.ToLower(sub))
58-
if err != nil {
59-
return false, err
60-
}
61-
if !strings.Contains(str, cleanSub) {
62-
return false, nil
61+
if !strings.Contains(str, clean(sub)) {
62+
return false
6363
}
6464
}
65-
return true, nil
65+
return true
6666
}

Diff for: commands/core/search.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
5454
}
5555

5656
for _, t := range toTest {
57-
matches, err := utils.Match(t, searchArgs)
58-
if err != nil {
59-
return false, err
60-
}
61-
if matches {
62-
return matches, nil
57+
if utils.Match(t, searchArgs) {
58+
return true, nil
6359
}
6460
}
6561
return false, nil

0 commit comments

Comments
 (0)