(in []byte)
| 61 | } |
| 62 | |
| 63 | func 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] |
| 87 | var backslashCharEscapeTable = [...]byte{ |
searching dependent graphs…