MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / decodeUtf16One

Function decodeUtf16One

packages/core/src/runtime/inputEditor.ts:42–68  ·  view source on GitHub ↗
(text: string, off: number)

Source from the content-addressed store, hash-verified

40type DecodeOne = Readonly<{ scalar: number; size: 1 | 2 }>;
41
42function 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
70function shouldBreak(
71 prevClass: number,

Callers 2

nextClusterEndFunction · 0.70
classifyClusterFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected