mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:37:36 +00:00
LibTextCodec+Everywhere: Return Optional<Decoder&> from decoder_for()
This commit is contained in:
parent
2f4c463920
commit
f2a9426885
16 changed files with 42 additions and 39 deletions
|
@ -514,7 +514,7 @@ void HTMLScriptElement::resource_did_load()
|
|||
// If the resource has an explicit encoding (i.e from a HTTP Content-Type header)
|
||||
// we have to re-encode it to UTF-8.
|
||||
if (resource()->has_encoding()) {
|
||||
if (auto* codec = TextCodec::decoder_for(resource()->encoding().value())) {
|
||||
if (auto codec = TextCodec::decoder_for(resource()->encoding().value()); codec.has_value()) {
|
||||
data = codec->to_utf8(data).to_byte_buffer();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2798,8 +2798,8 @@ HTMLTokenizer::HTMLTokenizer()
|
|||
|
||||
HTMLTokenizer::HTMLTokenizer(StringView input, DeprecatedString const& encoding)
|
||||
{
|
||||
auto* decoder = TextCodec::decoder_for(encoding);
|
||||
VERIFY(decoder);
|
||||
auto decoder = TextCodec::decoder_for(encoding);
|
||||
VERIFY(decoder.has_value());
|
||||
m_decoded_input = decoder->to_utf8(input);
|
||||
m_utf8_view = Utf8View(m_decoded_input);
|
||||
m_utf8_iterator = m_utf8_view.begin();
|
||||
|
|
|
@ -1420,7 +1420,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::atob)
|
|||
// The bytes object might contain bytes greater than 128, encode them in UTF8
|
||||
// NOTE: Any 8-bit encoding -> utf-8 decoder will work for this
|
||||
auto text_decoder = TextCodec::decoder_for("windows-1252"sv);
|
||||
VERIFY(text_decoder);
|
||||
VERIFY(text_decoder.has_value());
|
||||
auto text = text_decoder->to_utf8(decoded.release_value());
|
||||
|
||||
return JS::PrimitiveString::create(vm, DeprecatedString(text));
|
||||
|
|
|
@ -161,8 +161,8 @@ WebIDL::ExceptionOr<DeprecatedString> WorkerGlobalScope::atob(DeprecatedString c
|
|||
|
||||
// 3. Return decodedData.
|
||||
// decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8.
|
||||
auto* decoder = TextCodec::decoder_for("windows-1252"sv);
|
||||
VERIFY(decoder);
|
||||
auto decoder = TextCodec::decoder_for("windows-1252"sv);
|
||||
VERIFY(decoder.has_value());
|
||||
return decoder->to_utf8(decoded_data.value());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue