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,16 +1384,20 @@ func Get(json, path string) Result {
} }
} }
} }
if len(c.value.Raw) > 0 && !c.calcd { /*
jhdr := *(*reflect.StringHeader)(unsafe.Pointer(&json)) if len(c.value.Raw) > 0 && !c.calcd {
rhdr := *(*reflect.StringHeader)(unsafe.Pointer(&(c.value.Raw))) jhdr := *(*reflect.StringHeader)(unsafe.Pointer(&json))
c.value.Index = int(rhdr.Data - jhdr.Data) rhdr := *(*reflect.StringHeader)(unsafe.Pointer(&(c.value.Raw)))
if c.value.Index < 0 || c.value.Index >= len(json) { c.value.Index = int(rhdr.Data - jhdr.Data)
c.value.Index = 0 if c.value.Index < 0 || c.value.Index >= len(json) {
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,17 +1435,21 @@ 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 {
var result Result return Get(string(json), path)
if json != nil { /*
// unsafe cast to string var result Result
result = Get(*(*string)(unsafe.Pointer(&json)), path) if json != nil {
result = fromBytesGet(result) // unsafe cast to string
} result = Get(*(*string)(unsafe.Pointer(&json)), path)
return result result = fromBytesGet(result)
}
return result
*/
} }
// runeit returns the rune from the the \uXXXX // runeit returns the rune from the the \uXXXX