41 lines
754 B
Go
41 lines
754 B
Go
package util
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func PrependToSliceStr(strs *[]string, prefix string) {
|
|
for i, elm := range *strs {
|
|
(*strs)[i] = prefix + elm
|
|
}
|
|
}
|
|
|
|
func AppendToSliceStr(strs *[]string, suffix string) {
|
|
for i, elm := range *strs {
|
|
(*strs)[i] = elm + suffix
|
|
}
|
|
}
|
|
|
|
func Str2int64(str string, base int, fallback int64) int64 {
|
|
str = strings.TrimSuffix(str, "\n")
|
|
num, err := strconv.ParseInt(str, base, 64)
|
|
if err != nil {
|
|
num = fallback
|
|
}
|
|
return num
|
|
}
|
|
|
|
func Str2int(str string, base int, fallback int) int {
|
|
return int(Str2int64(str, base, int64(fallback)))
|
|
}
|
|
|
|
func CastStrings2ints(strs *[]string) []int {
|
|
a := make([]int, len(*strs))
|
|
for i, elm := range *strs {
|
|
var f int = Str2int(elm, 10, 0)
|
|
a[i] = f
|
|
}
|
|
return a
|
|
}
|