1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:07:45 +00:00

AK+Everywhere: Remove the null state of DeprecatedString

This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
This commit is contained in:
Ali Mohammad Pur 2023-10-10 15:00:58 +03:30 committed by Ali Mohammad Pur
parent daf6d8173c
commit aeee98b3a1
189 changed files with 597 additions and 652 deletions

View file

@ -40,7 +40,7 @@ DeprecatedString CSSNamespaceRule::serialized() const
builder.append("@namespace "sv);
// followed by the serialization as an identifier of the prefix attribute (if any),
if (!m_prefix.is_empty() && !m_prefix.is_null()) {
if (!m_prefix.is_empty()) {
serialize_an_identifier(builder, m_prefix);
// followed by a single SPACE (U+0020) if there is a prefix,
builder.append(" "sv);

View file

@ -53,23 +53,23 @@ DeprecatedString CSSStyleRule::serialized() const
builder.append(" {"sv);
// 2. Let decls be the result of performing serialize a CSS declaration block on the rules associated declarations, or null if there are no such declarations.
auto decls = declaration().serialized();
auto decls = declaration().length() > 0 ? declaration().serialized() : Optional<DeprecatedString>();
// FIXME: 3. Let rules be the result of performing serialize a CSS rule on each rule in the rules cssRules list, or null if there are no such rules.
DeprecatedString rules;
Optional<DeprecatedString> rules;
// 4. If decls and rules are both null, append " }" to s (i.e. a single SPACE (U+0020) followed by RIGHT CURLY BRACKET (U+007D)) and return s.
if (decls.is_null() && rules.is_null()) {
if (!decls.has_value() && !rules.has_value()) {
builder.append(" }"sv);
return builder.to_deprecated_string();
}
// 5. If rules is null:
if (rules.is_null()) {
if (!rules.has_value()) {
// 1. Append a single SPACE (U+0020) to s
builder.append(' ');
// 2. Append decls to s
builder.append(decls);
builder.append(*decls);
// 3. Append " }" to s (i.e. a single SPACE (U+0020) followed by RIGHT CURLY BRACKET (U+007D)).
builder.append(" }"sv);
// 4. Return s.

View file

@ -36,9 +36,9 @@ static inline bool matches_lang_pseudo_class(DOM::Element const& element, Vector
{
FlyString element_language;
for (auto const* e = &element; e; e = e->parent_element()) {
auto lang = e->deprecated_attribute(HTML::AttributeNames::lang);
if (!lang.is_null()) {
element_language = FlyString::from_deprecated_fly_string(lang).release_value_but_fixme_should_propagate_errors();
auto lang = e->attribute(HTML::AttributeNames::lang);
if (lang.has_value()) {
element_language = lang.release_value();
break;
}
}