mirror of
https://github.com/json-iterator/go.git
synced 2025-06-06 22:36:25 +02:00
#61 remove stringLazyAny
This commit is contained in:
parent
985e263300
commit
9f9ca4c9fc
@ -171,13 +171,6 @@ func (iter *Iterator) readNumberAny(positive bool) Any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (iter *Iterator) readStringAny() Any {
|
|
||||||
iter.startCapture(iter.head - 1)
|
|
||||||
iter.skipString()
|
|
||||||
lazyBuf := iter.stopCapture()
|
|
||||||
return &stringLazyAny{baseAny{}, iter.cfg, lazyBuf, nil, ""}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (iter *Iterator) readObjectAny() Any {
|
func (iter *Iterator) readObjectAny() Any {
|
||||||
iter.startCapture(iter.head - 1)
|
iter.startCapture(iter.head - 1)
|
||||||
iter.skipObject()
|
iter.skipObject()
|
||||||
|
@ -1,141 +1,9 @@
|
|||||||
package jsoniter
|
package jsoniter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"strconv"
|
"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 {
|
type stringAny struct {
|
||||||
baseAny
|
baseAny
|
||||||
err error
|
err error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user