Fix compatibility issues with OR operator and inverse terms

This commit is contained in:
Junegunn Choi
2015-11-10 01:50:41 +09:00
parent e7e86b68f4
commit 31278bcc68
4 changed files with 22 additions and 9 deletions

View File

@@ -323,21 +323,24 @@ func (p *Pattern) basicMatch(item *Item) (int, int, int) {
func (p *Pattern) extendedMatch(item *Item) []Offset {
input := p.prepareInput(item)
offsets := []Offset{}
Loop:
for _, termSet := range p.termSets {
var offset *Offset
for _, term := range termSet {
pfun := p.procFun[term.typ]
if sidx, eidx, tlen := p.iter(pfun, input, term.caseSensitive, p.forward, term.text); sidx >= 0 {
if term.inv {
break Loop
continue
}
offsets = append(offsets, Offset{int32(sidx), int32(eidx), int32(tlen)})
offset = &Offset{int32(sidx), int32(eidx), int32(tlen)}
break
} else if term.inv {
offsets = append(offsets, Offset{0, 0, 0})
break
offset = &Offset{0, 0, 0}
continue
}
}
if offset != nil {
offsets = append(offsets, *offset)
}
}
return offsets
}