// FmtInts formats the integer slice as a string each item separated by sep.
funcFmtInts(ints[]int,sepstring)string{
varoutbytes.Buffer
fori,val:=rangeints{
ifi>0{
out.WriteString(sep)
}
out.WriteString(Itoa(val))
}
returnout.String()
}
// FmtInts64 formats the integer slice as a string each item separated by sep.
funcFmtInts64(ints[]int64,sepstring)string{
varoutbytes.Buffer
fori,val:=rangeints{
ifi>0{
out.WriteString(sep)
}
out.WriteString(Itoa64(val))
}
returnout.String()
}
// MustAtoi parses string s as an integer. Method panics if the conversion fails.
funcMustAtoi(sstring)int{
vari,err=strconv.Atoi(s)
ifnil!=err{
panic("error converting string to int")
}
returni
}
// MustAtoi64 parses string s as an integer. Method panics if the conversion fails.
funcMustAtoi64(sstring)int64{
vari,err=strconv.ParseInt(s,10,64)
ifnil!=err{
panic("error converting string to int")
}
returni
}
// MustAstois parses the strings as integers. Method panics if one of the conversion fails.
funcMustAstois(s...string)[]int{
varres=make([]int,len(s))
fori:=ranges{
res[i]=MustAtoi(s[i])
}
returnres
}
// MustAstois64 parses the strings as integers. Method panics if one of the conversion fails.
funcMustAstois64(s...string)[]int64{
varres=make([]int64,len(s))
fori:=ranges{
res[i]=MustAtoi64(s[i])
}
returnres
}
// SplitInts splits the string s by separator sep, converts every part to an integer and returns all the integers as a slice. Method panics if one of the conversion fails.
funcSplitInts(s,sepstring)[]int{
varnumbers=strings.Split(s,sep)
varints=make([]int,len(numbers))
fori,n:=rangenumbers{
ints[i]=MustAtoi(n)
}
returnints
}
// SplitInts64 splits the string s by separator sep, converts every part to an integer and returns all the integers as a slice. Method panics if one of the conversion fails.