micro/src/util.go

31 lines
513 B
Go
Raw Normal View History

2016-03-18 00:27:57 +03:00
package main
import (
"unicode/utf8"
)
2016-03-19 03:40:00 +03:00
// Count returns the length of a string in runes
func Count(s string) int {
2016-03-18 00:27:57 +03:00
return utf8.RuneCountInString(s)
}
2016-03-19 03:40:00 +03:00
// NumOccurences counts the number of occurences of a byte in a string
func NumOccurences(s string, c byte) int {
2016-03-18 00:27:57 +03:00
var n int
for i := 0; i < len(s); i++ {
if s[i] == c {
n++
}
}
return n
}
2016-03-19 03:40:00 +03:00
// EmptyString returns an empty string n spaces long
func EmptyString(n int) string {
2016-03-18 00:27:57 +03:00
var str string
for i := 0; i < n; i++ {
str += " "
}
return str
}