139 lines
2.8 KiB
Go
139 lines
2.8 KiB
Go
package util
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
func mustParseInt(value string, bits int) int64 {
|
|
if parsed, err := strconv.ParseInt(value, 10, bits); err != nil {
|
|
panic(err)
|
|
} else {
|
|
return parsed
|
|
}
|
|
}
|
|
|
|
func mustParseUint(value string, bits int) uint64 {
|
|
if parsed, err := strconv.ParseUint(value, 10, bits); err != nil {
|
|
panic(err)
|
|
} else {
|
|
return parsed
|
|
}
|
|
}
|
|
|
|
func ParseUint8(value string) (ret *uint8) {
|
|
|
|
if parsed, err := strconv.ParseUint(value, 10, 8); err == nil {
|
|
ret = new(uint8)
|
|
*ret = uint8(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseUint16(value string) (ret *uint16) {
|
|
|
|
if parsed, err := strconv.ParseUint(value, 10, 16); err == nil {
|
|
ret = new(uint16)
|
|
*ret = uint16(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseUint32(value string) (ret *uint32) {
|
|
|
|
if parsed, err := strconv.ParseUint(value, 10, 32); err == nil {
|
|
ret = new(uint32)
|
|
*ret = uint32(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseUint64(value string) (ret *uint64) {
|
|
|
|
if parsed, err := strconv.ParseUint(value, 10, 64); err == nil {
|
|
ret = new(uint64)
|
|
*ret = uint64(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseUint(value string) (ret *uint) {
|
|
|
|
if parsed, err := strconv.ParseUint(value, 10, 0); err == nil {
|
|
ret = new(uint)
|
|
*ret = uint(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseInt8(value string) (ret *int8) {
|
|
|
|
if parsed, err := strconv.ParseInt(value, 10, 8); err == nil {
|
|
ret = new(int8)
|
|
*ret = int8(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseInt16(value string) (ret *int16) {
|
|
|
|
if parsed, err := strconv.ParseInt(value, 10, 16); err == nil {
|
|
ret = new(int16)
|
|
*ret = int16(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseInt32(value string) (ret *int32) {
|
|
|
|
if parsed, err := strconv.ParseInt(value, 10, 32); err == nil {
|
|
ret = new(int32)
|
|
*ret = int32(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseInt64(value string) (ret *int64) {
|
|
|
|
if parsed, err := strconv.ParseInt(value, 10, 64); err == nil {
|
|
ret = new(int64)
|
|
*ret = int64(parsed)
|
|
}
|
|
return
|
|
}
|
|
func ParseInt(value string) (ret *int) {
|
|
if parsed, err := strconv.ParseInt(value, 10, 0); err == nil {
|
|
ret = new(int)
|
|
*ret = int(parsed)
|
|
}
|
|
return
|
|
}
|
|
|
|
func ParseUint8Must(value string) uint8 {
|
|
return uint8(mustParseUint(value, 8))
|
|
}
|
|
func ParseUint16Must(value string) uint16 {
|
|
return uint16(mustParseUint(value, 16))
|
|
}
|
|
func ParseUint32Must(value string) uint32 {
|
|
return uint32(mustParseUint(value, 32))
|
|
}
|
|
func ParseUint64Must(value string) uint64 {
|
|
return mustParseUint(value, 64)
|
|
}
|
|
|
|
func ParseUintMust(value string) uint {
|
|
return uint(mustParseUint(value, 0))
|
|
}
|
|
|
|
func ParseInt8Must(value string) int8 {
|
|
return int8(mustParseInt(value, 8))
|
|
}
|
|
|
|
func ParseInt16Must(value string) int16 {
|
|
return int16(mustParseInt(value, 16))
|
|
}
|
|
|
|
func ParseInt32Must(value string) int32 {
|
|
return int32(mustParseInt(value, 32))
|
|
}
|
|
|
|
func ParseInt64Must(value string) int64 {
|
|
return mustParseInt(value, 64)
|
|
}
|
|
|
|
func ParseIntMust(value string) int {
|
|
return int(mustParseInt(value, 0))
|
|
}
|