-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathfiglet-parser.go
52 lines (44 loc) · 1.18 KB
/
figlet-parser.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
package figure
import (
"strconv"
"strings"
)
const signature = "flf2"
const reverseFlag = "1"
var charDelimiters = [3]string{"@", "#", "$"}
var hardblanksBlacklist = [2]byte{'a', '2'}
func getHeight(metadata string) int {
datum := strings.Fields(metadata)[1]
height, _ := strconv.Atoi(datum)
return height
}
func getBaseline(metadata string) int {
datum := strings.Fields(metadata)[2]
baseline, _ := strconv.Atoi(datum)
return baseline
}
func getHardblank(metadata string) byte {
datum := strings.Fields(metadata)[0]
hardblank := datum[len(datum)-1]
if hardblank == hardblanksBlacklist[0] || hardblank == hardblanksBlacklist[1] {
return ' '
} else {
return hardblank
}
}
func getReverse(metadata string) bool {
data := strings.Fields(metadata)
return len(data) > 6 && data[6] == reverseFlag
}
func lastCharLine(text string, height int) bool {
endOfLine, length := " ", 2
if height == 1 && len(text) > 0 {
length = 1
}
if len(text) >= length {
endOfLine = text[len(text)-length:]
}
return endOfLine == strings.Repeat(charDelimiters[0], length) ||
endOfLine == strings.Repeat(charDelimiters[1], length) ||
endOfLine == strings.Repeat(charDelimiters[2], length)
}