-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathascii_output.go
133 lines (112 loc) · 3.03 KB
/
ascii_output.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package osg
import (
"bufio"
"strconv"
"strings"
"github.com/flywave/go-osg/model"
)
type AsciiOutputIterator struct {
OutputIterator
ReadyForIndent bool
Indent int
}
func NewAsciiOutputIterator(wt *bufio.Writer) *AsciiOutputIterator {
ot := NewOutputIterator(wt)
return &AsciiOutputIterator{OutputIterator: *ot, ReadyForIndent: false, Indent: 0}
}
func (it *AsciiOutputIterator) writeBlank() {
it.Out.WriteString(" ")
}
func (it *AsciiOutputIterator) indentIfRequired() {
if it.ReadyForIndent {
str := ""
for i := 0; i < it.Indent; i++ {
str += " "
}
it.Out.WriteString(str)
it.ReadyForIndent = false
}
}
func (it *AsciiOutputIterator) WriteBool(b bool) {
it.indentIfRequired()
if b {
it.Out.WriteString("TRUE ")
} else {
it.Out.WriteString("FALSE ")
}
}
func (it *AsciiOutputIterator) WriteChar(val int8) {
it.Out.WriteString(strconv.Itoa(int(val)))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteShort(val int16) {
it.Out.WriteString(strconv.Itoa(int(val)))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteInt(val int32) {
it.Out.WriteString(strconv.Itoa(int(val)))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteLong(val int64) {
it.Out.WriteString(strconv.Itoa(int(val)))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteUChar(val uint8) {
it.Out.WriteString(strconv.FormatUint(uint64(val), 10))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteUShort(val uint16) {
it.Out.WriteString(strconv.FormatUint(uint64(val), 10))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteUInt(val uint32) {
it.Out.WriteString(strconv.FormatUint(uint64(val), 10))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteULong(val uint64) {
it.Out.WriteString(strconv.FormatUint(uint64(val), 10))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteFloat(val float32) {
it.Out.WriteString(strconv.FormatFloat(float64(val), 'f', -1, 32))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteDouble(val float64) {
it.Out.WriteString(strconv.FormatFloat(val, 'f', -1, 64))
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteString(val *string) {
it.Out.WriteString(*val)
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteGlenum(value *model.ObjectGlenum) {
str := GetObjectWrapperManager().FindLookup("GL").GetString(value.Value)
it.WriteString(&str)
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteProperty(value *model.ObjectProperty) {
str := GetObjectWrapperManager().FindLookup(value.Name).GetString(value.Value)
it.WriteString(&str)
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteCharArray(s []byte) {}
func (it *AsciiOutputIterator) WriteMark(mark *model.ObjectMark) {
it.Indent += int(mark.IndentDelta)
it.indentIfRequired()
it.WriteString(&mark.Name)
it.writeBlank()
}
func (it *AsciiOutputIterator) WriteWrappedString(str *string) {
b := strings.Builder{}
for _, c := range *str {
if byte(c) == '"' {
b.WriteByte('\\')
} else if byte(c) == '\\' {
b.WriteByte('\\')
}
b.WriteByte(byte(c))
}
s := "\"" + b.String()
s += "\""
it.WriteString(&s)
}