Skip to content

Commit

Permalink
negative selectors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ericchiang committed Sep 19, 2014
1 parent 7913664 commit d393748
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
)

const VERSION string = "0.2.1"
const VERSION string = "0.2.2"

var (
// Flags
Expand Down
8 changes: 6 additions & 2 deletions selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ type SliceSelector struct {
End int
LimitEnd bool
By int
N int
}

func (sel SliceSelector) Select(nodes []*html.Node) []*html.Node {
Expand All @@ -248,15 +249,17 @@ func (sel SliceSelector) Select(nodes []*html.Node) []*html.Node {
case !sel.LimitStart:
start = 0
case sel.Start < 0:
start = (nNodes + 1) + sel.Start
start = nNodes + sel.Start
default:
start = sel.Start
}
switch {
case sel.N == 1:
end = start + 1
case !sel.LimitEnd:
end = nNodes
case sel.End < 0:
end = (nNodes + 1) + sel.End
end = nNodes + sel.End
default:
end = sel.End
}
Expand Down Expand Up @@ -287,6 +290,7 @@ func parseSliceSelector(s string) (sel SliceSelector, err error) {
}
split := strings.Split(s, ":")
n := len(split)
sel.N = n
if n > 3 {
err = fmt.Errorf("too many slices")
return
Expand Down

0 comments on commit d393748

Please sign in to comment.