Skip to content

Added ParsePrimitiveValue convenience function for users #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Exported Unescape for users who want to unescape their search keys
  • Loading branch information
daboyuka committed Apr 7, 2016
commit 6cf33ba830a1021f90c1201b8601578c7b222b7f
2 changes: 1 addition & 1 deletion escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func unescapeToUTF8(in, out []byte) (inLen int, outLen int) {
// 'out' is used to build the unescaped string and is returned with no extra allocation
// Else:
// A new slice is allocated and returned.
func unescape(in, out []byte) ([]byte, error) {
func Unescape(in, out []byte) ([]byte, error) {
firstBackslash := bytes.IndexByte(in, '\\')
if firstBackslash == -1 {
return in, nil
Expand Down
2 changes: 1 addition & 1 deletion escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestUnescape(t *testing.T) {
in := []byte(test.in)
buf := buftest.buf

out, err := unescape(in, buf)
out, err := Unescape(in, buf)
isErr := (err != nil)
isAlloc := !isSameMemory(out, in) && !isSameMemory(out, buf)

Expand Down
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func searchKeys(data []byte, keys ...string) int {

// for unescape: if there are no escape sequences, this is cheap; if there are, it is a
// bit more expensive, but causes no allocations unless len(key) > unescapeStackBufSize
if keyUnesc, err := unescape(key, stackbuf[:]); err != nil {
if keyUnesc, err := Unescape(key, stackbuf[:]); err != nil {
return -1
} else {
keyUnescStr := unsafeBytesToString(keyUnesc)
Expand Down Expand Up @@ -407,7 +407,7 @@ func GetString(data []byte, keys ...string) (val string, err error) {
}

var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings
out, err := unescape(v, stackbuf[:])
out, err := Unescape(v, stackbuf[:])

return string(out), err
}
Expand Down