infra
/
goutils
Archived
1
0
Fork 0
This repository has been archived on 2022-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
goutils/misc/converse.go

127 lines
3.6 KiB
Go

package misc
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)) }
func FormatUint8(value uint8) string { return strconv.FormatUint(uint64(value), 10) }
func FormatUint16(value uint16) string { return strconv.FormatUint(uint64(value), 10) }
func FormatUint32(value uint32) string { return strconv.FormatUint(uint64(value), 10) }
func FormatUint64(value uint64) string { return strconv.FormatUint(value, 10) }
func FormatUint(value uint) string { return strconv.FormatUint(uint64(value), 10) }
func FormatInt8(value int8) string { return strconv.FormatInt(int64(value), 10) }
func FormatInt16(value int16) string { return strconv.FormatInt(int64(value), 10) }
func FormatInt32(value int32) string { return strconv.FormatInt(int64(value), 10) }
func FormatInt64(value int64) string { return strconv.FormatInt(value, 10) }
func FormatInt(value int) string { return strconv.FormatInt(int64(value), 10) }