-
Notifications
You must be signed in to change notification settings - Fork 17
/
store.go
64 lines (50 loc) · 1.25 KB
/
store.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
package ujson
import (
"errors"
"strconv"
)
type simpleStore struct{}
func (s simpleStore) NewObject() (interface{}, error) {
return make(map[string]interface{}), nil
}
func (s simpleStore) NewArray() (interface{}, error) {
a := make([]interface{}, 0)
return &a, nil
}
func (s simpleStore) ObjectAddKey(mi interface{}, k interface{}, v interface{}) error {
ks := k.(string)
m := mi.(map[string]interface{})
m[ks] = v
return nil
}
func (s simpleStore) ArrayAddItem(ai interface{}, v interface{}) error {
a := ai.(*[]interface{})
*a = append(*a, v)
return nil
}
func (s simpleStore) NewString(b []byte) (interface{}, error) {
str, ok := unquote(b)
if !ok {
return nil, errors.New("Failed to unquote string " + string(b))
}
return str, nil
}
type numeric []byte
func (n numeric) Int64() (int64, error) {
return strconv.ParseInt(string(n), 10, 64)
}
func (n numeric) Float64() (float64, error) {
return strconv.ParseFloat(string(n), 64)
}
func (s simpleStore) NewNumeric(b []byte) (interface{}, error) {
return numeric(b), nil
}
func (s simpleStore) NewTrue() (interface{}, error) {
return true, nil
}
func (s simpleStore) NewFalse() (interface{}, error) {
return false, nil
}
func (s simpleStore) NewNull() (interface{}, error) {
return nil, nil
}