Skip to content

Commit 6cf33ba

Browse files
committed
Exported Unescape for users who want to unescape their search keys
1 parent f184509 commit 6cf33ba

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

escape.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func unescapeToUTF8(in, out []byte) (inLen int, outLen int) {
106106
// 'out' is used to build the unescaped string and is returned with no extra allocation
107107
// Else:
108108
// A new slice is allocated and returned.
109-
func unescape(in, out []byte) ([]byte, error) {
109+
func Unescape(in, out []byte) ([]byte, error) {
110110
firstBackslash := bytes.IndexByte(in, '\\')
111111
if firstBackslash == -1 {
112112
return in, nil

escape_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func TestUnescape(t *testing.T) {
168168
in := []byte(test.in)
169169
buf := buftest.buf
170170

171-
out, err := unescape(in, buf)
171+
out, err := Unescape(in, buf)
172172
isErr := (err != nil)
173173
isAlloc := !isSameMemory(out, in) && !isSameMemory(out, buf)
174174

parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func searchKeys(data []byte, keys ...string) int {
144144

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

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

412412
return string(out), err
413413
}

0 commit comments

Comments
 (0)