ContainsAnyWordRunes 直接使用rune检查字符串是否包含任一单词
(s string, words [][]rune, isCaseInsensitive bool)
| 4 | |
| 5 | // ContainsAnyWordRunes 直接使用rune检查字符串是否包含任一单词 |
| 6 | func ContainsAnyWordRunes(s string, words [][]rune, isCaseInsensitive bool) bool { |
| 7 | var allRunes = []rune(s) |
| 8 | if len(allRunes) == 0 || len(words) == 0 { |
| 9 | return false |
| 10 | } |
| 11 | |
| 12 | var lastRune rune // last searching rune in s |
| 13 | var lastIndex = -2 // -2: not started, -1: not found, >=0: rune index |
| 14 | for _, wordRunes := range words { |
| 15 | if len(wordRunes) == 0 { |
| 16 | continue |
| 17 | } |
| 18 | |
| 19 | if lastIndex > -2 && lastRune == wordRunes[0] { |
| 20 | if lastIndex >= 0 { |
| 21 | result, _ := ContainsWordRunes(allRunes[lastIndex:], wordRunes, isCaseInsensitive) |
| 22 | if result { |
| 23 | return true |
| 24 | } |
| 25 | } |
| 26 | continue |
| 27 | } else { |
| 28 | result, firstIndex := ContainsWordRunes(allRunes, wordRunes, isCaseInsensitive) |
| 29 | lastIndex = firstIndex |
| 30 | if result { |
| 31 | return true |
| 32 | } |
| 33 | } |
| 34 | lastRune = wordRunes[0] |
| 35 | } |
| 36 | return false |
| 37 | } |
| 38 | |
| 39 | // ContainsAnyWord 检查字符串是否包含任一单词 |
| 40 | func ContainsAnyWord(s string, words []string, isCaseInsensitive bool) bool { |