MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / ContainsAnyWordRunes

Function ContainsAnyWordRunes

internal/utils/runes/runes.go:6–37  ·  view source on GitHub ↗

ContainsAnyWordRunes 直接使用rune检查字符串是否包含任一单词

(s string, words [][]rune, isCaseInsensitive bool)

Source from the content-addressed store, hash-verified

4
5// ContainsAnyWordRunes 直接使用rune检查字符串是否包含任一单词
6func 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 检查字符串是否包含任一单词
40func ContainsAnyWord(s string, words []string, isCaseInsensitive bool) bool {

Callers 2

TestMethod · 0.92

Calls 1

ContainsWordRunesFunction · 0.85

Tested by 1