MCPcopy
hub / github.com/buger/jsonparser / decodeUnicodeEscape

Function decodeUnicodeEscape

escape.go:63–84  ·  view source on GitHub ↗
(in []byte)

Source from the content-addressed store, hash-verified

61}
62
63func decodeUnicodeEscape(in []byte) (rune, int) {
64 if r, ok := decodeSingleUnicodeEscape(in); !ok {
65 // Invalid Unicode escape
66 return utf8.RuneError, -1
67 } else if !isUTF16EncodedRune(r) {
68 // Valid Unicode escape in Basic Multilingual Plane.
69 // Note: a single \uXXXX escape produces r in [0, 0xFFFF], so r is always
70 // within the BMP. The former r <= basicMultilingualPlaneOffset guard was
71 // tautological and has been removed — the real discriminator is whether r
72 // falls in the UTF-16 surrogate range.
73 return r, 6
74 } else if r2, ok := decodeSingleUnicodeEscape(in[6:]); !ok { // Note: previous decodeSingleUnicodeEscape success guarantees at least 6 bytes remain
75 // UTF16 "high surrogate" without manditory valid following Unicode escape for the "low surrogate"
76 return utf8.RuneError, -1
77 } else if r2 < lowSurrogateOffset {
78 // Invalid UTF16 "low surrogate"
79 return utf8.RuneError, -1
80 } else {
81 // Valid UTF16 surrogate pair
82 return combineUTF16Surrogates(r, r2), 12
83 }
84}
85
86// backslashCharEscapeTable: when '\X' is found for some byte X, it is to be replaced with backslashCharEscapeTable[X]
87var backslashCharEscapeTable = [...]byte{

Calls 3

isUTF16EncodedRuneFunction · 0.85
combineUTF16SurrogatesFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…