(text: string, off: number)
| 40 | type DecodeOne = Readonly<{ scalar: number; size: 1 | 2 }>; |
| 41 | |
| 42 | function decodeUtf16One(text: string, off: number): DecodeOne { |
| 43 | const a = text.charCodeAt(off); |
| 44 | if (!Number.isFinite(a)) { |
| 45 | // Unreachable under a well-typed caller, but keep total behavior deterministic. |
| 46 | return { scalar: 0xfffd, size: 1 }; |
| 47 | } |
| 48 | |
| 49 | // High surrogate |
| 50 | if (a >= 0xd800 && a <= 0xdbff) { |
| 51 | const b = text.charCodeAt(off + 1); |
| 52 | // Valid surrogate pair |
| 53 | if (b >= 0xdc00 && b <= 0xdfff) { |
| 54 | const hi = a - 0xd800; |
| 55 | const lo = b - 0xdc00; |
| 56 | return { scalar: 0x10000 + (hi << 10) + lo, size: 2 }; |
| 57 | } |
| 58 | // Unpaired high surrogate -> U+FFFD |
| 59 | return { scalar: 0xfffd, size: 1 }; |
| 60 | } |
| 61 | |
| 62 | // Unpaired low surrogate -> U+FFFD |
| 63 | if (a >= 0xdc00 && a <= 0xdfff) { |
| 64 | return { scalar: 0xfffd, size: 1 }; |
| 65 | } |
| 66 | |
| 67 | return { scalar: a, size: 1 }; |
| 68 | } |
| 69 | |
| 70 | function shouldBreak( |
| 71 | prevClass: number, |
no outgoing calls
no test coverage detected