-
Notifications
You must be signed in to change notification settings - Fork 1
/
iter_object.go
50 lines (47 loc) · 1.08 KB
/
iter_object.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
package jsoniter
// ReadObjectHead tells if there is object field to read
func (iter *Iterator) ReadObjectHead() bool {
c := iter.nextToken()
if c != '{' {
if c == 'n' {
iter.skipThreeBytes('u', 'l', 'l') // null
return false
}
iter.ReportError("ReadArrayHead", "expect {, but found "+string([]byte{c}))
iter.skip(c)
return false
}
c = iter.nextToken()
if c == '}' {
// {} is empty object
return false
}
iter.unreadByte()
return true
}
// ReadObjectMore tells if there is more field to read
func (iter *Iterator) ReadObjectMore() bool {
c := iter.nextToken()
switch c {
case ',':
return true
case '}':
return false
default:
iter.ReportError("ReadObjectMore", "expect , or }, but found "+string([]byte{c}))
return false
}
}
// ReadObjectField will return field name or empty string if not found
func (iter *Iterator) ReadObjectField() string {
var field string
if iter.ReadString(&field) != nil {
return ""
}
c := iter.nextToken()
if c != ':' {
iter.ReportError("ReadObjectField", "expect :, but found "+string([]byte{c}))
return ""
}
return field
}