1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-17 18:06:03 -05:00
OpenDiablo2/StringUtils.go
2019-10-24 11:26:07 -04:00

37 lines
722 B
Go

package OpenDiablo2
import "strconv"
// StringToInt converts a string to an integer
func StringToInt(text string) int {
result, err := strconv.Atoi(text)
if err != nil {
panic(err)
}
return result
}
// StringToUint8 converts a string to an uint8
func StringToUint8(text string) uint8 {
result, err := strconv.Atoi(text)
if err != nil {
panic(err)
}
if result < 0 || result > 255 {
panic("value out of range of byte")
}
return uint8(result)
}
// StringToInt8 converts a string to an int8
func StringToInt8(text string) int8 {
result, err := strconv.Atoi(text)
if err != nil {
panic(err)
}
if result < -128 || result > 122 {
panic("value out of range of a signed byte")
}
return int8(result)
}