forked from nanjishidu/gomini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strconv.go
146 lines (123 loc) · 3.02 KB
/
strconv.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package gomini
import (
"strconv"
)
func GetStrBool(strv string, def ...bool) (bool, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
return strconv.ParseBool(strv)
}
func GetStrFloat(strv string, def ...float64) (float64, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
return strconv.ParseFloat(strv, 32)
}
func GetStrUint(strv string, def ...uint) (uint, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
a, err := strconv.Atoi(strv)
return uint(a), err
}
func GetStrInt(strv string, def ...int) (int, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
a, err := strconv.Atoi(strv)
return int(a), err
}
func GetStrInt8(strv string, def ...int8) (int8, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
a, err := strconv.ParseInt(strv, 10, 8)
return int8(a), err
}
func GetStrUint8(strv string, def ...uint8) (uint8, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
ret, err := strconv.ParseUint(strv, 10, 8)
return uint8(ret), err
}
func GetStrInt16(strv string, def ...int16) (int16, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
a, err := strconv.ParseInt(strv, 10, 16)
return int16(a), err
}
func GetStrUint16(strv string, def ...uint16) (uint16, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
ret, err := strconv.ParseUint(strv, 10, 16)
return uint16(ret), err
}
func GetStrInt32(strv string, def ...int32) (int32, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
a, err := strconv.ParseInt(strv, 10, 32)
return int32(a), err
}
func GetStrUint32(strv string, def ...uint32) (uint32, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
ret, err := strconv.ParseUint(strv, 10, 32)
return uint32(ret), err
}
func GetStrInt64(strv string, def ...int64) (int64, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
ret, err := strconv.ParseInt(strv, 10, 64)
return ret, err
}
func GetStrUint64(strv string, def ...uint64) (uint64, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
ret, err := strconv.ParseUint(strv, 10, 64)
return ret, err
}
func GetStrFloat64(strv string, def ...float64) (float64, error) {
if len(strv) == 0 && len(def) > 0 {
return def[0], nil
}
ret, err := strconv.ParseFloat(strv, 64)
return ret, err
}
func GetUint64Str(d uint64) string {
return strconv.FormatUint(d, 10)
}
func GetInt64Str(d int64) string {
return strconv.FormatInt(d, 10)
}
func GetUint32Str(d uint32) string {
return strconv.Itoa(int(d))
}
func GetInt32Str(d int32) string {
return strconv.Itoa(int(d))
}
func GetUint16Str(d uint16) string {
return strconv.Itoa(int(d))
}
func GetInt16Str(d int16) string {
return strconv.Itoa(int(d))
}
func GetUint8Str(d uint8) string {
return strconv.Itoa(int(d))
}
func GetInt8Str(d int8) string {
return strconv.Itoa(int(d))
}
func GetUintStr(d uint) string {
return strconv.Itoa(int(d))
}
func GetIntStr(d int) string {
return strconv.Itoa(d)
}