-
Notifications
You must be signed in to change notification settings - Fork 24
/
misc.go
63 lines (50 loc) · 840 Bytes
/
misc.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
52
53
54
55
56
57
58
59
60
61
62
63
package ffmt
import (
"fmt"
"unicode/utf8"
)
// Printf fmt.Printf
var Printf = fmt.Printf
// Println fmt.Println
var Println = fmt.Println
func runeWidth(r rune) int {
switch {
case r == utf8.RuneError || r < '\x20':
return 0
case '\x20' <= r && r < '\u2000':
return 1
case '\u2000' <= r && r < '\uFF61':
return 2
case '\uFF61' <= r && r < '\uFFA0':
return 1
case '\uFFA0' <= r:
return 2
}
return 0
}
func strLen(str string) int {
i := 0
for _, v := range str {
i += runeWidth(v)
}
return i
}
func spac(depth int) string {
b := []byte{}
if depth > 0 {
for i := 0; i != depth; i++ {
b = append(b, Space)
}
}
return string(b)
}
var space = map[int]string{}
func spacing(depth int) string {
v, ok := space[depth]
if ok {
return v
}
v = "\n" + spac(depth-1)
space[depth] = v
return v
}