LibTextCodec: Normalize incoming encodings in decoder_for()

Instead of asserting when you call TextCoded::decoder_for() with a
non-standard encoding name, let's be nice and see if we can't find a
decoder for the standardized version of the encoding name.
This commit is contained in:
Andreas Kling 2020-12-13 18:20:50 +01:00
parent 986ce57be9
commit 024059b49b
Notes: sideshowbarker 2024-07-19 00:53:26 +09:00

View file

@ -46,14 +46,14 @@ static UTF8Decoder& utf8_decoder()
return *decoder;
}
Decoder* decoder_for(const String& encoding)
Decoder* decoder_for(const String& a_encoding)
{
ASSERT(is_standardized_encoding(encoding));
auto encoding = get_standardized_encoding(a_encoding);
if (encoding.equals_ignoring_case("windows-1252"))
return &latin1_decoder();
if (encoding.equals_ignoring_case("utf-8"))
return &utf8_decoder();
dbg() << "TextCodec: No decoder implemented for encoding '" << encoding << "'";
dbgln("TextCodec: No decoder implemented for encoding '{}'", a_encoding);
return nullptr;
}