-
Notifications
You must be signed in to change notification settings - Fork 0
/
boolean.go
61 lines (47 loc) · 882 Bytes
/
boolean.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
package jsonextract
import "io"
var (
trueChars = []rune{'r', 'u', 'e'}
falseChars = []rune{'a', 'l', 's', 'e'}
)
func parseBool(r reader, firstC rune) (*JSON, error) {
json := &JSON{kind: Boolean}
json.push(firstC)
// true bool
if firstC == 't' {
for _, c := range trueChars {
char, _, err := r.ReadRune()
if err != nil {
if err == io.EOF {
return nil, errInvalid
}
return nil, err
}
if char != c {
return nil, errInvalid
}
json.push(char)
}
json.val = true
return json, nil
}
// false bool
if firstC == 'f' {
for _, c := range falseChars {
char, _, err := r.ReadRune()
if err != nil {
if err == io.EOF {
return nil, errInvalid
}
return nil, err
}
if char != c {
return nil, errInvalid
}
json.push(char)
}
json.val = false
return json, nil
}
return json, nil
}