-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
51 lines (40 loc) · 843 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package minigo
import (
"strings"
"unicode/utf8"
)
func minInt(i, j int) int {
if i < j {
return i
}
return j
}
func maxInt(i, j int) int {
if i > j {
return i
}
return j
}
func WrapperLargeurNormale(text string) []string {
return Wrapper(text, ColonnesSimple)
}
func WrapperLargeurDouble(text string) []string {
return Wrapper(text, ColonnesDouble)
}
func Wrapper(text string, size int) (wrapped []string) {
var words []string
length := 0
for _, s := range strings.Split(text, " ") {
if length+utf8.RuneCountInString(s)+1 >= size {
wrapped = append(wrapped, strings.Join(words, " "))
length = 0
words = []string{}
}
length += utf8.RuneCountInString(s) + 1 // the size of the space
words = append(words, s)
}
if len(words) > 0 {
wrapped = append(wrapped, strings.Join(words, " "))
}
return
}