LibTextCodec: Add SingleByteEncoders

They are similar to their already existing decoder counterparts.
This commit is contained in:
0x4261756D 2024-10-09 23:06:06 +02:00 committed by Andreas Kling
parent 7faebb2702
commit 96de4ef7e0
Notes: github-actions[bot] 2024-10-10 08:40:18 +00:00
3 changed files with 147 additions and 0 deletions

View file

@ -153,3 +153,22 @@ TEST_CASE(test_gb18030_encoder)
EXPECT(processed_bytes[2] == 0xFE);
EXPECT(processed_bytes[3] == 0xFE);
}
TEST_CASE(test_windows1252_encoder)
{
auto encoder = TextCodec::encoder_for_exact_name("windows-1252"sv);
auto test_string = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏfoo€"sv;
Vector<u8> processed_bytes;
MUST(encoder.value().process(
Utf8View(test_string),
[&](u8 byte) { dbgln("{}", processed_bytes.size()); return processed_bytes.try_append(byte); },
[&](u32) -> ErrorOr<void> { EXPECT(false); return {}; }));
EXPECT(processed_bytes.size() == 20);
for (u8 i = 0; i < 15; i++) {
EXPECT(processed_bytes[i] == (0xC0 + i));
}
EXPECT(processed_bytes[16] == 0x66);
EXPECT(processed_bytes[17] == 0x6F);
EXPECT(processed_bytes[18] == 0x6F);
EXPECT(processed_bytes[19] == 0x80);
}