Skip to content

Commit bee32b6

Browse files
AtkinsSJtrflynn89
authored andcommitted
LibWeb: Port CSS::Parser::Declaration to new Strings
1 parent a168cda commit bee32b6

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2020-2021, the SerenityOS developers.
3-
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
3+
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
44
*
55
* SPDX-License-Identifier: BSD-2-Clause
66
*/
@@ -10,7 +10,7 @@
1010

1111
namespace Web::CSS::Parser {
1212

13-
Declaration::Declaration(DeprecatedFlyString name, Vector<ComponentValue> values, Important important)
13+
Declaration::Declaration(FlyString name, Vector<ComponentValue> values, Important important)
1414
: m_name(move(name))
1515
, m_values(move(values))
1616
, m_important(move(important))
@@ -19,18 +19,18 @@ Declaration::Declaration(DeprecatedFlyString name, Vector<ComponentValue> values
1919

2020
Declaration::~Declaration() = default;
2121

22-
DeprecatedString Declaration::to_deprecated_string() const
22+
ErrorOr<String> Declaration::to_string() const
2323
{
2424
StringBuilder builder;
2525

2626
serialize_an_identifier(builder, m_name);
27-
builder.append(": "sv);
28-
builder.join(' ', m_values);
27+
TRY(builder.try_append(": "sv));
28+
TRY(builder.try_join(' ', m_values));
2929

3030
if (m_important == Important::Yes)
31-
builder.append(" !important"sv);
31+
TRY(builder.try_append(" !important"sv));
3232

33-
return builder.to_deprecated_string();
33+
return builder.to_string();
3434
}
3535

3636
}

Userland/Libraries/LibWeb/CSS/Parser/Declaration.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
22
* Copyright (c) 2020-2021, the SerenityOS developers.
3+
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
34
*
45
* SPDX-License-Identifier: BSD-2-Clause
56
*/
67

78
#pragma once
89

9-
#include <AK/DeprecatedString.h>
10+
#include <AK/FlyString.h>
1011
#include <AK/Vector.h>
1112
#include <LibWeb/CSS/CSSStyleDeclaration.h>
1213
#include <LibWeb/CSS/Parser/ComponentValue.h>
@@ -15,17 +16,17 @@ namespace Web::CSS::Parser {
1516

1617
class Declaration {
1718
public:
18-
Declaration(DeprecatedFlyString name, Vector<ComponentValue> values, Important);
19+
Declaration(FlyString name, Vector<ComponentValue> values, Important);
1920
~Declaration();
2021

2122
StringView name() const { return m_name; }
2223
Vector<ComponentValue> const& values() const { return m_values; }
2324
Important importance() const { return m_important; }
2425

25-
DeprecatedString to_deprecated_string() const;
26+
ErrorOr<String> to_string() const;
2627

2728
private:
28-
DeprecatedFlyString m_name;
29+
FlyString m_name;
2930
Vector<ComponentValue> m_values;
3031
Important m_important { Important::No };
3132
};

Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DeprecatedString DeclarationOrAtRule::to_deprecated_string() const
3333
builder.append(m_at->to_deprecated_string());
3434
break;
3535
case DeclarationType::Declaration:
36-
builder.append(m_declaration->to_deprecated_string());
36+
builder.append(m_declaration->to_string().release_value_but_fixme_should_propagate_errors());
3737
break;
3838
}
3939

Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<Component
13951395
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
13961396
transaction.commit();
13971397
return Supports::Feature {
1398-
Supports::Declaration { declaration->to_deprecated_string() }
1398+
Supports::Declaration { declaration->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string() }
13991399
};
14001400
}
14011401
}
@@ -1856,7 +1856,7 @@ Optional<Declaration> Parser::consume_a_declaration(TokenStream<T>& tokens)
18561856
// Create a new declaration with its name set to the value of the current input token
18571857
// and its value initially set to the empty list.
18581858
// NOTE: We create a fully-initialized Declaration just before returning it instead.
1859-
DeprecatedFlyString declaration_name = ((Token)token).ident();
1859+
auto declaration_name = FlyString::from_utf8(((Token)token).ident()).release_value_but_fixme_should_propagate_errors();
18601860
Vector<ComponentValue> declaration_values;
18611861
Important declaration_important = Important::No;
18621862

0 commit comments

Comments
 (0)