Files
flokatirc/util/util.go
T

60 lines
1018 B
Go
Raw Normal View History

2016-01-11 07:18:52 +01:00
// vi:ts=4:sts=4:sw=4:noet:tw=72
2016-01-10 18:45:21 +01:00
package util
import (
"bytes"
"strconv"
2016-03-19 23:49:41 +01:00
"strings"
2016-01-10 18:45:21 +01:00
)
2016-02-16 00:17:42 +01:00
func ToInt(v interface{}) int {
switch v.(type) {
case int:
return v.(int)
case float64:
return int(v.(float64))
case string:
ret, _ := strconv.Atoi(v.(string))
return ret
default:
return 0
}
}
2016-01-10 18:45:21 +01:00
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()
}
2016-02-16 00:17:42 +01:00
2016-03-19 23:49:41 +01:00
func ReplaceUmlauts(s string) string {
ret := strings.Replace(s, "Ä", "Ae", -1)
ret = strings.Replace(ret, "Ö", "Oe", -1)
ret = strings.Replace(ret, "Ü", "Ue", -1)
ret = strings.Replace(ret, "ä", "ae", -1)
ret = strings.Replace(ret, "ö", "oe", -1)
ret = strings.Replace(ret, "ü", "ue", -1)
ret = strings.Replace(ret, "ß", "ss", -1)
return ret
}