format.gno

0.78 Kb ยท 46 lines
 1package boards2
 2
 3import (
 4	"strconv"
 5	"strings"
 6)
 7
 8func padLeft(s string, length int) string {
 9	if len(s) >= length {
10		return s
11	}
12	return strings.Repeat(" ", length-len(s)) + s
13}
14
15func padZero(u64 uint64, length int) string {
16	s := strconv.Itoa(int(u64))
17	if len(s) >= length {
18		return s
19	}
20	return strings.Repeat("0", length-len(s)) + s
21}
22
23func indentBody(indent string, body string) string {
24	var (
25		res   string
26		lines = strings.Split(body, "\n")
27	)
28	for i, line := range lines {
29		if i > 0 {
30			res += "\n"
31		}
32		res += indent + line
33	}
34	return res
35}
36
37func summaryOf(text string, length int) string {
38	lines := strings.SplitN(text, "\n", 2)
39	line := lines[0]
40	if len(line) > length {
41		line = line[:(length-3)] + "..."
42	} else if len(lines) > 1 {
43		line = line + "..."
44	}
45	return line
46}