-
Notifications
You must be signed in to change notification settings - Fork 0
/
word.go
75 lines (62 loc) · 1.26 KB
/
word.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package dirsyn
func wordMatch(a, b any) (result Boolean, err error) {
var str1, str2 string
str1, err = assertString(a, 1, "word")
if err != nil {
return
}
str2, err = assertString(b, 1, "word")
if err != nil {
return
}
// Split the attribute value into words
words := fields(str2)
// Check if any word matches the assertion value
var found bool
for _, word := range words {
if found = streqf(word, str1); found {
break
}
}
result.Set(found)
return
}
/*
TODO: dig deeper into other impls. to determine best (or most common)
practice to adopt.
*/
func keywordSplit(input string) (out []string) {
bld := newStrBuilder()
for _, char := range input {
if isSpace(char) || isPunct(char) {
if bld.Len() > 0 {
out = append(out, bld.String())
bld.Reset()
}
} else {
bld.WriteRune(char)
}
}
if bld.Len() > 0 {
out = append(out, bld.String())
}
return
}
func keywordMatch(a, b any) (result Boolean, err error) {
var str1, str2 string
if str1, err = assertString(a, 1, "keyword"); err != nil {
return
}
if str2, err = assertString(b, 1, "keyword"); err != nil {
return
}
keys := keywordSplit(str2)
var found bool
for _, key := range keys {
if found = streqf(key, str1); found {
break
}
}
result.Set(found)
return
}