-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstream_object.go
More file actions
37 lines (34 loc) · 911 Bytes
/
stream_object.go
File metadata and controls
37 lines (34 loc) · 911 Bytes
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
package jsoniter
// WriteObjectHead write { with possible indention
func (stream *Stream) WriteObjectHead() {
stream.indentCount += 1
stream.writeByte('{')
stream.writeIndent()
}
// WriteObjectField write "field": with possible indention
func (stream *Stream) WriteObjectField(field string) {
stream.WriteString(field)
if stream.withIndent() {
stream.writeTwoBytes(':', ' ')
} else {
stream.writeByte(':')
}
}
// WriteObjectTail write } with possible indention
func (stream *Stream) WriteObjectTail() {
lookBack := len(stream.buf) - 1 - len(stream.Prefix) - len(stream.Indent)*stream.indentCount
if stream.withIndent() {
lookBack -= 1
}
lookBackChar := stream.buf[lookBack]
stream.indentCount -= 1
if lookBackChar == ',' {
stream.buf = stream.buf[:lookBack]
}
if lookBackChar == '{' {
stream.buf = stream.buf[:lookBack+1]
} else {
stream.writeIndent()
}
stream.writeByte('}')
}