|
|
@@ -1,141 +1,9 @@
|
|
|
package jsoniter
|
|
|
|
|
|
import (
|
|
|
- "io"
|
|
|
"strconv"
|
|
|
)
|
|
|
|
|
|
-type stringLazyAny struct {
|
|
|
- baseAny
|
|
|
- cfg *frozenConfig
|
|
|
- buf []byte
|
|
|
- err error
|
|
|
- cache string
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ValueType() ValueType {
|
|
|
- return String
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) fillCache() {
|
|
|
- if any.err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- any.cache = iter.ReadString()
|
|
|
- if iter.Error != io.EOF {
|
|
|
- iter.reportError("stringLazyAny", "there are bytes left")
|
|
|
- }
|
|
|
- any.err = iter.Error
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) LastError() error {
|
|
|
- return any.err
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToBool() bool {
|
|
|
- str := any.ToString()
|
|
|
- if str == "false" {
|
|
|
- return false
|
|
|
- }
|
|
|
- for _, c := range str {
|
|
|
- switch c {
|
|
|
- case ' ', '\n', '\r', '\t':
|
|
|
- default:
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToInt() int {
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- iter.head++
|
|
|
- val := iter.ReadInt()
|
|
|
- any.err = iter.Error
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToInt32() int32 {
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- iter.head++
|
|
|
- val := iter.ReadInt32()
|
|
|
- any.err = iter.Error
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToInt64() int64 {
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- iter.head++
|
|
|
- val := iter.ReadInt64()
|
|
|
- any.err = iter.Error
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToUint() uint {
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- iter.head++
|
|
|
- val := iter.ReadUint()
|
|
|
- any.err = iter.Error
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToUint32() uint32 {
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- iter.head++
|
|
|
- val := iter.ReadUint32()
|
|
|
- any.err = iter.Error
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToUint64() uint64 {
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- iter.head++
|
|
|
- val := iter.ReadUint64()
|
|
|
- any.err = iter.Error
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToFloat32() float32 {
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- iter.head++
|
|
|
- val := iter.ReadFloat32()
|
|
|
- any.err = iter.Error
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToFloat64() float64 {
|
|
|
- iter := any.cfg.BorrowIterator(any.buf)
|
|
|
- defer any.cfg.ReturnIterator(iter)
|
|
|
- iter.head++
|
|
|
- val := iter.ReadFloat64()
|
|
|
- any.err = iter.Error
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) ToString() string {
|
|
|
- var val string
|
|
|
- any.err = any.cfg.Unmarshal(any.buf, &val)
|
|
|
- return val
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) WriteTo(stream *Stream) {
|
|
|
- stream.Write(any.buf)
|
|
|
-}
|
|
|
-
|
|
|
-func (any *stringLazyAny) GetInterface() interface{} {
|
|
|
- any.fillCache()
|
|
|
- return any.cache
|
|
|
-}
|
|
|
-
|
|
|
type stringAny struct {
|
|
|
baseAny
|
|
|
err error
|