forked from mirror/gjson
Added GopherJS support
This commit is contained in:
parent
081192fa2e
commit
5a96cfda70
|
@ -1,4 +1,4 @@
|
||||||
//+build appengine
|
//+build appengine js
|
||||||
|
|
||||||
package gjson
|
package gjson
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//+build !appengine
|
//+build !appengine
|
||||||
|
//+build !js
|
||||||
|
|
||||||
package gjson
|
package gjson
|
||||||
|
|
||||||
|
@ -15,12 +16,6 @@ func getBytes(json []byte, path string) Result {
|
||||||
if json != nil {
|
if json != nil {
|
||||||
// unsafe cast to string
|
// unsafe cast to string
|
||||||
result = Get(*(*string)(unsafe.Pointer(&json)), path)
|
result = Get(*(*string)(unsafe.Pointer(&json)), path)
|
||||||
result = fromBytesGet(result)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func fromBytesGet(result Result) Result {
|
|
||||||
// safely get the string headers
|
// safely get the string headers
|
||||||
rawhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Raw))
|
rawhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Raw))
|
||||||
strhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Str))
|
strhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Str))
|
||||||
|
@ -55,6 +50,7 @@ func fromBytesGet(result Result) Result {
|
||||||
result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh)))
|
result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh)))
|
||||||
result.Str = string(*(*[]byte)(unsafe.Pointer(&strh)))
|
result.Str = string(*(*[]byte)(unsafe.Pointer(&strh)))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1361,7 +1361,7 @@ null
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumUint64String(t *testing.T) {
|
func TestNumUint64String(t *testing.T) {
|
||||||
i := 9007199254740993 //2^53 + 1
|
var i int64 = 9007199254740993 //2^53 + 1
|
||||||
j := fmt.Sprintf(`{"data": [ %d, "hello" ] }`, i)
|
j := fmt.Sprintf(`{"data": [ %d, "hello" ] }`, i)
|
||||||
res := Get(j, "data.0")
|
res := Get(j, "data.0")
|
||||||
if res.String() != "9007199254740993" {
|
if res.String() != "9007199254740993" {
|
||||||
|
@ -1370,7 +1370,7 @@ func TestNumUint64String(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumInt64String(t *testing.T) {
|
func TestNumInt64String(t *testing.T) {
|
||||||
i := -9007199254740993
|
var i int64 = -9007199254740993
|
||||||
j := fmt.Sprintf(`{"data":[ "hello", %d ]}`, i)
|
j := fmt.Sprintf(`{"data":[ "hello", %d ]}`, i)
|
||||||
res := Get(j, "data.1")
|
res := Get(j, "data.1")
|
||||||
if res.String() != "-9007199254740993" {
|
if res.String() != "-9007199254740993" {
|
||||||
|
@ -1388,7 +1388,7 @@ func TestNumBigString(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumFloatString(t *testing.T) {
|
func TestNumFloatString(t *testing.T) {
|
||||||
i := -9007199254740993
|
var i int64 = -9007199254740993
|
||||||
j := fmt.Sprintf(`{"data":[ "hello", %d ]}`, i) //No quotes around value!!
|
j := fmt.Sprintf(`{"data":[ "hello", %d ]}`, i) //No quotes around value!!
|
||||||
res := Get(j, "data.1")
|
res := Get(j, "data.1")
|
||||||
if res.String() != "-9007199254740993" {
|
if res.String() != "-9007199254740993" {
|
||||||
|
|
Loading…
Reference in New Issue