1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:07:36 +00:00

AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions

View file

@ -17,7 +17,7 @@ Block::Block(Token token, Vector<ComponentValue>&& values)
Block::~Block() = default;
String Block::to_string() const
DeprecatedString Block::to_string() const
{
StringBuilder builder;

View file

@ -32,7 +32,7 @@ public:
Vector<ComponentValue> const& values() const { return m_values; }
String to_string() const;
DeprecatedString to_string() const;
private:
Block(Token, Vector<ComponentValue>&&);

View file

@ -26,7 +26,7 @@ ComponentValue::ComponentValue(NonnullRefPtr<Block> block)
ComponentValue::~ComponentValue() = default;
String ComponentValue::to_string() const
DeprecatedString ComponentValue::to_string() const
{
return m_value.visit(
[](Token const& token) { return token.to_string(); },
@ -34,17 +34,17 @@ String ComponentValue::to_string() const
[](NonnullRefPtr<Function> const& function) { return function->to_string(); });
}
String ComponentValue::to_debug_string() const
DeprecatedString ComponentValue::to_debug_string() const
{
return m_value.visit(
[](Token const& token) {
return String::formatted("Token: {}", token.to_debug_string());
return DeprecatedString::formatted("Token: {}", token.to_debug_string());
},
[](NonnullRefPtr<Block> const& block) {
return String::formatted("Block: {}", block->to_string());
return DeprecatedString::formatted("Block: {}", block->to_string());
},
[](NonnullRefPtr<Function> const& function) {
return String::formatted("Function: {}", function->to_string());
return DeprecatedString::formatted("Function: {}", function->to_string());
});
}

View file

@ -33,8 +33,8 @@ public:
Token const& token() const { return m_value.get<Token>(); }
operator Token() const { return m_value.get<Token>(); }
String to_string() const;
String to_debug_string() const;
DeprecatedString to_string() const;
DeprecatedString to_debug_string() const;
private:
Variant<Token, NonnullRefPtr<Function>, NonnullRefPtr<Block>> m_value;

View file

@ -19,7 +19,7 @@ Declaration::Declaration(FlyString name, Vector<ComponentValue> values, Importan
Declaration::~Declaration() = default;
String Declaration::to_string() const
DeprecatedString Declaration::to_string() const
{
StringBuilder builder;

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/Vector.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/Parser/ComponentValue.h>
@ -22,7 +22,7 @@ public:
Vector<ComponentValue> const& values() const { return m_values; }
Important importance() const { return m_important; }
String to_string() const;
DeprecatedString to_string() const;
private:
FlyString m_name;

View file

@ -24,7 +24,7 @@ DeclarationOrAtRule::DeclarationOrAtRule(Declaration declaration)
DeclarationOrAtRule::~DeclarationOrAtRule() = default;
String DeclarationOrAtRule::to_string() const
DeprecatedString DeclarationOrAtRule::to_string() const
{
StringBuilder builder;
switch (m_type) {

View file

@ -37,7 +37,7 @@ public:
return *m_declaration;
}
String to_string() const;
DeprecatedString to_string() const;
private:
DeclarationType m_type;

View file

@ -18,7 +18,7 @@ Function::Function(FlyString name, Vector<ComponentValue>&& values)
Function::~Function() = default;
String Function::to_string() const
DeprecatedString Function::to_string() const
{
StringBuilder builder;

View file

@ -7,9 +7,9 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/FlyString.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibWeb/CSS/Parser/ComponentValue.h>
#include <LibWeb/Forward.h>
@ -28,7 +28,7 @@ public:
StringView name() const { return m_name; }
Vector<ComponentValue> const& values() const { return m_values; }
String to_string() const;
DeprecatedString to_string() const;
private:
Function(FlyString name, Vector<ComponentValue>&& values);

View file

@ -77,12 +77,12 @@ bool ParsingContext::in_quirks_mode() const
}
// https://www.w3.org/TR/css-values-4/#relative-urls
AK::URL ParsingContext::complete_url(String const& addr) const
AK::URL ParsingContext::complete_url(DeprecatedString const& addr) const
{
return m_url.complete_url(addr);
}
Parser::Parser(ParsingContext const& context, StringView input, String const& encoding)
Parser::Parser(ParsingContext const& context, StringView input, DeprecatedString const& encoding)
: m_context(context)
, m_tokenizer(input, encoding)
, m_tokens(m_tokenizer.parse())
@ -3382,7 +3382,7 @@ Optional<UnicodeRange> Parser::parse_unicode_range(TokenStream<ComponentValue>&
// Integers like `+34` get serialized as `34`, so manually include the `+` sign.
if (component_value.is(Token::Type::Number) && component_value.token().number().is_integer_with_explicit_sign()) {
auto int_value = component_value.token().number().integer_value();
return String::formatted("{:+}", int_value);
return DeprecatedString::formatted("{:+}", int_value);
}
return component_value.to_string();
@ -3879,7 +3879,7 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
return color;
} else if (component_value.is(Token::Type::Hash)) {
auto color = Color::from_string(String::formatted("#{}", component_value.token().hash_value()));
auto color = Color::from_string(DeprecatedString::formatted("#{}", component_value.token().hash_value()));
if (color.has_value())
return color;
return {};
@ -3898,7 +3898,7 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
// 1. Let cv be the component value.
auto const& cv = component_value;
String serialization;
DeprecatedString serialization;
// 2. If cv is a <number-token> or a <dimension-token>, follow these substeps:
if (cv.is(Token::Type::Number) || cv.is(Token::Type::Dimension)) {
// 1. If cvs type flag is not "integer", return an error.
@ -3947,7 +3947,7 @@ Optional<Color> Parser::parse_color(ComponentValue const& component_value)
}
// 6. Return the concatenation of "#" (U+0023) and serialization.
String concatenation = String::formatted("#{}", serialization);
DeprecatedString concatenation = DeprecatedString::formatted("#{}", serialization);
return Color::from_string(concatenation);
}
@ -5228,7 +5228,7 @@ RefPtr<StyleValue> Parser::parse_font_family_value(Vector<ComponentValue> const&
// font-family: my cool font\!, serif;
// font-family: "my cool font!", serif;
NonnullRefPtrVector<StyleValue> font_families;
Vector<String> current_name_parts;
Vector<DeprecatedString> current_name_parts;
for (size_t i = start_index; i < component_values.size(); ++i) {
auto const& part = component_values[i];
@ -5266,7 +5266,7 @@ RefPtr<StyleValue> Parser::parse_font_family_value(Vector<ComponentValue> const&
if (part.is(Token::Type::Comma)) {
if (current_name_parts.is_empty())
return nullptr;
font_families.append(StringStyleValue::create(String::join(' ', current_name_parts)));
font_families.append(StringStyleValue::create(DeprecatedString::join(' ', current_name_parts)));
current_name_parts.clear();
// Can't have a trailing comma
if (i + 1 == component_values.size())
@ -5276,7 +5276,7 @@ RefPtr<StyleValue> Parser::parse_font_family_value(Vector<ComponentValue> const&
}
if (!current_name_parts.is_empty()) {
font_families.append(StringStyleValue::create(String::join(' ', current_name_parts)));
font_families.append(StringStyleValue::create(DeprecatedString::join(' ', current_name_parts)));
current_name_parts.clear();
}
@ -5303,7 +5303,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
if (declaration.name().equals_ignoring_case("font-family"sv)) {
// FIXME: This is very similar to, but different from, the logic in parse_font_family_value().
// Ideally they could share code.
Vector<String> font_family_parts;
Vector<DeprecatedString> font_family_parts;
bool had_syntax_error = false;
for (size_t i = 0; i < declaration.values().size(); ++i) {
auto const& part = declaration.values()[i];
@ -5341,7 +5341,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
if (had_syntax_error || font_family_parts.is_empty())
continue;
font_family = String::join(' ', font_family_parts);
font_family = DeprecatedString::join(' ', font_family_parts);
continue;
}
if (declaration.name().equals_ignoring_case("src"sv)) {
@ -6014,11 +6014,11 @@ Optional<CSS::GridRepeat> Parser::parse_repeat(Vector<ComponentValue> const& com
return {};
Vector<CSS::ExplicitGridTrack> repeat_params;
Vector<Vector<String>> line_names_list;
Vector<Vector<DeprecatedString>> line_names_list;
auto last_object_was_line_names = false;
while (part_two_tokens.has_next_token()) {
auto token = part_two_tokens.next_token();
Vector<String> line_names;
Vector<DeprecatedString> line_names;
if (token.is_block()) {
if (last_object_was_line_names)
return {};
@ -6112,7 +6112,7 @@ Optional<CSS::ExplicitGridTrack> Parser::parse_track_sizing_function(ComponentVa
RefPtr<StyleValue> Parser::parse_grid_track_sizes(Vector<ComponentValue> const& component_values)
{
Vector<CSS::ExplicitGridTrack> track_list;
Vector<Vector<String>> line_names_list;
Vector<Vector<DeprecatedString>> line_names_list;
auto last_object_was_line_names = false;
TokenStream tokens { component_values };
while (tokens.has_next_token()) {
@ -6121,7 +6121,7 @@ RefPtr<StyleValue> Parser::parse_grid_track_sizes(Vector<ComponentValue> const&
if (last_object_was_line_names)
return GridTrackSizeStyleValue::make_auto();
last_object_was_line_names = true;
Vector<String> line_names;
Vector<DeprecatedString> line_names;
if (!token.block().is_square())
return GridTrackSizeStyleValue::make_auto();
TokenStream block_tokens { token.block().values() };
@ -6196,7 +6196,7 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
auto span_value = false;
auto span_or_position_value = 0;
String line_name_value;
DeprecatedString line_name_value;
while (true) {
if (is_auto(current_token))
return {};

View file

@ -43,7 +43,7 @@ public:
bool in_quirks_mode() const;
DOM::Document const* document() const { return m_document; }
AK::URL complete_url(String const&) const;
AK::URL complete_url(DeprecatedString const&) const;
PropertyID current_property_id() const { return m_current_property_id; }
void set_current_property_id(PropertyID property_id) { m_current_property_id = property_id; }
@ -59,7 +59,7 @@ private:
class Parser {
public:
Parser(ParsingContext const&, StringView input, String const& encoding = "utf-8");
Parser(ParsingContext const&, StringView input, DeprecatedString const& encoding = "utf-8");
~Parser() = default;
CSSStyleSheet* parse_as_css_stylesheet(Optional<AK::URL> location);
@ -353,7 +353,7 @@ private:
struct PropertiesAndCustomProperties {
Vector<StyleProperty> properties;
HashMap<String, StyleProperty> custom_properties;
HashMap<DeprecatedString, StyleProperty> custom_properties;
};
PropertiesAndCustomProperties extract_properties(Vector<DeclarationOrAtRule> const&);

View file

@ -20,7 +20,7 @@ Rule::Rule(Rule::Type type, FlyString name, Vector<ComponentValue> prelude, RefP
Rule::~Rule() = default;
String Rule::to_string() const
DeprecatedString Rule::to_string() const
{
StringBuilder builder;

View file

@ -41,7 +41,7 @@ public:
RefPtr<Block const> block() const { return m_block; }
StringView at_rule_name() const { return m_at_rule_name; }
String to_string() const;
DeprecatedString to_string() const;
private:
Rule(Type, FlyString name, Vector<ComponentValue> prelude, RefPtr<Block>);

View file

@ -5,13 +5,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <LibWeb/CSS/Parser/Token.h>
#include <LibWeb/CSS/Serialize.h>
namespace Web::CSS::Parser {
String Token::to_string() const
DeprecatedString Token::to_string() const
{
StringBuilder builder;
@ -21,15 +21,15 @@ String Token::to_string() const
case Type::Ident:
return serialize_an_identifier(ident());
case Type::Function:
return String::formatted("{}(", serialize_an_identifier(function()));
return DeprecatedString::formatted("{}(", serialize_an_identifier(function()));
case Type::AtKeyword:
return String::formatted("@{}", serialize_an_identifier(at_keyword()));
return DeprecatedString::formatted("@{}", serialize_an_identifier(at_keyword()));
case Type::Hash: {
switch (m_hash_type) {
case HashType::Id:
return String::formatted("#{}", serialize_an_identifier(hash_value()));
return DeprecatedString::formatted("#{}", serialize_an_identifier(hash_value()));
case HashType::Unrestricted:
return String::formatted("#{}", hash_value());
return DeprecatedString::formatted("#{}", hash_value());
}
VERIFY_NOT_REACHED();
}
@ -44,11 +44,11 @@ String Token::to_string() const
case Type::Delim:
return m_value;
case Type::Number:
return String::number(m_number_value.value());
return DeprecatedString::number(m_number_value.value());
case Type::Percentage:
return String::formatted("{}%", m_number_value.value());
return DeprecatedString::formatted("{}%", m_number_value.value());
case Type::Dimension:
return String::formatted("{}{}", m_number_value.value(), dimension_unit());
return DeprecatedString::formatted("{}{}", m_number_value.value(), dimension_unit());
case Type::Whitespace:
return " ";
case Type::CDO:
@ -79,7 +79,7 @@ String Token::to_string() const
}
}
String Token::to_debug_string() const
DeprecatedString Token::to_debug_string() const
{
switch (m_type) {
case Type::Invalid:
@ -88,29 +88,29 @@ String Token::to_debug_string() const
case Type::EndOfFile:
return "__EOF__";
case Type::Ident:
return String::formatted("Ident: {}", ident());
return DeprecatedString::formatted("Ident: {}", ident());
case Type::Function:
return String::formatted("Function: {}", function());
return DeprecatedString::formatted("Function: {}", function());
case Type::AtKeyword:
return String::formatted("AtKeyword: {}", at_keyword());
return DeprecatedString::formatted("AtKeyword: {}", at_keyword());
case Type::Hash:
return String::formatted("Hash: {} (hash_type: {})", hash_value(), m_hash_type == HashType::Unrestricted ? "Unrestricted" : "Id");
return DeprecatedString::formatted("Hash: {} (hash_type: {})", hash_value(), m_hash_type == HashType::Unrestricted ? "Unrestricted" : "Id");
case Type::String:
return String::formatted("String: {}", string());
return DeprecatedString::formatted("String: {}", string());
case Type::BadString:
return "BadString";
case Type::Url:
return String::formatted("Url: {}", url());
return DeprecatedString::formatted("Url: {}", url());
case Type::BadUrl:
return "BadUrl";
case Type::Delim:
return String::formatted("Delim: {}", m_value);
return DeprecatedString::formatted("Delim: {}", m_value);
case Type::Number:
return String::formatted("Number: {}{} (number_type: {})", m_number_value.value() > 0 && m_number_value.is_integer_with_explicit_sign() ? "+" : "", m_number_value.value(), m_number_value.is_integer() ? "Integer" : "Number");
return DeprecatedString::formatted("Number: {}{} (number_type: {})", m_number_value.value() > 0 && m_number_value.is_integer_with_explicit_sign() ? "+" : "", m_number_value.value(), m_number_value.is_integer() ? "Integer" : "Number");
case Type::Percentage:
return String::formatted("Percentage: {}% (number_type: {})", percentage(), m_number_value.is_integer() ? "Integer" : "Number");
return DeprecatedString::formatted("Percentage: {}% (number_type: {})", percentage(), m_number_value.is_integer() ? "Integer" : "Number");
case Type::Dimension:
return String::formatted("Dimension: {}{} (number_type: {})", dimension_value(), dimension_unit(), m_number_value.is_integer() ? "Integer" : "Number");
return DeprecatedString::formatted("Dimension: {}{} (number_type: {})", dimension_value(), dimension_unit(), m_number_value.is_integer() ? "Integer" : "Number");
case Type::Whitespace:
return "Whitespace";
case Type::CDO:
@ -156,7 +156,7 @@ Token::Type Token::mirror_variant() const
return Type::Invalid;
}
String Token::bracket_string() const
DeprecatedString Token::bracket_string() const
{
if (is(Token::Type::OpenCurly)) {
return "{";
@ -185,7 +185,7 @@ String Token::bracket_string() const
return "";
}
String Token::bracket_mirror_string() const
DeprecatedString Token::bracket_mirror_string() const
{
if (is(Token::Type::OpenCurly)) {
return "}";

View file

@ -7,8 +7,8 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/FlyString.h>
#include <AK/String.h>
#include <AK/Utf8View.h>
#include <LibWeb/CSS/Number.h>
@ -142,11 +142,11 @@ public:
}
Type mirror_variant() const;
String bracket_string() const;
String bracket_mirror_string() const;
DeprecatedString bracket_string() const;
DeprecatedString bracket_mirror_string() const;
String to_string() const;
String to_debug_string() const;
DeprecatedString to_string() const;
DeprecatedString to_debug_string() const;
Position const& start_position() const { return m_start_position; }
Position const& end_position() const { return m_end_position; }

View file

@ -195,10 +195,10 @@ static inline bool is_E(u32 code_point)
return code_point == 0x45;
}
Tokenizer::Tokenizer(StringView input, String const& encoding)
Tokenizer::Tokenizer(StringView input, DeprecatedString const& encoding)
{
// https://www.w3.org/TR/css-syntax-3/#css-filter-code-points
auto filter_code_points = [](StringView input, auto const& encoding) -> String {
auto filter_code_points = [](StringView input, auto const& encoding) -> DeprecatedString {
auto* decoder = TextCodec::decoder_for(encoding);
VERIFY(decoder);
@ -352,7 +352,7 @@ Token Tokenizer::create_eof_token()
return create_new_token(Token::Type::EndOfFile);
}
Token Tokenizer::create_value_token(Token::Type type, String value)
Token Tokenizer::create_value_token(Token::Type type, DeprecatedString value)
{
Token token;
token.m_type = type;
@ -576,7 +576,7 @@ float Tokenizer::convert_a_string_to_a_number(StringView string)
}
// https://www.w3.org/TR/css-syntax-3/#consume-name
String Tokenizer::consume_an_ident_sequence()
DeprecatedString Tokenizer::consume_an_ident_sequence()
{
// This section describes how to consume an ident sequence from a stream of code points.
// It returns a string containing the largest name that can be formed from adjacent

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <AK/Utf8View.h>
@ -60,7 +60,7 @@ public:
class Tokenizer {
public:
explicit Tokenizer(StringView input, String const& encoding);
explicit Tokenizer(StringView input, DeprecatedString const& encoding);
[[nodiscard]] Vector<Token> parse();
@ -76,7 +76,7 @@ private:
[[nodiscard]] U32Triplet start_of_input_stream_triplet();
[[nodiscard]] static Token create_new_token(Token::Type);
[[nodiscard]] static Token create_value_token(Token::Type, String value);
[[nodiscard]] static Token create_value_token(Token::Type, DeprecatedString value);
[[nodiscard]] static Token create_value_token(Token::Type, u32 value);
[[nodiscard]] Token consume_a_token();
[[nodiscard]] Token consume_string_token(u32 ending_code_point);
@ -84,7 +84,7 @@ private:
[[nodiscard]] Token consume_an_ident_like_token();
[[nodiscard]] Number consume_a_number();
[[nodiscard]] float convert_a_string_to_a_number(StringView);
[[nodiscard]] String consume_an_ident_sequence();
[[nodiscard]] DeprecatedString consume_an_ident_sequence();
[[nodiscard]] u32 consume_escaped_code_point();
[[nodiscard]] Token consume_a_url_token();
void consume_the_remnants_of_a_bad_url();
@ -95,7 +95,7 @@ private:
[[nodiscard]] static bool would_start_an_ident_sequence(U32Triplet);
[[nodiscard]] static bool would_start_a_number(U32Triplet);
String m_decoded_input;
DeprecatedString m_decoded_input;
Utf8View m_utf8_view;
AK::Utf8CodePointIterator m_utf8_iterator;
AK::Utf8CodePointIterator m_prev_utf8_iterator;