-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_helper.go
102 lines (94 loc) · 1.64 KB
/
common_helper.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
package phpserialize
import (
"strconv"
)
func PhpValueString(p PhpValue) (res string) {
res, _ = p.(string)
return
}
func PhpValueBool(p PhpValue) (res bool) {
switch p.(type) {
case bool:
res, _ = p.(bool)
case string:
str, _ := p.(string)
res, _ = strconv.ParseBool(str)
}
return
}
func PhpValueInt(p PhpValue) (res int) {
switch p.(type) {
case int:
res, _ = p.(int)
case int8:
intVal, _ := p.(int8)
res = int(intVal)
case int16:
intVal, _ := p.(int16)
res = int(intVal)
case int32:
intVal, _ := p.(int32)
res = int(intVal)
case int64:
intVal, _ := p.(int64)
res = int(intVal)
case uint:
intVal, _ := p.(uint)
res = int(intVal)
case uint8:
intVal, _ := p.(uint8)
res = int(intVal)
case uint16:
intVal, _ := p.(uint16)
res = int(intVal)
case uint32:
intVal, _ := p.(uint32)
res = int(intVal)
case uint64:
intVal, _ := p.(uint64)
res = int(intVal)
case string:
str, _ := p.(string)
res, _ = strconv.Atoi(str)
}
return
}
func PhpValueInt64(p PhpValue) (res int64) {
switch p.(type) {
case int64:
res = p.(int64)
default:
res = int64(PhpValueInt(p))
}
return
}
func PhpValueUInt(p PhpValue) (res uint) {
switch p.(type) {
case uint:
res = p.(uint)
default:
res = uint(PhpValueInt(p))
}
return
}
func PhpValueUInt64(p PhpValue) (res uint64) {
switch p.(type) {
case uint64:
res = p.(uint64)
default:
res = uint64(PhpValueInt(p))
}
return
}
func PhpValueFloat64(p PhpValue) (res float64) {
switch p.(type) {
case float64:
res, _ = p.(float64)
case string:
str, _ := p.(string)
res, _ = strconv.ParseFloat(str, 64)
default:
return float64(PhpValueInt(p))
}
return
}