Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 28dd57d

Browse files
committed
Moving SearchTermsFromQueryString into proper place
1 parent ebb55e3 commit 28dd57d

File tree

4 files changed

+12
-33
lines changed

4 files changed

+12
-33
lines changed

‎arduino/utils/search.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ func removeDiatrics(s string) (string, error) {
4343
return s, nil
4444
}
4545

46+
// SearchTermsFromQueryString returns the terms inside the query string.
47+
// All non alphanumeric characters (expect ':') are considered separators.
48+
// All search terms are converted to lowercase.
49+
func SearchTermsFromQueryString(query string) []string {
50+
// Split on anything but 0-9, a-z or :
51+
return strings.FieldsFunc(strings.ToLower(query), func(r rune) bool {
52+
return !unicode.IsLetter(r) && !unicode.IsNumber(r) && r != ':'
53+
})
54+
}
55+
4656
// Match returns true if all substrings are contained in str.
4757
// Both str and substrings are transforms to lower case and have their
4858
// accents and other unicode diatrics removed.

‎commands/core/search.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
4040
vid, pid := req.SearchArgs[:4], req.SearchArgs[5:]
4141
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
4242
} else {
43-
searchArgs := rpc.SearchTermsFromQueryString(req.SearchArgs)
43+
searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs)
4444
allVersions := req.AllVersions
4545
for _, targetPackage := range pme.GetPackages() {
4646
for _, platform := range targetPackage.Platforms {

‎commands/lib/search.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.Lib
3838

3939
func searchLibrary(req *rpc.LibrarySearchRequest, lm *librariesmanager.LibrariesManager) *rpc.LibrarySearchResponse {
4040
res := []*rpc.SearchedLibrary{}
41-
queryTerms := rpc.SearchTermsFromQueryString(req.GetQuery())
41+
queryTerms := utils.SearchTermsFromQueryString(req.GetQuery())
4242

4343
for _, lib := range lm.Index.Libraries {
4444
toTest := lib.Name + " " +

‎rpc/cc/arduino/cli/commands/v1/search.go‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /