forked from go-pg/pg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhstore_parser.go
65 lines (52 loc) · 973 Bytes
/
hstore_parser.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
package types
import (
"errors"
"io"
"github.com/go-pg/pg/internal/parser"
)
var endOfHstore = errors.New("pg: end of hstore")
type hstoreParser struct {
p parser.StreamingParser
}
func newHstoreParser(rd Reader) *hstoreParser {
return &hstoreParser{
p: parser.NewStreamingParser(rd),
}
}
func (p *hstoreParser) NextKey() ([]byte, error) {
err := p.p.SkipByte('"')
if err != nil {
if err == io.EOF {
return nil, endOfHstore
}
return nil, err
}
key, err := p.p.ReadSubstring()
if err != nil {
return nil, err
}
err = p.p.SkipByte('=')
if err != nil {
return nil, err
}
err = p.p.SkipByte('>')
if err != nil {
return nil, err
}
return key, nil
}
func (p *hstoreParser) NextValue() ([]byte, error) {
err := p.p.SkipByte('"')
if err != nil {
return nil, err
}
value, err := p.p.ReadSubstring()
if err != nil {
return nil, err
}
err = p.p.SkipByte(',')
if err == nil {
_ = p.p.SkipByte(' ')
}
return value, nil
}