summaryrefslogtreecommitdiff
path: root/helpers.go
blob: 85f6113f26f24800c3521bd5dc7d84f2b650944b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// helpers.go
package main

// truncateRunes returns at most n runes from s.
func truncateRunes(s string, n int) string {
	if n <= 0 {
		return ""
	}
	i := 0
	for idx := range s {
		if i == n {
			return s[:idx]
		}
		i++
	}
	return s
}