MCPcopy Create free account
hub / github.com/cogentcore/core / IsSeedMatching

Function IsSeedMatching

parse/complete/complete.go:151–177  ·  view source on GitHub ↗

IsSeedMatching returns whether the given lowercase seed matches the given completion string. It checks whether different transformations of the completion contain the lowercase version of the seed.

(lseed string, completion string)

Source from the content-addressed store, hash-verified

149// transformations of the completion contain the lowercase
150// version of the seed.
151func IsSeedMatching(lseed string, completion string) bool {
152 lc := strings.ToLower(completion)
153 if strings.Contains(lc, lseed) {
154 return true
155 }
156
157 // stripped version of completion
158 // (space delimeted with no punctuation and symbols)
159 cs := strings.Map(func(r rune) rune {
160 if unicode.IsPunct(r) || unicode.IsSymbol(r) {
161 return -1
162 }
163 return r
164 }, completion)
165 cs = strcase.ToWordCase(cs, strcase.WordLowerCase, ' ')
166 if strings.Contains(cs, lseed) {
167 return true
168 }
169
170 // the initials (first letters) of every field
171 ci := ""
172 csdf := strings.Fields(cs)
173 for _, f := range csdf {
174 ci += string(f[0])
175 }
176 return strings.Contains(ci, lseed)
177}
178
179// MatchPrecedence returns the sorting precedence of the given
180// completion relative to the given lowercase seed. The completion

Callers 2

MatchSeedStringFunction · 0.85
MatchSeedCompletionFunction · 0.85

Calls 3

ToWordCaseFunction · 0.92
MapMethod · 0.80
ContainsMethod · 0.45

Tested by

no test coverage detected