-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_int.go
151 lines (131 loc) · 3.38 KB
/
convert_int.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
147
148
149
150
151
package cdt
// ToIntE function to convert other type data to int, with error
func (i *convert) ToIntE() (int, error) {
number, err := i.ToFloat64E()
if err != nil {
return 0, err
}
return int(number), nil
}
// ToIntPtr function to convert other type data to int, with pointer
func (i *convert) ToIntPtr() *int {
v, _ := i.ToIntE()
return &v
}
// ToIntPtrE function to convert other type data to int, with pointer and error
func (i *convert) ToIntPtrE() (*int, error) {
v, err := i.ToIntE()
if err != nil {
return nil, err
}
return &v, nil
}
// ToInt function to convert other type data to int
func (i *convert) ToInt() int {
v, _ := i.ToIntE()
return v
}
// ToInt8E function converts data of any type to int8, with error
func (i *convert) ToInt8E() (int8, error) {
number, err := i.ToFloat64E()
if err != nil {
return 0, err
}
return int8(number), err
}
// ToInt8Ptr function to convert other type data to int8, with pointer
func (i *convert) ToInt8Ptr() *int8 {
v, _ := i.ToInt8E()
return &v
}
// ToInt8PtrE function to convert other type data to int8, with pointer and error
func (i *convert) ToInt8PtrE() (*int8, error) {
v, err := i.ToInt8E()
if err != nil {
return nil, err
}
return &v, nil
}
// ToInt8 function to convert other type data to int8
func (i *convert) ToInt8() int8 {
v, _ := i.ToInt8E()
return v
}
// ToInt16E function converts data of any type to int16, with error
func (i *convert) ToInt16E() (int16, error) {
number, err := i.ToFloat64E()
if err != nil {
return 0, err
}
return int16(number), err
}
// ToInt16Ptr function to convert other type data to int16, with pointer
func (i *convert) ToInt16Ptr() *int16 {
v, _ := i.ToInt16E()
return &v
}
// ToInt16PtrE function to convert other type data to int16, with pointer and error
func (i *convert) ToInt16PtrE() (*int16, error) {
v, err := i.ToInt16E()
if err != nil {
return nil, err
}
return &v, nil
}
// ToInt16 function to convert other type data to int16
func (i *convert) ToInt16() int16 {
v, _ := i.ToInt16E()
return v
}
// ToInt32E function to convert other type data to int32, with error
func (i *convert) ToInt32E() (int32, error) {
number, err := i.ToFloat64E()
if err != nil {
return 0, err
}
return int32(number), nil
}
// ToInt32Ptr function to convert other type data to int32, with pointer
func (i *convert) ToInt32Ptr() *int32 {
v, _ := i.ToInt32E()
return &v
}
// ToInt32PtrE function to convert other type data to int32, with pointer and error
func (i *convert) ToInt32PtrE() (*int32, error) {
v, err := i.ToInt32E()
if err != nil {
return nil, err
}
return &v, nil
}
// ToInt32 function to convert other type data to int32
func (i *convert) ToInt32() int32 {
v, _ := i.ToInt32E()
return v
}
// ToInt64E function to convert other type data to int64, with error
func (i *convert) ToInt64E() (int64, error) {
number, err := i.ToFloat64E()
if err != nil {
return 0, err
}
return int64(number), nil
}
// ToInt64Ptr function to convert other type data to int64, with pointer
func (i *convert) ToInt64Ptr() *int64 {
v, _ := i.ToInt64E()
return &v
}
// ToInt64PtrE function to convert other type data to int64, with pointer and error
func (i *convert) ToInt64PtrE() (*int64, error) {
v, err := i.ToInt64E()
if err != nil {
return nil, err
}
return &v, nil
}
// ToInt64 function to convert other type data to int64
func (i *convert) ToInt64() int64 {
v, _ := i.ToInt64E()
return v
}