MCPcopy Create free account
hub / github.com/PuerkitoBio/goquery / Slice

Method Slice

array.go:58–68  ·  view source on GitHub ↗

Slice reduces the set of matched elements to a subset specified by a range of indices. The start index is 0-based and indicates the index of the first element to select. The end index is 0-based and indicates the index at which the elements stop being selected (the end index is not selected). The i

(start, end int)

Source from the content-addressed store, hash-verified

56// until the end are selected. This works both for a positive and negative start
57// index.
58func (s *Selection) Slice(start, end int) *Selection {
59 if start < 0 {
60 start += len(s.Nodes)
61 }
62 if end == ToEnd {
63 end = len(s.Nodes)
64 } else if end < 0 {
65 end += len(s.Nodes)
66 }
67 return pushStack(s, s.Nodes[start:end])
68}
69
70// Get retrieves the underlying node at the specified index.
71// Get without parameter is not implemented, since the node array is available

Callers 14

EqMethod · 0.95
TestSliceFunction · 0.80
TestSliceToEndFunction · 0.80
TestSliceEmptyFunction · 0.80
TestSliceInvalidFunction · 0.80
TestSliceInvalidToEndFunction · 0.80
TestSliceOutOfBoundsFunction · 0.80
TestNegativeSliceStartFunction · 0.80
TestNegativeSliceEndFunction · 0.80
TestNegativeSliceBothFunction · 0.80
TestNegativeSliceToEndFunction · 0.80

Calls 1

pushStackFunction · 0.85

Tested by 13

TestSliceFunction · 0.64
TestSliceToEndFunction · 0.64
TestSliceEmptyFunction · 0.64
TestSliceInvalidFunction · 0.64
TestSliceInvalidToEndFunction · 0.64
TestSliceOutOfBoundsFunction · 0.64
TestNegativeSliceStartFunction · 0.64
TestNegativeSliceEndFunction · 0.64
TestNegativeSliceBothFunction · 0.64
TestNegativeSliceToEndFunction · 0.64
TestSliceRollbackFunction · 0.64