Skip to content

Commit 848e480

Browse files
committed
src: remove decodeLatin1 function and related tests
1 parent 25319d5 commit 848e480

File tree

1 file changed

+0
-70
lines changed

1 file changed

+0
-70
lines changed

src/encoding_binding.cc

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -313,76 +313,6 @@ void BindingData::DecodeWindows1252(const FunctionCallbackInfo<Value>& args) {
313313
}
314314
}
315315

316-
void BindingData::DecodeWindows1252(const FunctionCallbackInfo<Value>& args) {
317-
Environment* env = Environment::GetCurrent(args);
318-
319-
CHECK_GE(args.Length(), 1);
320-
if (!(args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer() ||
321-
args[0]->IsArrayBufferView())) {
322-
return node::THROW_ERR_INVALID_ARG_TYPE(
323-
env->isolate(),
324-
"The \"input\" argument must be an instance of ArrayBuffer, "
325-
"SharedArrayBuffer, or ArrayBufferView.");
326-
}
327-
328-
bool ignore_bom = args[1]->IsTrue();
329-
330-
ArrayBufferViewContents<uint8_t> buffer(args[0]);
331-
const uint8_t* data = buffer.data();
332-
size_t length = buffer.length();
333-
334-
if (ignore_bom && length > 0 && data[0] == 0xFF) {
335-
data++;
336-
length--;
337-
}
338-
339-
if (length == 0) {
340-
return args.GetReturnValue().SetEmptyString();
341-
}
342-
343-
// Windows-1252 specific mapping for bytes 128-159
344-
// These differ from Latin-1/ISO-8859-1
345-
static const uint16_t windows1252_mapping[32] = {
346-
0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, // 80-87
347-
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F, // 88-8F
348-
0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, // 90-97
349-
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178 // 98-9F
350-
};
351-
352-
std::string result;
353-
result.reserve(length * 3); // Reserve space for UTF-8 output
354-
355-
for (size_t i = 0; i < length; i++) {
356-
uint8_t byte = data[i];
357-
uint32_t codepoint;
358-
359-
// Check if byte is in the special Windows-1252 range (128-159)
360-
if (byte >= 0x80 && byte <= 0x9F) {
361-
codepoint = windows1252_mapping[byte - 0x80];
362-
} else {
363-
// For all other bytes, Windows-1252 is identical to Latin-1
364-
codepoint = byte;
365-
}
366-
367-
// Convert codepoint to UTF-8
368-
if (codepoint < 0x80) {
369-
result.push_back(static_cast<char>(codepoint));
370-
} else if (codepoint < 0x800) {
371-
result.push_back(static_cast<char>(0xC0 | (codepoint >> 6)));
372-
result.push_back(static_cast<char>(0x80 | (codepoint & 0x3F)));
373-
} else {
374-
result.push_back(static_cast<char>(0xE0 | (codepoint >> 12)));
375-
result.push_back(static_cast<char>(0x80 | ((codepoint >> 6) & 0x3F)));
376-
result.push_back(static_cast<char>(0x80 | (codepoint & 0x3F)));
377-
}
378-
}
379-
380-
Local<Value> ret;
381-
if (ToV8Value(env->context(), result, env->isolate()).ToLocal(&ret)) {
382-
args.GetReturnValue().Set(ret);
383-
}
384-
}
385-
386316
} // namespace encoding_binding
387317
} // namespace node
388318

0 commit comments

Comments
 (0)