]> git.lizzy.rs Git - micro.git/blob - src/util.go
Update readme
[micro.git] / src / util.go
1 package main
2
3 import (
4         "unicode/utf8"
5 )
6
7 // Count returns the length of a string in runes
8 func Count(s string) int {
9         return utf8.RuneCountInString(s)
10 }
11
12 // NumOccurences counts the number of occurences of a byte in a string
13 func NumOccurences(s string, c byte) int {
14         var n int
15         for i := 0; i < len(s); i++ {
16                 if s[i] == c {
17                         n++
18                 }
19         }
20         return n
21 }
22
23 // EmptyString returns an empty string n spaces long
24 func EmptyString(n int) string {
25         var str string
26         for i := 0; i < n; i++ {
27                 str += " "
28         }
29         return str
30 }