MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / decodeUtf16LeIgnore

Function decodeUtf16LeIgnore

packages/kaos/src/internal.ts:84–121  ·  view source on GitHub ↗
(data: Buffer)

Source from the content-addressed store, hash-verified

82}
83
84function decodeUtf16LeIgnore(data: Buffer): string {
85 let output = '';
86 let i = 0;
87
88 while (i + 1 < data.length) {
89 const first = data[i];
90 const second = data[i + 1];
91 if (first === undefined || second === undefined) break;
92
93 const codeUnit = first | (second << 8);
94
95 if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
96 const lowFirst = data[i + 2];
97 const lowSecond = data[i + 3];
98 if (lowFirst !== undefined && lowSecond !== undefined) {
99 const low = lowFirst | (lowSecond << 8);
100 if (low >= 0xdc00 && low <= 0xdfff) {
101 const codePoint = 0x10000 + ((codeUnit - 0xd800) << 10) + (low - 0xdc00);
102 output += String.fromCodePoint(codePoint);
103 i += 4;
104 continue;
105 }
106 }
107 i += 2;
108 continue;
109 }
110
111 if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
112 i += 2;
113 continue;
114 }
115
116 output += String.fromCodePoint(codeUnit);
117 i += 2;
118 }
119
120 return output;
121}
122
123/**
124 * Decode a Buffer into a string with Python-compatible `errors` handling.

Callers 1

decodeTextWithErrorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected