(li, searchString, method, normalize)
| 420 | // </editor-fold> |
| 421 | |
| 422 | function stringSearch (li, searchString, method, normalize) { |
| 423 | var stringTypes = [ |
| 424 | 'display', |
| 425 | 'subtext', |
| 426 | 'tokens' |
| 427 | ], |
| 428 | searchSuccess = false; |
| 429 | |
| 430 | for (var i = 0; i < stringTypes.length; i++) { |
| 431 | var stringType = stringTypes[i], |
| 432 | string = li[stringType]; |
| 433 | |
| 434 | if (string) { |
| 435 | string = string.toString(); |
| 436 | |
| 437 | // Strip HTML tags. This isn't perfect, but it's much faster than any other method |
| 438 | if (stringType === 'display') { |
| 439 | string = string.replace(/<[^>]+>/g, ''); |
| 440 | } |
| 441 | |
| 442 | if (normalize) string = normalizeToBase(string); |
| 443 | string = string.toUpperCase(); |
| 444 | |
| 445 | if (method === 'contains') { |
| 446 | searchSuccess = string.indexOf(searchString) >= 0; |
| 447 | } else { |
| 448 | searchSuccess = string.startsWith(searchString); |
| 449 | } |
| 450 | |
| 451 | if (searchSuccess) break; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | return searchSuccess; |
| 456 | } |
| 457 | |
| 458 | function toInteger (value) { |
| 459 | return parseInt(value, 10) || 0; |
no test coverage detected