mirror of
https://github.com/json-iterator/go.git
synced 2025-06-12 22:47:42 +02:00
#25 make fielding binding case insensitive
This commit is contained in:
parent
7d5f90261e
commit
e5a1e704ad
@ -1,6 +1,9 @@
|
|||||||
package jsoniter
|
package jsoniter
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
func (iter *Iterator) ReadObject() (ret string) {
|
func (iter *Iterator) ReadObject() (ret string) {
|
||||||
c := iter.nextToken()
|
c := iter.nextToken()
|
||||||
@ -37,6 +40,9 @@ func (iter *Iterator) readFieldHash() int32 {
|
|||||||
for i := iter.head; i < iter.tail; i++ {
|
for i := iter.head; i < iter.tail; i++ {
|
||||||
// require ascii string and no escape
|
// require ascii string and no escape
|
||||||
b := iter.buf[i]
|
b := iter.buf[i]
|
||||||
|
if 'A' <= b && b <= 'Z' {
|
||||||
|
b += 'a' - 'A'
|
||||||
|
}
|
||||||
if b == '"' {
|
if b == '"' {
|
||||||
iter.head = i+1
|
iter.head = i+1
|
||||||
c = iter.nextToken()
|
c = iter.nextToken()
|
||||||
@ -61,7 +67,7 @@ func (iter *Iterator) readFieldHash() int32 {
|
|||||||
func calcHash(str string) int32 {
|
func calcHash(str string) int32 {
|
||||||
hash := int64(0x811c9dc5)
|
hash := int64(0x811c9dc5)
|
||||||
for _, b := range str {
|
for _, b := range str {
|
||||||
hash ^= int64(b)
|
hash ^= int64(unicode.ToLower(b))
|
||||||
hash *= 0x1000193
|
hash *= 0x1000193
|
||||||
}
|
}
|
||||||
return int32(hash)
|
return int32(hash)
|
||||||
|
@ -14,7 +14,7 @@ func Test_decode_one_field_struct(t *testing.T) {
|
|||||||
obj := TestObject{}
|
obj := TestObject{}
|
||||||
should.Nil(UnmarshalFromString(`{}`, &obj))
|
should.Nil(UnmarshalFromString(`{}`, &obj))
|
||||||
should.Equal("", obj.Field1)
|
should.Equal("", obj.Field1)
|
||||||
should.Nil(UnmarshalFromString(`{"Field1": "hello"}`, &obj))
|
should.Nil(UnmarshalFromString(`{"field1": "hello"}`, &obj))
|
||||||
should.Equal("hello", obj.Field1)
|
should.Equal("hello", obj.Field1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user