Skip to content

Commit

Permalink
autoprop fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed May 26, 2022
1 parent 99e021d commit 315da99
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
10 changes: 7 additions & 3 deletions hdq.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (p NodeSet) One() (ret NodeSet) {
if _, ok := p.Data.(oneNode); ok {
return p
}
node, err := p.CollectOne(false)
node, err := p.CollectOne__1(false)
if err != nil {
return NodeSet{Err: err}
}
Expand Down Expand Up @@ -495,12 +495,12 @@ func (p NodeSet) ChildrenAsText(doReplace bool) (ret NodeSet) {

// -----------------------------------------------------------------------------

func (p NodeSet) CollectOne(exactly ...bool) (item *html.Node, err error) {
func (p NodeSet) CollectOne__1(exactly bool) (item *html.Node, err error) {
if p.Err != nil {
return nil, p.Err
}
err = ErrNotFound
if exactly != nil && exactly[0] {
if exactly {
p.Data.ForEach(func(node *html.Node) error {
if err == ErrNotFound {
item, err = node, nil
Expand All @@ -518,6 +518,10 @@ func (p NodeSet) CollectOne(exactly ...bool) (item *html.Node, err error) {
return
}

func (p NodeSet) CollectOne__0() (item *html.Node, err error) {
return p.CollectOne__1(false)
}

func (p NodeSet) Collect() (items []*html.Node, err error) {
if p.Err != nil {
return nil, p.Err
Expand Down
53 changes: 39 additions & 14 deletions hdq_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,28 +211,36 @@ func (p NodeSet) Id(v string) (ret NodeSet) {
// ExactText returns text of NodeSet.
// exactlyOne=false: if NodeSet is more than one, returns first node's text (if
// node type is not TextNode, return error).
func (p NodeSet) ExactText(exactlyOne ...bool) (text string, err error) {
node, err := p.CollectOne(exactlyOne...)
func (p NodeSet) ExactText__1(exactlyOne bool) (text string, err error) {
node, err := p.CollectOne__1(exactlyOne)
if err != nil {
return
}
return exactText(node)
}

func (p NodeSet) ExactText__0() (text string, err error) {
return p.ExactText__1(false)
}

// Text returns text of NodeSet.
// exactlyOne=false: if NodeSet is more than one, returns first node's text.
func (p NodeSet) Text(exactlyOne ...bool) (text string, err error) {
node, err := p.CollectOne(exactlyOne...)
func (p NodeSet) Text__1(exactlyOne bool) (text string, err error) {
node, err := p.CollectOne__1(exactlyOne)
if err != nil {
return
}
return textOf(node), nil
}

func (p NodeSet) Text__0() (text string, err error) {
return p.Text__1(false)
}

// ScanInt returns int value of p.Text().
// exactlyOne=false: if NodeSet is more than one, returns first node's value.
func (p NodeSet) ScanInt(format string, exactlyOne ...bool) (v int, err error) {
text, err := p.Text(exactlyOne...)
text, err := p.Text__1(exactlyOne != nil && exactlyOne[0])
if err != nil {
return
}
Expand Down Expand Up @@ -272,8 +280,8 @@ func parseFormat(format string) (prefix, suffix string, err error) {

// UnitedFloat returns UnitedFloat value of p.Text().
// exactlyOne=false: if NodeSet is more than one, returns first node's value.
func (p NodeSet) UnitedFloat(exactlyOne ...bool) (v float64, err error) {
text, err := p.Text(exactlyOne...)
func (p NodeSet) UnitedFloat__1(exactlyOne bool) (v float64, err error) {
text, err := p.Text__1(exactlyOne)
if err != nil {
return
}
Expand All @@ -294,20 +302,28 @@ func (p NodeSet) UnitedFloat(exactlyOne ...bool) (v float64, err error) {
return v * unit, nil
}

func (p NodeSet) UnitedFloat__0() (v float64, err error) {
return p.UnitedFloat__1(false)
}

// Int returns int value of p.Text().
// exactlyOne=false: if NodeSet is more than one, returns first node's value.
func (p NodeSet) Int(exactlyOne ...bool) (v int, err error) {
text, err := p.Text(exactlyOne...)
func (p NodeSet) Int__1(exactlyOne bool) (v int, err error) {
text, err := p.Text__1(exactlyOne)
if err != nil {
return
}
return strconv.Atoi(strings.Replace(text, ",", "", -1))
}

func (p NodeSet) Int__0() (v int, err error) {
return p.Int__1(false)
}

// AttrVal returns attribute value of NodeSet.
// exactlyOne=false: if NodeSet is more than one, returns first node's attribute value.
func (p NodeSet) AttrVal(k string, exactlyOne ...bool) (text string, err error) {
node, err := p.CollectOne(exactlyOne...)
node, err := p.CollectOne__1(exactlyOne != nil && exactlyOne[0])
if err != nil {
return
}
Expand All @@ -316,22 +332,31 @@ func (p NodeSet) AttrVal(k string, exactlyOne ...bool) (text string, err error)

// HrefVal returns href attribute's value of NodeSet.
// exactlyOne=false: if NodeSet is more than one, returns first node's attribute value.
func (p NodeSet) HrefVal(exactlyOne ...bool) (text string, err error) {
return p.AttrVal("href", exactlyOne...)
func (p NodeSet) HrefVal__1(exactlyOne bool) (text string, err error) {
return p.AttrVal("href", exactlyOne)
}

func (p NodeSet) HrefVal__0() (text string, err error) {
return p.AttrVal("href", false)
}

// -----------------------------------------------------------------------------

// Href returns href attribute's value of NodeSet.
func (p NodeSet) Href__0(exactlyOne ...bool) (text string, err error) {
return p.AttrVal("href", exactlyOne...)
func (p NodeSet) Href__0() (text string, err error) {
return p.AttrVal("href", false)
}

// Href returns NodeSet which `href` attribute is `v`.
func (p NodeSet) Href__1(v string) (ret NodeSet) {
return p.Attribute("href", v)
}

// Href returns href attribute's value of NodeSet.
func (p NodeSet) Href__2(exactlyOne bool) (text string, err error) {
return p.AttrVal("href", exactlyOne)
}

func (p NodeSet) Attr__0(k string, exactlyOne ...bool) (text string, err error) {
return p.AttrVal(k, exactlyOne...)
}
Expand Down

0 comments on commit 315da99

Please sign in to comment.