| 298 | } |
| 299 | |
| 300 | func FindMatchIn(searchName string, items ...string) (match string, closeMatch string) { |
| 301 | |
| 302 | if searchName == `` { |
| 303 | return ``, `` // No match |
| 304 | } |
| 305 | |
| 306 | searchName, searchNumber := GetMatchNumber(searchName) |
| 307 | |
| 308 | var matchCt int = 0 |
| 309 | var closeMatchCt int = 0 |
| 310 | |
| 311 | for _, i := range items { |
| 312 | |
| 313 | part, full := stringMatch(searchName, i, false) |
| 314 | |
| 315 | if part { |
| 316 | closeMatchCt++ |
| 317 | if closeMatchCt == searchNumber { |
| 318 | closeMatch = i |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | if full { |
| 323 | matchCt++ |
| 324 | if matchCt == searchNumber { |
| 325 | match = i |
| 326 | break |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | } |
| 331 | |
| 332 | // If no "starts with" or "exact" matches are found, try and find the first item that contain the supplied name |
| 333 | // Note: Can't have an exact match if there was never a close match |
| 334 | if len(closeMatch) == 0 { |
| 335 | closeMatchCt = 0 |
| 336 | for _, i := range items { |
| 337 | part, _ := stringMatch(searchName, i, true) |
| 338 | |
| 339 | if part { |
| 340 | closeMatchCt++ |
| 341 | if closeMatchCt == searchNumber { |
| 342 | closeMatch = i |
| 343 | break |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | } |
| 348 | |
| 349 | } |
| 350 | |
| 351 | return match, closeMatch |
| 352 | } |
| 353 | |
| 354 | // Searches for a partial or full match of a string |
| 355 | // If allowContains is true, the match can appear anywhere in the string. |