You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	fix #228
This commit is contained in:
		| @@ -1,6 +1,9 @@ | ||||
| package jsoniter | ||||
|  | ||||
| import "unsafe" | ||||
| import ( | ||||
| 	"unsafe" | ||||
| 	"io" | ||||
| ) | ||||
|  | ||||
| type numberLazyAny struct { | ||||
| 	baseAny | ||||
| @@ -29,7 +32,9 @@ func (any *numberLazyAny) ToInt() int { | ||||
| 	iter := any.cfg.BorrowIterator(any.buf) | ||||
| 	defer any.cfg.ReturnIterator(iter) | ||||
| 	val := iter.ReadInt() | ||||
| 	any.err = iter.Error | ||||
| 	if iter.Error != nil && iter.Error != io.EOF { | ||||
| 		any.err = iter.Error | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
|  | ||||
| @@ -37,7 +42,9 @@ func (any *numberLazyAny) ToInt32() int32 { | ||||
| 	iter := any.cfg.BorrowIterator(any.buf) | ||||
| 	defer any.cfg.ReturnIterator(iter) | ||||
| 	val := iter.ReadInt32() | ||||
| 	any.err = iter.Error | ||||
| 	if iter.Error != nil && iter.Error != io.EOF { | ||||
| 		any.err = iter.Error | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
|  | ||||
| @@ -45,7 +52,9 @@ func (any *numberLazyAny) ToInt64() int64 { | ||||
| 	iter := any.cfg.BorrowIterator(any.buf) | ||||
| 	defer any.cfg.ReturnIterator(iter) | ||||
| 	val := iter.ReadInt64() | ||||
| 	any.err = iter.Error | ||||
| 	if iter.Error != nil && iter.Error != io.EOF { | ||||
| 		any.err = iter.Error | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
|  | ||||
| @@ -53,7 +62,9 @@ func (any *numberLazyAny) ToUint() uint { | ||||
| 	iter := any.cfg.BorrowIterator(any.buf) | ||||
| 	defer any.cfg.ReturnIterator(iter) | ||||
| 	val := iter.ReadUint() | ||||
| 	any.err = iter.Error | ||||
| 	if iter.Error != nil && iter.Error != io.EOF { | ||||
| 		any.err = iter.Error | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
|  | ||||
| @@ -61,7 +72,9 @@ func (any *numberLazyAny) ToUint32() uint32 { | ||||
| 	iter := any.cfg.BorrowIterator(any.buf) | ||||
| 	defer any.cfg.ReturnIterator(iter) | ||||
| 	val := iter.ReadUint32() | ||||
| 	any.err = iter.Error | ||||
| 	if iter.Error != nil && iter.Error != io.EOF { | ||||
| 		any.err = iter.Error | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
|  | ||||
| @@ -69,7 +82,9 @@ func (any *numberLazyAny) ToUint64() uint64 { | ||||
| 	iter := any.cfg.BorrowIterator(any.buf) | ||||
| 	defer any.cfg.ReturnIterator(iter) | ||||
| 	val := iter.ReadUint64() | ||||
| 	any.err = iter.Error | ||||
| 	if iter.Error != nil && iter.Error != io.EOF { | ||||
| 		any.err = iter.Error | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
|  | ||||
| @@ -77,7 +92,9 @@ func (any *numberLazyAny) ToFloat32() float32 { | ||||
| 	iter := any.cfg.BorrowIterator(any.buf) | ||||
| 	defer any.cfg.ReturnIterator(iter) | ||||
| 	val := iter.ReadFloat32() | ||||
| 	any.err = iter.Error | ||||
| 	if iter.Error != nil && iter.Error != io.EOF { | ||||
| 		any.err = iter.Error | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
|  | ||||
| @@ -85,7 +102,9 @@ func (any *numberLazyAny) ToFloat64() float64 { | ||||
| 	iter := any.cfg.BorrowIterator(any.buf) | ||||
| 	defer any.cfg.ReturnIterator(iter) | ||||
| 	val := iter.ReadFloat64() | ||||
| 	any.err = iter.Error | ||||
| 	if iter.Error != nil && iter.Error != io.EOF { | ||||
| 		any.err = iter.Error | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -51,6 +51,7 @@ func Test_read_string_as_any(t *testing.T) { | ||||
|  | ||||
| func Test_wrap_string(t *testing.T) { | ||||
| 	should := require.New(t) | ||||
| 	any := WrapString("123") | ||||
| 	should.Equal(123, any.ToInt()) | ||||
| 	any := Get([]byte("-32000")).MustBeValid() | ||||
| 	should.Equal(-32000, any.ToInt()) | ||||
| 	should.NoError(any.LastError()) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user