forked from mirror/go-json
Fix calculating of length for stream decoder
This commit is contained in:
parent
3ec642d31f
commit
23081eadad
|
@ -68,10 +68,7 @@ func (d *mapDecoder) decodeStream(s *stream, depth int64, p unsafe.Pointer) erro
|
|||
return err
|
||||
}
|
||||
s.skipWhiteSpace()
|
||||
if s.char() == nul {
|
||||
s.read()
|
||||
}
|
||||
if s.char() != ':' {
|
||||
if !s.equalChar(':') {
|
||||
return errExpected("colon after object key", s.totalOffset())
|
||||
}
|
||||
s.cursor++
|
||||
|
@ -81,15 +78,12 @@ func (d *mapDecoder) decodeStream(s *stream, depth int64, p unsafe.Pointer) erro
|
|||
}
|
||||
mapassign(d.mapType, mapValue, k, v)
|
||||
s.skipWhiteSpace()
|
||||
if s.char() == nul {
|
||||
s.read()
|
||||
}
|
||||
if s.char() == '}' {
|
||||
if s.equalChar('}') {
|
||||
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
||||
s.cursor++
|
||||
return nil
|
||||
}
|
||||
if s.char() != ',' {
|
||||
if !s.equalChar(',') {
|
||||
return errExpected("comma after object value", s.totalOffset())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,15 @@ func (s *stream) char() byte {
|
|||
return s.buf[s.cursor]
|
||||
}
|
||||
|
||||
func (s *stream) equalChar(c byte) bool {
|
||||
cur := s.buf[s.cursor]
|
||||
if cur == nul {
|
||||
s.read()
|
||||
cur = s.buf[s.cursor]
|
||||
}
|
||||
return cur == c
|
||||
}
|
||||
|
||||
func (s *stream) stat() ([]byte, int64, unsafe.Pointer) {
|
||||
return s.buf, s.cursor, (*sliceHeader)(unsafe.Pointer(&s.buf)).data
|
||||
}
|
||||
|
|
|
@ -127,7 +127,8 @@ func decodeUnicode(s *stream) error {
|
|||
unicode := []byte(string(r))
|
||||
unicodeLen := int64(len(unicode))
|
||||
s.buf = append(append(s.buf[:s.cursor-1], unicode...), s.buf[s.cursor+offset:]...)
|
||||
s.length = int64(len(s.buf))
|
||||
unicodeOrgLen := offset - 1
|
||||
s.length = s.length - (backSlashAndULen + (unicodeOrgLen - unicodeLen))
|
||||
s.cursor = s.cursor - backSlashAndULen + unicodeLen
|
||||
return nil
|
||||
}
|
||||
|
@ -163,6 +164,7 @@ RETRY:
|
|||
return errUnexpectedEndOfJSON("string", s.totalOffset())
|
||||
}
|
||||
s.buf = append(s.buf[:s.cursor-1], s.buf[s.cursor:]...)
|
||||
s.length--
|
||||
s.cursor--
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue