Skip to content

Commit

Permalink
add position feature for followingQuery to fixing following and `fo…
Browse files Browse the repository at this point in the history
…llowing-siblingand` position filter. antchfx/xmlquery#14
  • Loading branch information
zhengchun committed Aug 2, 2019
1 parent b6dbe47 commit 668f667
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func (d *descendantQuery) Clone() query {

// followingQuery is an XPath following node query.(following::*|following-sibling::*)
type followingQuery struct {
posit int
iterator func() NodeNavigator

Input query
Expand All @@ -307,6 +308,7 @@ type followingQuery struct {
func (f *followingQuery) Select(t iterator) NodeNavigator {
for {
if f.iterator == nil {
f.posit = 0
node := f.Input.Select(t)
if node == nil {
return nil
Expand All @@ -319,12 +321,13 @@ func (f *followingQuery) Select(t iterator) NodeNavigator {
return nil
}
if f.Predicate(node) {
f.posit++
return node
}
}
}
} else {
var q query // descendant query
var q *descendantQuery // descendant query
f.iterator = func() NodeNavigator {
for {
if q == nil {
Expand All @@ -341,6 +344,7 @@ func (f *followingQuery) Select(t iterator) NodeNavigator {
t.Current().MoveTo(node)
}
if node := q.Select(t); node != nil {
f.posit = q.posit
return node
}
q = nil
Expand Down Expand Up @@ -369,6 +373,10 @@ func (f *followingQuery) Clone() query {
return &followingQuery{Input: f.Input.Clone(), Sibling: f.Sibling, Predicate: f.Predicate}
}

func (f *followingQuery) position() int {
return f.posit
}

// precedingQuery is an XPath preceding node query.(preceding::*)
type precedingQuery struct {
iterator func() NodeNavigator
Expand Down

0 comments on commit 668f667

Please sign in to comment.