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)
| 149 | // transformations of the completion contain the lowercase |
| 150 | // version of the seed. |
| 151 | func 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 |
no test coverage detected