Completed
Push — main ( d205ff...d7083f )
by Yume
24s queued 13s
created

utils.ConvertInt32ToStr   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package utils
2
3
import (
4
	"strconv"
5
)
6
7
const (
8
	base10  = 10
9
	bitSize = 32
10
)
11
12
// ConvertStrToUInt converts a string to an unsigned integer.
13
func ConvertStrToUInt(str string) (uint, error) {
14
	number, err := strconv.ParseUint(str, base10, bitSize)
15
	if err != nil {
16
		return 0, err
17
	}
18
	return uint(number), nil
19
}
20
21
// ConvertUIntToStr converts an unsigned integer to a string.
22
func ConvertUIntToStr(number uint) string {
23
	return strconv.FormatUint(uint64(number), base10)
24
}
25
26
// ConvertIntToStr converts an integer to a string.
27
func ConvertIntToStr(number int) string {
28
	return strconv.FormatInt(int64(number), base10)
29
}
30
31
// ConvertInt32ToStr converts an int32 to a string.
32
func ConvertInt32ToStr(number int32) string {
33
	return strconv.FormatInt(int64(number), base10)
34
}
35
36
// ConvertStrToInt converts a string to an integer.
37
func ConvertStrToInt(str string) (int, error) {
38
	number, err := strconv.ParseInt(str, base10, bitSize)
39
	if err != nil {
40
		return 0, err
41
	}
42
	return int(number), nil
43
}
44
45
// ConvertStrToInt32 converts a string to an int32.
46
func ConvertStrToInt32(str string) (int32, error) {
47
	number, err := strconv.ParseInt(str, base10, bitSize)
48
	if err != nil {
49
		return 0, err
50
	}
51
	return int32(number), nil
52
}
53