removed usage of package "unsafe" for Google App Engine compatibility

This commit is contained in:
Johnnie Kearse III 2018-04-09 15:35:14 -04:00
parent 9ed3f8e1a5
commit 58fc9b4bc4
1 changed files with 24 additions and 17 deletions

View File

@ -13,7 +13,6 @@ import (
"time" "time"
"unicode/utf16" "unicode/utf16"
"unicode/utf8" "unicode/utf8"
"unsafe"
"github.com/tidwall/match" "github.com/tidwall/match"
) )
@ -1292,7 +1291,7 @@ func parseArray(c *parseContext, i int, path string) (int, bool) {
c.value.Raw = val c.value.Raw = val
c.value.Type = Number c.value.Type = Number
c.value.Num = float64(h - 1) c.value.Num = float64(h - 1)
c.calcd = true // c.calcd = true
return i + 1, true return i + 1, true
} }
if len(multires) > 0 && !c.value.Exists() { if len(multires) > 0 && !c.value.Exists() {
@ -1329,7 +1328,7 @@ func ForEachLine(json string, iterator func(line Result) bool) {
type parseContext struct { type parseContext struct {
json string json string
value Result value Result
calcd bool // calcd bool
lines bool lines bool
} }
@ -1385,6 +1384,7 @@ func Get(json, path string) Result {
} }
} }
} }
/*
if len(c.value.Raw) > 0 && !c.calcd { if len(c.value.Raw) > 0 && !c.calcd {
jhdr := *(*reflect.StringHeader)(unsafe.Pointer(&json)) jhdr := *(*reflect.StringHeader)(unsafe.Pointer(&json))
rhdr := *(*reflect.StringHeader)(unsafe.Pointer(&(c.value.Raw))) rhdr := *(*reflect.StringHeader)(unsafe.Pointer(&(c.value.Raw)))
@ -1393,8 +1393,11 @@ func Get(json, path string) Result {
c.value.Index = 0 c.value.Index = 0
} }
} }
*/
return c.value return c.value
} }
/*
func fromBytesGet(result Result) 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))
@ -1432,10 +1435,13 @@ func fromBytesGet(result Result) Result {
} }
return result return result
} }
*/
// GetBytes searches json for the specified path. // GetBytes searches json for the specified path.
// If working with bytes, this method preferred over Get(string(data), path) // If working with bytes, this method preferred over Get(string(data), path)
func GetBytes(json []byte, path string) Result { func GetBytes(json []byte, path string) Result {
return Get(string(json), path)
/*
var result Result var result Result
if json != nil { if json != nil {
// unsafe cast to string // unsafe cast to string
@ -1443,6 +1449,7 @@ func GetBytes(json []byte, path string) Result {
result = fromBytesGet(result) result = fromBytesGet(result)
} }
return result return result
*/
} }
// runeit returns the rune from the the \uXXXX // runeit returns the rune from the the \uXXXX