File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ func (m *AcModel) buildFailPointers() {
129
129
} else {
130
130
p := tmpAcNode .fail
131
131
for p != nil {
132
- if next , found := p .children [ node .value ] ; found {
132
+ if next , found := p .getChild ( node .value ) ; found {
133
133
node .fail = next
134
134
break
135
135
}
@@ -181,23 +181,29 @@ func (m *AcModel) FindAll(text string) []string {
181
181
182
182
for pos := 0 ; pos < len (runes ); pos ++ {
183
183
_ , found = now .getChild (runes [pos ])
184
- if ! found && now != m .root {
184
+ if ! found && now != nil && now != m .root {
185
185
now = now .fail
186
- for ; ! found && now != m .root ; now , found = now .getChild (runes [pos ]) {
186
+ for ; ! found && now != nil && now != m .root ; now , found = now .getChild (runes [pos ]) {
187
187
now = now .fail
188
188
}
189
189
}
190
190
191
191
// 若找到匹配成功的字符串结点, 则指向那个结点, 否则指向根结点
192
- if next , ok := now .getChild (runes [pos ]); ok {
192
+ var next * acNode
193
+ var ok bool
194
+
195
+ if now != nil {
196
+ next , ok = now .getChild (runes [pos ])
197
+ }
198
+ if ok {
193
199
now = next
194
200
} else {
195
201
now = m .root
196
202
}
197
203
198
204
temp = now
199
205
200
- for temp != m .root {
206
+ for temp != nil && temp != m .root {
201
207
if temp .word != nil {
202
208
matches = append (matches , * temp .word )
203
209
}
You can’t perform that action at this time.
0 commit comments