Skip to content

Commit 09af6d5

Browse files
committed
Simplified utils.Match function
1 parent 804b8d0 commit 09af6d5

File tree

5 files changed

+19
-35
lines changed

5 files changed

+19
-35
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/board/listall.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,8 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
4747
}
4848

4949
for _, t := range toTest {
50-
matches, err := utils.Match(t, searchArgs)
51-
if err != nil {
52-
return false, err
53-
}
54-
if matches {
55-
return matches, nil
50+
if utils.Match(t, searchArgs) {
51+
return true, nil
5652
}
5753
}
5854
return false, nil

Diff for: commands/board/search.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
4444
}
4545

4646
for _, t := range toTest {
47-
matches, err := utils.Match(t, searchArgs)
48-
if err != nil {
49-
return false, err
50-
}
51-
if matches {
52-
return matches, nil
47+
if utils.Match(t, searchArgs) {
48+
return true, nil
5349
}
5450
}
5551
return false, nil

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

Diff for: commands/lib/search.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ func searchLibrary(req *rpc.LibrarySearchRequest, lm *librariesmanager.Libraries
5151
}
5252

5353
for _, t := range toTest {
54-
matches, err := utils.Match(t, searchArgs)
55-
if err != nil {
56-
return false, err
57-
}
58-
if matches {
59-
return matches, nil
54+
if utils.Match(t, searchArgs) {
55+
return true, nil
6056
}
6157
}
6258
return false, nil

0 commit comments

Comments
 (0)