From 893a9ff5b05557547c173d67b66eff0642806698 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 27 May 2020 19:34:27 +0200 Subject: [PATCH] LibTextCodec: Improve Latin-1 decoder so it decodes everything I can now see Swedish letters when opening Google in the browser. :^) --- Libraries/LibTextCodec/Decoder.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Libraries/LibTextCodec/Decoder.cpp b/Libraries/LibTextCodec/Decoder.cpp index e126fc63cb..1619e58070 100644 --- a/Libraries/LibTextCodec/Decoder.cpp +++ b/Libraries/LibTextCodec/Decoder.cpp @@ -65,7 +65,12 @@ String Latin1Decoder::to_utf8(const StringView& input) StringBuilder builder(input.length()); for (size_t i = 0; i < input.length(); ++i) { u8 ch = input[i]; - builder.append(ch >= 0x80 ? '?' : ch); + if (ch & 0x80) { + builder.append(0xc0 | (ch >> 6)); + builder.append(0x80 | (ch & 0x3f)); + } else { + builder.append(ch); + } } return builder.to_string(); }