Skip to content

Commit

Permalink
Add support for parsing raw hex values via \x
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed Oct 12, 2023
1 parent 2da050b commit 68e2149
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,17 @@ func unquoteBytes(s []byte) (t []byte, ok bool) {
b[w] = '\t'
r++
w++
case 'x':
if (r+2) < len(s) {
n, err := strconv.ParseUint(string(s[r+1:r+3]), 16, 8)
if err != nil {
return
} else {
b[w] = byte(n)
r += 3
w++
}
}
case 'u':
r--
rr := getu4(s[r:])
Expand Down
2 changes: 1 addition & 1 deletion scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func stateInStringSingle(s *scanner, c byte) int {
func stateInStringEsc(resume func(s *scanner, c byte) int) func(s *scanner, c byte) int {
return func(s *scanner, c byte) int {
switch c {
case 'b', 'f', 'n', 'r', 't', '\\', '/', '"', '\'', '\n':
case 'b', 'f', 'n', 'r', 't', '\\', '/', '"', '\'', '\n', 'x':
s.step = resume
return scanContinue
case 'u':
Expand Down

0 comments on commit 68e2149

Please sign in to comment.