1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/runtime/collections/html.go
Tim Voronov 549b4abd3b
Feature/#5 collect keyword alt (#141)
Implemented COLLECT key word
2018-10-24 21:30:05 -04:00

41 lines
773 B
Go

package collections
import (
"github.com/MontFerret/ferret/pkg/runtime/values"
)
type HTMLNodeIterator struct {
valVar string
keyVar string
values values.HTMLNode
pos int
}
func NewHTMLNodeIterator(
valVar,
keyVar string,
input values.HTMLNode,
) Iterator {
return &HTMLNodeIterator{valVar, keyVar, input, 0}
}
func (iterator *HTMLNodeIterator) HasNext() bool {
return iterator.values.Length() > values.NewInt(iterator.pos)
}
func (iterator *HTMLNodeIterator) Next() (DataSet, error) {
if iterator.values.Length() > values.NewInt(iterator.pos) {
idx := values.NewInt(iterator.pos)
val := iterator.values.GetChildNode(idx)
iterator.pos++
return DataSet{
iterator.valVar: val,
iterator.keyVar: idx,
}, nil
}
return nil, ErrExhausted
}