go-json/decode_context.go

42 lines
613 B
Go
Raw Normal View History

2020-04-23 19:39:20 +03:00
package json
var (
isWhiteSpace = [256]bool{}
)
func init() {
isWhiteSpace[' '] = true
isWhiteSpace['\n'] = true
isWhiteSpace['\t'] = true
isWhiteSpace['\r'] = true
}
2020-04-23 19:39:20 +03:00
type context struct {
cursor int
buf []byte
buflen int
}
func (c *context) setBuf(buf []byte) {
c.buf = buf
c.buflen = len(buf)
c.cursor = 0
}
func (c *context) skipWhiteSpace() int {
buflen := c.buflen
buf := c.buf
for cursor := c.cursor; cursor < buflen; cursor++ {
if isWhiteSpace[buf[cursor]] {
2020-04-23 19:39:20 +03:00
continue
}
c.cursor = cursor
return cursor
}
return buflen
}
func newContext() *context {
return &context{}
}