This commit is contained in:
Andreas Neue 2016-01-10 18:45:21 +01:00
commit 51b7e05596
11 changed files with 1214 additions and 0 deletions

33
util/util.go Normal file
View file

@ -0,0 +1,33 @@
// vim:ts=4:sts=4:sw=4:noet:tw=72
package util
import (
"bytes"
"strconv"
)
func NumberToString(n int, sep rune) string {
start := 0
var buf bytes.Buffer
s := strconv.Itoa(n)
if n < 0 {
start = 1
buf.WriteByte('-')
}
l := len(s)
ci := 3 - ((l - start) % 3)
if ci == 3 {
ci = 0
}
for i := start; i < l; i++ {
if ci == 3 {
buf.WriteRune(sep)
ci = 0
}
ci++
buf.WriteByte(s[i])
}
return buf.String()
}