1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

LibWeb: Change Resource's m_encoding to Optional<String>

This modifies the Resource class to use Optional<String> for the
encoding. If the encoding is unknown, the Optional will not have a
value (instead of using the null state of the String class). It also
implements a has_encoding() instance method and modifies the callers
of Resource::encoding() to use the new API.
This commit is contained in:
Max Wipfli 2021-05-12 10:21:00 +02:00 committed by Andreas Kling
parent ce6d6706a6
commit a7681dbeea
3 changed files with 11 additions and 7 deletions

View file

@ -85,14 +85,12 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, const HashMap
m_mime_type = Core::guess_mime_type_based_on_filename(url().path());
}
m_encoding = {};
if (content_type.has_value()) {
auto encoding = encoding_from_content_type(content_type.value());
if (encoding.has_value()) {
dbgln_if(RESOURCE_DEBUG, "Set encoding '{}' from Content-Type", encoding.has_value());
m_encoding = encoding.value();
} else {
// FIXME: This doesn't seem nice.
m_encoding = "utf-8";
}
}