mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-05 08:46:53 +08:00
lint
This commit is contained in:
76
array.go
76
array.go
@@ -4,89 +4,89 @@ import (
|
||||
"code.google.com/p/go.net/html"
|
||||
)
|
||||
|
||||
// First() reduces the set of matched elements to the first in the set.
|
||||
// First reduces the set of matched elements to the first in the set.
|
||||
// It returns a new Selection object, and an empty Selection object if the
|
||||
// the selection is empty.
|
||||
func (this *Selection) First() *Selection {
|
||||
return this.Eq(0)
|
||||
func (s *Selection) First() *Selection {
|
||||
return s.Eq(0)
|
||||
}
|
||||
|
||||
// Last() reduces the set of matched elements to the last in the set.
|
||||
// Last reduces the set of matched elements to the last in the set.
|
||||
// It returns a new Selection object, and an empty Selection object if
|
||||
// the selection is empty.
|
||||
func (this *Selection) Last() *Selection {
|
||||
return this.Eq(-1)
|
||||
func (s *Selection) Last() *Selection {
|
||||
return s.Eq(-1)
|
||||
}
|
||||
|
||||
// Eq() reduces the set of matched elements to the one at the specified index.
|
||||
// Eq reduces the set of matched elements to the one at the specified index.
|
||||
// If a negative index is given, it counts backwards starting at the end of the
|
||||
// set. It returns a new Selection object, and an empty Selection object if the
|
||||
// index is invalid.
|
||||
func (this *Selection) Eq(index int) *Selection {
|
||||
func (s *Selection) Eq(index int) *Selection {
|
||||
if index < 0 {
|
||||
index += len(this.Nodes)
|
||||
index += len(s.Nodes)
|
||||
}
|
||||
|
||||
if index >= len(this.Nodes) || index < 0 {
|
||||
return newEmptySelection(this.document)
|
||||
if index >= len(s.Nodes) || index < 0 {
|
||||
return newEmptySelection(s.document)
|
||||
}
|
||||
|
||||
return this.Slice(index, index+1)
|
||||
return s.Slice(index, index+1)
|
||||
}
|
||||
|
||||
// Slice() reduces the set of matched elements to a subset specified by a range
|
||||
// Slice reduces the set of matched elements to a subset specified by a range
|
||||
// of indices.
|
||||
func (this *Selection) Slice(start int, end int) *Selection {
|
||||
func (s *Selection) Slice(start int, end int) *Selection {
|
||||
if start < 0 {
|
||||
start += len(this.Nodes)
|
||||
start += len(s.Nodes)
|
||||
}
|
||||
if end < 0 {
|
||||
end += len(this.Nodes)
|
||||
end += len(s.Nodes)
|
||||
}
|
||||
return pushStack(this, this.Nodes[start:end])
|
||||
return pushStack(s, s.Nodes[start:end])
|
||||
}
|
||||
|
||||
// Get() retrieves the underlying node at the specified index.
|
||||
// Get() without parameter is not implemented, since the node array is available
|
||||
// Get retrieves the underlying node at the specified index.
|
||||
// Get without parameter is not implemented, since the node array is available
|
||||
// on the Selection object.
|
||||
func (this *Selection) Get(index int) *html.Node {
|
||||
func (s *Selection) Get(index int) *html.Node {
|
||||
if index < 0 {
|
||||
index += len(this.Nodes) // Negative index gets from the end
|
||||
index += len(s.Nodes) // Negative index gets from the end
|
||||
}
|
||||
return this.Nodes[index]
|
||||
return s.Nodes[index]
|
||||
}
|
||||
|
||||
// Index() returns the position of the first element within the Selection object
|
||||
// Index returns the position of the first element within the Selection object
|
||||
// relative to its sibling elements.
|
||||
func (this *Selection) Index() int {
|
||||
if len(this.Nodes) > 0 {
|
||||
return newSingleSelection(this.Nodes[0], this.document).PrevAll().Length()
|
||||
func (s *Selection) Index() int {
|
||||
if len(s.Nodes) > 0 {
|
||||
return newSingleSelection(s.Nodes[0], s.document).PrevAll().Length()
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// IndexSelector() returns the position of the first element within the
|
||||
// IndexSelector returns the position of the first element within the
|
||||
// Selection object relative to the elements matched by the selector, or -1 if
|
||||
// not found.
|
||||
func (this *Selection) IndexSelector(selector string) int {
|
||||
if len(this.Nodes) > 0 {
|
||||
sel := this.document.Find(selector)
|
||||
return indexInSlice(sel.Nodes, this.Nodes[0])
|
||||
func (s *Selection) IndexSelector(selector string) int {
|
||||
if len(s.Nodes) > 0 {
|
||||
sel := s.document.Find(selector)
|
||||
return indexInSlice(sel.Nodes, s.Nodes[0])
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// IndexOfNode() returns the position of the specified node within the Selection
|
||||
// IndexOfNode returns the position of the specified node within the Selection
|
||||
// object, or -1 if not found.
|
||||
func (this *Selection) IndexOfNode(node *html.Node) int {
|
||||
return indexInSlice(this.Nodes, node)
|
||||
func (s *Selection) IndexOfNode(node *html.Node) int {
|
||||
return indexInSlice(s.Nodes, node)
|
||||
}
|
||||
|
||||
// IndexOfSelection() returns the position of the first node in the specified
|
||||
// IndexOfSelection returns the position of the first node in the specified
|
||||
// Selection object within this Selection object, or -1 if not found.
|
||||
func (this *Selection) IndexOfSelection(s *Selection) int {
|
||||
if s != nil && len(s.Nodes) > 0 {
|
||||
return indexInSlice(this.Nodes, s.Nodes[0])
|
||||
func (s *Selection) IndexOfSelection(sel *Selection) int {
|
||||
if sel != nil && len(sel.Nodes) > 0 {
|
||||
return indexInSlice(s.Nodes, sel.Nodes[0])
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
Reference in New Issue
Block a user