-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattr_ext.go
More file actions
101 lines (82 loc) · 2.12 KB
/
attr_ext.go
File metadata and controls
101 lines (82 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package htmlparser
import (
"strconv"
)
func (t *HtmlTag) HasAttribute(name string) bool {
_, exists := t.Attributes[name]
return exists
}
func (t *HtmlTag) GetAttribute(name string) *HtmlAttribute {
if attr, exists := t.Attributes[name]; exists {
return &attr
}
return nil
}
func (t *HtmlTag) SetAttribute(name, value string) {
if t.Attributes == nil {
t.Attributes = make(map[string]HtmlAttribute)
}
attr := HtmlAttribute{
Name: name,
Value: value,
IsValueExist: true,
}
t.Attributes[name] = attr
}
func (t *HtmlTag) RemoveAttribute(name string) {
if t.Attributes == nil {
return
}
delete(t.Attributes, name)
}
func (a HtmlAttribute) AsString() string {
return a.Value
}
func (a HtmlAttribute) AsBool() (bool, error) {
return strconv.ParseBool(a.Value)
}
func (a HtmlAttribute) AsInt() (int, error) {
v, err := strconv.ParseInt(a.Value, 10, 0)
return int(v), err
}
func (a HtmlAttribute) AsInt8() (int8, error) {
v, err := strconv.ParseInt(a.Value, 10, 8)
return int8(v), err
}
func (a HtmlAttribute) AsInt16() (int16, error) {
v, err := strconv.ParseInt(a.Value, 10, 16)
return int16(v), err
}
func (a HtmlAttribute) AsInt32() (int32, error) {
v, err := strconv.ParseInt(a.Value, 10, 32)
return int32(v), err
}
func (a HtmlAttribute) AsInt64() (int64, error) {
return strconv.ParseInt(a.Value, 10, 64)
}
func (a HtmlAttribute) AsUint() (uint, error) {
v, err := strconv.ParseUint(a.Value, 10, 0)
return uint(v), err
}
func (a HtmlAttribute) AsUint8() (uint8, error) {
v, err := strconv.ParseUint(a.Value, 10, 8)
return uint8(v), err
}
func (a HtmlAttribute) AsUint16() (uint16, error) {
v, err := strconv.ParseUint(a.Value, 10, 16)
return uint16(v), err
}
func (a HtmlAttribute) AsUint32() (uint32, error) {
v, err := strconv.ParseUint(a.Value, 10, 32)
return uint32(v), err
}
func (a HtmlAttribute) AsUint64() (uint64, error) {
return strconv.ParseUint(a.Value, 10, 64)
}
func (a HtmlAttribute) AsFloat32() (float32, error) {
v, err := strconv.ParseFloat(a.Value, 32)
return float32(v), err
}
func (a HtmlAttribute) AsFloat64() (float64, error) {
return strconv.ParseFloat(a.Value, 64)
}