-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfields.go
113 lines (98 loc) · 1.75 KB
/
fields.go
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
102
103
104
105
106
107
108
109
110
111
112
113
package browscap
import (
"strconv"
"reflect"
"unsafe"
"hash/crc32"
)
var crc = crc32.NewIEEE()
type browscapField int
const (
fPropertyName browscapField = iota
fMasterParent
fLiteMode
fParent
fComment
fBrowser
fBrowserType
fBrowserBits
fBrowser_Maker
fBrowser_Modus
fVersion
fMajorVer
fMinorVer
fPlatform
fPlatform_Version
fPlatform_Description
fPlatformBits
fPlatform_Maker
fAlpha
fBeta
fWin16
fWin32
fWin64
fFrames
fIFrames
fTables
fCookies
fBackgroundSounds
fJavaScript
fVBScript
fJavaApplets
fActiveXControls
fIsMobileDevice
fIsTablet
fisSyndicationReader
fCrawler
fIsFake
fIsAnonymized
fIsModified
fCssVersion
fAolVersion
fDevice_Name
fDevice_Maker
fDeviceType
fDevicePointingMethod
fDevice_Code_Name
fDevice_Brand_Name
fRenderingEngine_Name
fRenderingEngine_Version
fRenderingEngine_Description
fRenderingEngine_Maker
)
func (nf browscapField) Is(opts []string) bool {
if len(opts) > int(nf) {
if ok, _ := strconv.ParseBool(opts[int(nf)]); ok {
return true
}
}
return false
}
func (nf browscapField) Hash(opts []string) (string, uint32) {
crc.Reset()
s := nf.GetString(opts)
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh := reflect.SliceHeader{Data: sh.Data, Len: sh.Len, Cap: sh.Len}
crc.Write(*(*[]byte)(unsafe.Pointer(&bh)))
return s, crc.Sum32()
}
func (nf browscapField) Equals(opts []string, v string) bool {
if len(opts) > int(nf) {
return opts[int(nf)] == v
}
return false
}
func (nf browscapField) GetString(opts []string) string {
if len(opts) > int(nf) {
return opts[int(nf)]
}
return ""
}
func (nf browscapField) GetInt(opts []string) int {
if v := nf.GetString(opts); v != "" {
if i, err := strconv.Atoi(v); err == nil {
return i
}
}
return 0
}