mirror of
https://github.com/ericchiang/pup
synced 2024-11-28 02:48:16 +00:00
negative selectors fixed
This commit is contained in:
parent
791366455e
commit
d39374885b
2
main.go
2
main.go
@ -12,7 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION string = "0.2.1"
|
const VERSION string = "0.2.2"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Flags
|
// Flags
|
||||||
|
@ -238,6 +238,7 @@ type SliceSelector struct {
|
|||||||
End int
|
End int
|
||||||
LimitEnd bool
|
LimitEnd bool
|
||||||
By int
|
By int
|
||||||
|
N int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sel SliceSelector) Select(nodes []*html.Node) []*html.Node {
|
func (sel SliceSelector) Select(nodes []*html.Node) []*html.Node {
|
||||||
@ -248,15 +249,17 @@ func (sel SliceSelector) Select(nodes []*html.Node) []*html.Node {
|
|||||||
case !sel.LimitStart:
|
case !sel.LimitStart:
|
||||||
start = 0
|
start = 0
|
||||||
case sel.Start < 0:
|
case sel.Start < 0:
|
||||||
start = (nNodes + 1) + sel.Start
|
start = nNodes + sel.Start
|
||||||
default:
|
default:
|
||||||
start = sel.Start
|
start = sel.Start
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
|
case sel.N == 1:
|
||||||
|
end = start + 1
|
||||||
case !sel.LimitEnd:
|
case !sel.LimitEnd:
|
||||||
end = nNodes
|
end = nNodes
|
||||||
case sel.End < 0:
|
case sel.End < 0:
|
||||||
end = (nNodes + 1) + sel.End
|
end = nNodes + sel.End
|
||||||
default:
|
default:
|
||||||
end = sel.End
|
end = sel.End
|
||||||
}
|
}
|
||||||
@ -287,6 +290,7 @@ func parseSliceSelector(s string) (sel SliceSelector, err error) {
|
|||||||
}
|
}
|
||||||
split := strings.Split(s, ":")
|
split := strings.Split(s, ":")
|
||||||
n := len(split)
|
n := len(split)
|
||||||
|
sel.N = n
|
||||||
if n > 3 {
|
if n > 3 {
|
||||||
err = fmt.Errorf("too many slices")
|
err = fmt.Errorf("too many slices")
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user