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

Everywhere: Rename {Deprecated => Byte}String

This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
Ali Mohammad Pur 2023-12-16 17:49:34 +03:30 committed by Ali Mohammad Pur
parent 38d62563b3
commit 5e1499d104
1615 changed files with 10257 additions and 10257 deletions

View file

@ -68,16 +68,16 @@ static bool is_ui_dimension_property(StringView property)
}
// FIXME: Since normal string-based properties take either String or StringView (and the latter can be implicitly constructed from the former),
// we need to special-case DeprecatedString property setters while those still exist.
// we need to special-case ByteString property setters while those still exist.
// Please remove a setter from this list once it uses StringView or String.
static bool takes_deprecated_string(StringView property)
static bool takes_byte_string(StringView property)
{
static HashTable<StringView> deprecated_string_properties;
if (deprecated_string_properties.is_empty()) {
deprecated_string_properties.set("icon_from_path"sv);
deprecated_string_properties.set("name"sv);
static HashTable<StringView> byte_string_properties;
if (byte_string_properties.is_empty()) {
byte_string_properties.set("icon_from_path"sv);
byte_string_properties.set("name"sv);
}
return deprecated_string_properties.contains(property);
return byte_string_properties.contains(property);
}
static ErrorOr<String> include_path_for(StringView class_name, LexicalPath const& gml_file_name)
@ -141,7 +141,7 @@ static char const footer[] = R"~~~(
static ErrorOr<String> escape_string(JsonValue to_escape)
{
auto string = TRY(String::from_deprecated_string(to_escape.as_string()));
auto string = TRY(String::from_byte_string(to_escape.as_string()));
// All C++ simple escape sequences; see https://en.cppreference.com/w/cpp/language/escape
// Other commonly-escaped characters are hard-to-type Unicode and therefore fine to include verbatim in UTF-8 coded strings.
@ -194,7 +194,7 @@ static ErrorOr<String> generate_initializer_for(Optional<StringView> property_na
{
if (value.is_string()) {
if (property_name.has_value()) {
if (takes_deprecated_string(*property_name))
if (takes_byte_string(*property_name))
return String::formatted(R"~~~("{}"sv)~~~", TRY(escape_string(value)));
if (auto const enum_value = TRY(generate_enum_initializer_for(*property_name, value)); enum_value.has_value())
@ -252,7 +252,7 @@ static ErrorOr<String> generate_initializer_for(Optional<StringView> property_na
// All loading happens in a separate block.
static ErrorOr<void> generate_loader_for_object(GUI::GML::Object const& gml_object, SourceGenerator generator, String object_name, size_t indentation, UseObjectConstructor use_object_constructor)
{
generator.set("object_name", object_name.to_deprecated_string());
generator.set("object_name", object_name.to_byte_string());
generator.set("class_name", gml_object.name());
auto append = [&]<size_t N>(auto& generator, char const(&text)[N]) -> ErrorOr<void> {

View file

@ -17,12 +17,12 @@
#include <stdio.h>
struct Parameter {
Vector<DeprecatedString> attributes;
DeprecatedString type;
DeprecatedString name;
Vector<ByteString> attributes;
ByteString type;
ByteString name;
};
static DeprecatedString pascal_case(DeprecatedString const& identifier)
static ByteString pascal_case(ByteString const& identifier)
{
StringBuilder builder;
bool was_new_word = true;
@ -37,48 +37,48 @@ static DeprecatedString pascal_case(DeprecatedString const& identifier)
} else
builder.append(ch);
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
struct Message {
DeprecatedString name;
ByteString name;
bool is_synchronous { false };
Vector<Parameter> inputs;
Vector<Parameter> outputs;
DeprecatedString response_name() const
ByteString response_name() const
{
StringBuilder builder;
builder.append(pascal_case(name));
builder.append("Response"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
};
struct Endpoint {
Vector<DeprecatedString> includes;
DeprecatedString name;
Vector<ByteString> includes;
ByteString name;
u32 magic;
Vector<Message> messages;
};
static bool is_primitive_type(DeprecatedString const& type)
static bool is_primitive_type(ByteString const& type)
{
return type.is_one_of("u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "size_t", "bool", "double", "float", "int", "unsigned", "unsigned int");
}
static bool is_simple_type(DeprecatedString const& type)
static bool is_simple_type(ByteString const& type)
{
// Small types that it makes sense just to pass by value.
return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode");
}
static bool is_primitive_or_simple_type(DeprecatedString const& type)
static bool is_primitive_or_simple_type(ByteString const& type)
{
return is_primitive_type(type) || is_simple_type(type);
}
static DeprecatedString message_name(DeprecatedString const& endpoint, DeprecatedString const& message, bool is_response)
static ByteString message_name(ByteString const& endpoint, ByteString const& message, bool is_response)
{
StringBuilder builder;
builder.append("Messages::"sv);
@ -87,7 +87,7 @@ static DeprecatedString message_name(DeprecatedString const& endpoint, Deprecate
builder.append(pascal_case(message));
if (is_response)
builder.append("Response"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
Vector<Endpoint> parse(ByteBuffer const& file_contents)
@ -133,7 +133,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
consume_whitespace();
}
}
// FIXME: This is not entirely correct. Types can have spaces, for example `HashMap<int, DeprecatedString>`.
// FIXME: This is not entirely correct. Types can have spaces, for example `HashMap<int, ByteString>`.
// Maybe we should use LibCpp::Parser for parsing types.
parameter.type = lexer.consume_until([](char ch) { return isspace(ch); });
if (parameter.type.ends_with(',')) {
@ -208,7 +208,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
};
auto parse_include = [&] {
DeprecatedString include;
ByteString include;
consume_whitespace();
include = lexer.consume_while([](char ch) { return ch != '\n'; });
consume_whitespace();
@ -234,7 +234,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
lexer.consume_specific("endpoint");
consume_whitespace();
endpoints.last().name = lexer.consume_while([](char ch) { return !isspace(ch); });
endpoints.last().magic = Traits<DeprecatedString>::hash(endpoints.last().name);
endpoints.last().magic = Traits<ByteString>::hash(endpoints.last().name);
consume_whitespace();
assert_specific('{');
parse_messages();
@ -248,22 +248,22 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
return endpoints;
}
HashMap<DeprecatedString, int> build_message_ids_for_endpoint(SourceGenerator generator, Endpoint const& endpoint)
HashMap<ByteString, int> build_message_ids_for_endpoint(SourceGenerator generator, Endpoint const& endpoint)
{
HashMap<DeprecatedString, int> message_ids;
HashMap<ByteString, int> message_ids;
generator.appendln("\nenum class MessageID : i32 {");
for (auto const& message : endpoint.messages) {
message_ids.set(message.name, message_ids.size() + 1);
generator.set("message.pascal_name", pascal_case(message.name));
generator.set("message.id", DeprecatedString::number(message_ids.size()));
generator.set("message.id", ByteString::number(message_ids.size()));
generator.appendln(" @message.pascal_name@ = @message.id@,");
if (message.is_synchronous) {
message_ids.set(message.response_name(), message_ids.size() + 1);
generator.set("message.pascal_name", pascal_case(message.response_name()));
generator.set("message.id", DeprecatedString::number(message_ids.size()));
generator.set("message.id", ByteString::number(message_ids.size()));
generator.appendln(" @message.pascal_name@ = @message.id@,");
}
@ -272,14 +272,14 @@ HashMap<DeprecatedString, int> build_message_ids_for_endpoint(SourceGenerator ge
return message_ids;
}
DeprecatedString constructor_for_message(DeprecatedString const& name, Vector<Parameter> const& parameters)
ByteString constructor_for_message(ByteString const& name, Vector<Parameter> const& parameters)
{
StringBuilder builder;
builder.append(name);
if (parameters.is_empty()) {
builder.append("() {}"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
builder.append('(');
for (size_t i = 0; i < parameters.size(); ++i) {
@ -296,10 +296,10 @@ DeprecatedString constructor_for_message(DeprecatedString const& name, Vector<Pa
builder.append(", "sv);
}
builder.append(" {}"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
void do_message(SourceGenerator message_generator, DeprecatedString const& name, Vector<Parameter> const& parameters, DeprecatedString const& response_type = {})
void do_message(SourceGenerator message_generator, ByteString const& name, Vector<Parameter> const& parameters, ByteString const& response_type = {})
{
auto pascal_name = pascal_case(name);
message_generator.set("message.name", name);
@ -377,7 +377,7 @@ public:)~~~");
builder.append(", "sv);
}
message_generator.set("message.constructor_call_parameters", builder.to_deprecated_string());
message_generator.set("message.constructor_call_parameters", builder.to_byte_string());
message_generator.appendln(R"~~~(
return make<@message.pascal_name@>(@message.constructor_call_parameters@);
})~~~");
@ -432,17 +432,17 @@ private:
void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& endpoint, Message const& message)
{
auto do_implement_proxy = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_synchronous, bool is_try) {
DeprecatedString return_type = "void";
auto do_implement_proxy = [&](ByteString const& name, Vector<Parameter> const& parameters, bool is_synchronous, bool is_try) {
ByteString return_type = "void";
if (is_synchronous) {
if (message.outputs.size() == 1)
return_type = message.outputs[0].type;
else if (!message.outputs.is_empty())
return_type = message_name(endpoint.name, message.name, true);
}
DeprecatedString inner_return_type = return_type;
ByteString inner_return_type = return_type;
if (is_try)
return_type = DeprecatedString::formatted("IPC::IPCErrorOr<{}>", return_type);
return_type = ByteString::formatted("IPC::IPCErrorOr<{}>", return_type);
message_generator.set("message.name", message.name);
message_generator.set("message.pascal_name", pascal_case(message.name));
@ -541,14 +541,14 @@ void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& end
void build_endpoint(SourceGenerator generator, Endpoint const& endpoint)
{
generator.set("endpoint.name", endpoint.name);
generator.set("endpoint.magic", DeprecatedString::number(endpoint.magic));
generator.set("endpoint.magic", ByteString::number(endpoint.magic));
generator.appendln("\nnamespace Messages::@endpoint.name@ {");
HashMap<DeprecatedString, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
HashMap<ByteString, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
for (auto const& message : endpoint.messages) {
DeprecatedString response_name;
ByteString response_name;
if (message.is_synchronous) {
response_name = message.response_name();
do_message(generator.fork(), response_name, message.outputs);
@ -611,7 +611,7 @@ public:
switch (message_id) {)~~~");
for (auto const& message : endpoint.messages) {
auto do_decode_message = [&](DeprecatedString const& name) {
auto do_decode_message = [&](ByteString const& name) {
auto message_generator = generator.fork();
message_generator.set("message.name", name);
@ -649,13 +649,13 @@ public:
virtual ~@endpoint.name@Stub() override { }
virtual u32 magic() const override { return @endpoint.magic@; }
virtual DeprecatedString name() const override { return "@endpoint.name@"; }
virtual ByteString name() const override { return "@endpoint.name@"; }
virtual ErrorOr<OwnPtr<IPC::MessageBuffer>> handle(const IPC::Message& message) override
{
switch (message.message_id()) {)~~~");
for (auto const& message : endpoint.messages) {
auto do_handle_message = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool returns_something) {
auto do_handle_message = [&](ByteString const& name, Vector<Parameter> const& parameters, bool returns_something) {
auto message_generator = generator.fork();
StringBuilder argument_generator;
@ -671,7 +671,7 @@ public:
message_generator.set("message.pascal_name", pascal_case(name));
message_generator.set("message.response_type", pascal_case(message.response_name()));
message_generator.set("handler_name", name);
message_generator.set("arguments", argument_generator.to_deprecated_string());
message_generator.set("arguments", argument_generator.to_byte_string());
message_generator.appendln(R"~~~(
case (int)Messages::@endpoint.name@::MessageID::@message.pascal_name@: {)~~~");
if (returns_something) {
@ -709,8 +709,8 @@ public:
for (auto const& message : endpoint.messages) {
auto message_generator = generator.fork();
auto do_handle_message_decl = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_response) {
DeprecatedString return_type = "void";
auto do_handle_message_decl = [&](ByteString const& name, Vector<Parameter> const& parameters, bool is_response) {
ByteString return_type = "void";
if (message.is_synchronous && !message.outputs.is_empty() && !is_response)
return_type = message_name(endpoint.name, message.name, true);
message_generator.set("message.complex_return_type", return_type);
@ -719,7 +719,7 @@ public:
message_generator.appendln(R"~~~(
virtual @message.complex_return_type@ @handler_name@()~~~");
auto make_argument_type = [](DeprecatedString const& type) {
auto make_argument_type = [](ByteString const& type) {
StringBuilder builder;
bool const_ref = !is_primitive_or_simple_type(type);
@ -728,7 +728,7 @@ public:
if (const_ref)
builder.append(" const&"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
};
for (size_t i = 0; i < parameters.size(); ++i) {

View file

@ -5,7 +5,7 @@
*/
#include <AK/Array.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/JsonObject.h>
#include <AK/NumericLimits.h>
#include <AK/Optional.h>
@ -18,40 +18,40 @@
#include <LibMain/Main.h>
struct ArgumentDefinition {
Optional<DeprecatedString> name;
Optional<DeprecatedString> cpp_type;
DeprecatedString expression;
Optional<DeprecatedString> cast_to;
Optional<ByteString> name;
Optional<ByteString> cpp_type;
ByteString expression;
Optional<ByteString> cast_to;
};
struct FunctionDefinition {
DeprecatedString name;
DeprecatedString return_type;
ByteString name;
ByteString return_type;
Vector<ArgumentDefinition> arguments;
DeprecatedString implementation;
ByteString implementation;
bool unimplemented;
DeprecatedString variant_gl_type;
ByteString variant_gl_type;
};
struct VariantType {
DeprecatedString encoded_type;
Optional<DeprecatedString> implementation;
ByteString encoded_type;
Optional<ByteString> implementation;
bool unimplemented;
};
struct Variants {
Vector<DeprecatedString> api_suffixes { "" };
Vector<ByteString> api_suffixes { "" };
Vector<u32> argument_counts { NumericLimits<u32>::max() };
Vector<DeprecatedString> argument_defaults { "" };
Vector<ByteString> argument_defaults { "" };
bool convert_range { false };
Vector<VariantType> types {
{
.encoded_type = "",
.implementation = Optional<DeprecatedString> {},
.implementation = Optional<ByteString> {},
.unimplemented = false,
}
};
DeprecatedString pointer_argument { "" };
ByteString pointer_argument { "" };
};
struct EncodedTypeEntry {
@ -76,18 +76,18 @@ constexpr static Array<EncodedTypeEntry, 9> type_definitions = {
struct EncodedType {
EncodedTypeEntry type_entry;
DeprecatedString cpp_type;
DeprecatedString function_name_suffix;
ByteString cpp_type;
ByteString function_name_suffix;
bool is_pointer;
bool is_const_pointer;
};
Vector<DeprecatedString> get_name_list(Optional<JsonValue const&> name_definition)
Vector<ByteString> get_name_list(Optional<JsonValue const&> name_definition)
{
if (!name_definition.has_value() || name_definition->is_null())
return {};
Vector<DeprecatedString, 1> names;
Vector<ByteString, 1> names;
if (name_definition->is_string()) {
names.append(name_definition->as_string());
} else if (name_definition->is_array()) {
@ -101,12 +101,12 @@ Vector<DeprecatedString> get_name_list(Optional<JsonValue const&> name_definitio
return names;
}
Optional<EncodedType> get_encoded_type(DeprecatedString encoded_type)
Optional<EncodedType> get_encoded_type(ByteString encoded_type)
{
bool is_const_pointer = !encoded_type.ends_with('!');
if (!is_const_pointer)
encoded_type = encoded_type.substring_view(0, encoded_type.length() - 1);
DeprecatedString function_name_suffix = encoded_type;
ByteString function_name_suffix = encoded_type;
bool is_pointer = encoded_type.ends_with('v');
if (is_pointer)
@ -127,7 +127,7 @@ Optional<EncodedType> get_encoded_type(DeprecatedString encoded_type)
return EncodedType {
.type_entry = type_definition.value(),
.cpp_type = DeprecatedString::formatted(
.cpp_type = ByteString::formatted(
"{}{}{}",
type_definition->cpp_type,
is_pointer && is_const_pointer ? " const" : "",
@ -138,7 +138,7 @@ Optional<EncodedType> get_encoded_type(DeprecatedString encoded_type)
};
}
DeprecatedString wrap_expression_in_range_conversion(DeprecatedString source_type, DeprecatedString target_type, DeprecatedString expression)
ByteString wrap_expression_in_range_conversion(ByteString source_type, ByteString target_type, ByteString expression)
{
VERIFY(target_type == "GLfloat" || target_type == "GLdouble");
@ -147,19 +147,19 @@ DeprecatedString wrap_expression_in_range_conversion(DeprecatedString source_typ
return expression;
if (source_type == "GLbyte")
return DeprecatedString::formatted("({} + 128.) / 127.5 - 1.", expression);
return ByteString::formatted("({} + 128.) / 127.5 - 1.", expression);
else if (source_type == "GLfloat")
return DeprecatedString::formatted("static_cast<GLdouble>({})", expression);
return ByteString::formatted("static_cast<GLdouble>({})", expression);
else if (source_type == "GLint")
return DeprecatedString::formatted("({} + 2147483648.) / 2147483647.5 - 1.", expression);
return ByteString::formatted("({} + 2147483648.) / 2147483647.5 - 1.", expression);
else if (source_type == "GLshort")
return DeprecatedString::formatted("({} + 32768.) / 32767.5 - 1.", expression);
return ByteString::formatted("({} + 32768.) / 32767.5 - 1.", expression);
else if (source_type == "GLubyte")
return DeprecatedString::formatted("{} / 255.", expression);
return ByteString::formatted("{} / 255.", expression);
else if (source_type == "GLuint")
return DeprecatedString::formatted("{} / 4294967296.", expression);
return ByteString::formatted("{} / 4294967296.", expression);
else if (source_type == "GLushort")
return DeprecatedString::formatted("{} / 65536.", expression);
return ByteString::formatted("{} / 65536.", expression);
VERIFY_NOT_REACHED();
}
@ -189,7 +189,7 @@ Variants read_variants_settings(JsonObject const& variants_obj)
});
}
if (variants_obj.has_string("pointer_argument"sv)) {
variants.pointer_argument = variants_obj.get_deprecated_string("pointer_argument"sv).value();
variants.pointer_argument = variants_obj.get_byte_string("pointer_argument"sv).value();
}
if (variants_obj.has_object("types"sv)) {
variants.types.clear_with_capacity();
@ -197,7 +197,7 @@ Variants read_variants_settings(JsonObject const& variants_obj)
auto const& type = type_value.as_object();
variants.types.append(VariantType {
.encoded_type = key,
.implementation = type.get_deprecated_string("implementation"sv),
.implementation = type.get_byte_string("implementation"sv),
.unimplemented = type.get_bool("unimplemented"sv).value_or(false),
});
});
@ -223,20 +223,20 @@ Vector<ArgumentDefinition> copy_arguments_for_variant(Vector<ArgumentDefinition>
// Pointer argument
if (encoded_type.is_pointer) {
variant_arguments[i].name = (variadic_index == 0) ? variants.pointer_argument : Optional<DeprecatedString> {};
variant_arguments[i].name = (variadic_index == 0) ? variants.pointer_argument : Optional<ByteString> {};
if (variadic_index >= argument_count) {
// If this variable argument is past the argument count, fall back to the defaults
variant_arguments[i].expression = variants.argument_defaults[variadic_index];
variant_arguments[i].cast_to = Optional<DeprecatedString> {};
variant_arguments[i].cast_to = Optional<ByteString> {};
} else if (argument_count == 1 && variants.argument_counts.size() == 1) {
// Otherwise, if the pointer is the only variadic argument, pass it through unchanged
variant_arguments[i].cast_to = Optional<DeprecatedString> {};
variant_arguments[i].cast_to = Optional<ByteString> {};
} else {
// Otherwise, index into the pointer argument
auto indexed_expression = DeprecatedString::formatted("{}[{}]", variants.pointer_argument, variadic_index);
auto indexed_expression = ByteString::formatted("{}[{}]", variants.pointer_argument, variadic_index);
if (variants.convert_range && cast_to.has_value())
indexed_expression = wrap_expression_in_range_conversion(base_cpp_type, cast_to.value(), indexed_expression);
variant_arguments[i].expression = indexed_expression;
@ -246,9 +246,9 @@ Vector<ArgumentDefinition> copy_arguments_for_variant(Vector<ArgumentDefinition>
// Regular argument
if (variadic_index >= argument_count) {
// If the variable argument is past the argument count, fall back to the defaults
variant_arguments[i].name = Optional<DeprecatedString> {};
variant_arguments[i].name = Optional<ByteString> {};
variant_arguments[i].expression = variants.argument_defaults[variadic_index];
variant_arguments[i].cast_to = Optional<DeprecatedString> {};
variant_arguments[i].cast_to = Optional<ByteString> {};
} else if (variants.convert_range && cast_to.has_value()) {
// Otherwise, if we need to convert the input values, wrap the expression in a range conversion
@ -261,7 +261,7 @@ Vector<ArgumentDefinition> copy_arguments_for_variant(Vector<ArgumentDefinition>
// Determine if we can skip casting to the target type
if (cast_to == base_cpp_type || (variants.convert_range && cast_to == "GLdouble"))
variant_arguments[i].cast_to = Optional<DeprecatedString> {};
variant_arguments[i].cast_to = Optional<ByteString> {};
variadic_index++;
}
@ -269,7 +269,7 @@ Vector<ArgumentDefinition> copy_arguments_for_variant(Vector<ArgumentDefinition>
return variant_arguments;
}
Vector<FunctionDefinition> create_function_definitions(DeprecatedString function_name, JsonObject const& function_definition)
Vector<FunctionDefinition> create_function_definitions(ByteString function_name, JsonObject const& function_definition)
{
// A single function definition can expand to multiple generated functions by way of:
// - differing API suffices (ARB, EXT, etc.);
@ -284,17 +284,17 @@ Vector<FunctionDefinition> create_function_definitions(DeprecatedString function
VERIFY(argument_value.is_object());
auto const& argument = argument_value.as_object();
auto type = argument.get_deprecated_string("type"sv);
auto type = argument.get_byte_string("type"sv);
auto argument_names = get_name_list(argument.get("name"sv));
auto expression = argument.get_deprecated_string("expression"sv).value_or("@argument_name@");
auto cast_to = argument.get_deprecated_string("cast_to"sv);
auto expression = argument.get_byte_string("expression"sv).value_or("@argument_name@");
auto cast_to = argument.get_byte_string("cast_to"sv);
// Add an empty dummy name when all we have is an expression
if (argument_names.is_empty() && !expression.is_empty())
argument_names.append("");
for (auto const& argument_name : argument_names) {
argument_definitions.append({ .name = argument_name.is_empty() ? Optional<DeprecatedString> {} : argument_name,
argument_definitions.append({ .name = argument_name.is_empty() ? Optional<ByteString> {} : argument_name,
.cpp_type = type,
.expression = expression,
.cast_to = cast_to });
@ -304,8 +304,8 @@ Vector<FunctionDefinition> create_function_definitions(DeprecatedString function
// Create functions for each name and/or variant
Vector<FunctionDefinition> functions;
auto return_type = function_definition.get_deprecated_string("return_type"sv).value_or("void");
auto function_implementation = function_definition.get_deprecated_string("implementation"sv).value_or(function_name.to_snakecase());
auto return_type = function_definition.get_byte_string("return_type"sv).value_or("void");
auto function_implementation = function_definition.get_byte_string("implementation"sv).value_or(function_name.to_snakecase());
auto function_unimplemented = function_definition.get_bool("unimplemented"sv).value_or(false);
if (!function_definition.has("variants"sv)) {
@ -336,10 +336,10 @@ Vector<FunctionDefinition> create_function_definitions(DeprecatedString function
for (auto const& api_suffix : variants.api_suffixes) {
functions.append({
.name = DeprecatedString::formatted(
.name = ByteString::formatted(
"{}{}{}{}",
function_name,
variants.argument_counts.size() > 1 ? DeprecatedString::formatted("{}", argument_count) : "",
variants.argument_counts.size() > 1 ? ByteString::formatted("{}", argument_count) : "",
encoded_type.has_value() && variants.types.size() > 1 ? encoded_type->function_name_suffix : "",
api_suffix),
.return_type = return_type,

View file

@ -6,8 +6,8 @@
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/AllOf.h>
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/Find.h>
#include <AK/Format.h>
@ -487,7 +487,7 @@ struct AK::Formatter<Locale::HourCycle> : Formatter<FormatString> {
};
struct LocaleData {
HashMap<DeprecatedString, size_t> calendars;
HashMap<ByteString, size_t> calendars;
size_t time_zones { 0 };
size_t time_zone_formats { 0 };
@ -513,27 +513,27 @@ struct CLDR {
UniqueStorage<DayPeriodList> unique_day_period_lists;
UniqueStorage<HourCycleList> unique_hour_cycle_lists;
HashMap<DeprecatedString, LocaleData> locales;
HashMap<ByteString, LocaleData> locales;
HashMap<DeprecatedString, size_t> hour_cycles;
Vector<DeprecatedString> hour_cycle_regions;
HashMap<ByteString, size_t> hour_cycles;
Vector<ByteString> hour_cycle_regions;
HashMap<DeprecatedString, u8> minimum_days;
Vector<DeprecatedString> minimum_days_regions;
HashMap<ByteString, u8> minimum_days;
Vector<ByteString> minimum_days_regions;
HashMap<DeprecatedString, Locale::Weekday> first_day;
Vector<DeprecatedString> first_day_regions;
HashMap<ByteString, Locale::Weekday> first_day;
Vector<ByteString> first_day_regions;
HashMap<DeprecatedString, Locale::Weekday> weekend_start;
Vector<DeprecatedString> weekend_start_regions;
HashMap<ByteString, Locale::Weekday> weekend_start;
Vector<ByteString> weekend_start_regions;
HashMap<DeprecatedString, Locale::Weekday> weekend_end;
Vector<DeprecatedString> weekend_end_regions;
HashMap<ByteString, Locale::Weekday> weekend_end;
Vector<ByteString> weekend_end_regions;
HashMap<DeprecatedString, Vector<TimeZone::TimeZone>> meta_zones;
Vector<DeprecatedString> time_zones { "UTC"sv };
HashMap<ByteString, Vector<TimeZone::TimeZone>> meta_zones;
Vector<ByteString> time_zones { "UTC"sv };
Vector<DeprecatedString> calendars;
Vector<ByteString> calendars;
};
static Optional<Locale::DayPeriod> day_period_from_string(StringView day_period)
@ -563,7 +563,7 @@ static Optional<Locale::DayPeriod> day_period_from_string(StringView day_period)
return {};
}
static ErrorOr<void> parse_hour_cycles(DeprecatedString core_path, CLDR& cldr)
static ErrorOr<void> parse_hour_cycles(ByteString core_path, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Data
LexicalPath time_data_path(move(core_path));
@ -587,7 +587,7 @@ static ErrorOr<void> parse_hour_cycles(DeprecatedString core_path, CLDR& cldr)
};
time_data_object.for_each_member([&](auto const& key, JsonValue const& value) {
auto allowed_hour_cycles_string = value.as_object().get_deprecated_string("_allowed"sv).value();
auto allowed_hour_cycles_string = value.as_object().get_byte_string("_allowed"sv).value();
auto allowed_hour_cycles = allowed_hour_cycles_string.split_view(' ');
Vector<Locale::HourCycle> hour_cycles;
@ -607,7 +607,7 @@ static ErrorOr<void> parse_hour_cycles(DeprecatedString core_path, CLDR& cldr)
return {};
}
static ErrorOr<void> parse_week_data(DeprecatedString core_path, CLDR& cldr)
static ErrorOr<void> parse_week_data(ByteString core_path, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Week_Data
LexicalPath week_data_path(move(core_path));
@ -672,7 +672,7 @@ static ErrorOr<void> parse_week_data(DeprecatedString core_path, CLDR& cldr)
return {};
}
static ErrorOr<void> parse_meta_zones(DeprecatedString core_path, CLDR& cldr)
static ErrorOr<void> parse_meta_zones(ByteString core_path, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Metazones
LexicalPath meta_zone_path(move(core_path));
@ -686,8 +686,8 @@ static ErrorOr<void> parse_meta_zones(DeprecatedString core_path, CLDR& cldr)
meta_zone_array.for_each([&](JsonValue const& value) {
auto const& mapping = value.as_object().get_object("mapZone"sv).value();
auto const& meta_zone = mapping.get_deprecated_string("_other"sv).value();
auto const& golden_zone = mapping.get_deprecated_string("_type"sv).value();
auto const& meta_zone = mapping.get_byte_string("_other"sv).value();
auto const& golden_zone = mapping.get_byte_string("_type"sv).value();
if (auto time_zone = TimeZone::time_zone_from_string(golden_zone); time_zone.has_value()) {
auto& golden_zones = cldr.meta_zones.ensure(meta_zone);
@ -770,7 +770,7 @@ static ErrorOr<String> remove_period_from_pattern(String pattern)
return pattern;
}
static ErrorOr<Optional<CalendarPattern>> parse_date_time_pattern_raw(DeprecatedString pattern, DeprecatedString skeleton, CLDR& cldr)
static ErrorOr<Optional<CalendarPattern>> parse_date_time_pattern_raw(ByteString pattern, ByteString skeleton, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
using Locale::CalendarPatternStyle;
@ -989,16 +989,16 @@ static ErrorOr<Optional<CalendarPattern>> parse_date_time_pattern_raw(Deprecated
return format;
}
static ErrorOr<Optional<size_t>> parse_date_time_pattern(DeprecatedString pattern, DeprecatedString skeleton, CLDR& cldr)
static ErrorOr<Optional<size_t>> parse_date_time_pattern(ByteString pattern, ByteString skeleton, CLDR& cldr)
{
auto format = TRY(parse_date_time_pattern_raw(move(pattern), move(skeleton), cldr));
if (!format.has_value())
return OptionalNone {};
format->pattern_index = cldr.unique_strings.ensure(format->pattern.to_deprecated_string());
format->pattern_index = cldr.unique_strings.ensure(format->pattern.to_byte_string());
if (format->pattern12.has_value())
format->pattern12_index = cldr.unique_strings.ensure(format->pattern12->to_deprecated_string());
format->pattern12_index = cldr.unique_strings.ensure(format->pattern12->to_byte_string());
return Optional<size_t> { cldr.unique_patterns.ensure(format.release_value()) };
}
@ -1388,7 +1388,7 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
calendar.symbols = cldr.unique_calendar_symbols_lists.ensure(move(symbols_list));
}
static ErrorOr<void> parse_calendars(DeprecatedString locale_calendars_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_calendars(ByteString locale_calendars_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath calendars_path(move(locale_calendars_path));
if (!calendars_path.basename().starts_with("ca-"sv))
@ -1402,10 +1402,10 @@ static ErrorOr<void> parse_calendars(DeprecatedString locale_calendars_path, CLD
auto parse_patterns = [&](auto const& patterns_object, auto const& skeletons_object, Vector<CalendarPattern>* patterns) -> ErrorOr<size_t> {
auto parse_pattern = [&](auto name) -> ErrorOr<size_t> {
auto format = patterns_object.get_deprecated_string(name);
auto skeleton = skeletons_object.get_deprecated_string(name);
auto format = patterns_object.get_byte_string(name);
auto skeleton = skeletons_object.get_byte_string(name);
auto format_index = TRY(parse_date_time_pattern(format.value(), skeleton.value_or(DeprecatedString::empty()), cldr)).value();
auto format_index = TRY(parse_date_time_pattern(format.value(), skeleton.value_or(ByteString::empty()), cldr)).value();
if (patterns)
patterns->append(cldr.unique_patterns.get(format_index));
@ -1483,7 +1483,7 @@ static ErrorOr<void> parse_calendars(DeprecatedString locale_calendars_path, CLD
return {};
}
static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_names_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_time_zone_names(ByteString locale_time_zone_names_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath time_zone_names_path(move(locale_time_zone_names_path));
time_zone_names_path = time_zone_names_path.append("timeZoneNames.json"sv);
@ -1494,9 +1494,9 @@ static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_nam
auto const& dates_object = locale_object.get_object("dates"sv).value();
auto const& time_zone_names_object = dates_object.get_object("timeZoneNames"sv).value();
auto const& meta_zone_object = time_zone_names_object.get_object("metazone"sv);
auto const& hour_format_string = time_zone_names_object.get_deprecated_string("hourFormat"sv).value();
auto const& gmt_format_string = time_zone_names_object.get_deprecated_string("gmtFormat"sv).value();
auto const& gmt_zero_format_string = time_zone_names_object.get_deprecated_string("gmtZeroFormat"sv).value();
auto const& hour_format_string = time_zone_names_object.get_byte_string("hourFormat"sv).value();
auto const& gmt_format_string = time_zone_names_object.get_byte_string("gmtFormat"sv).value();
auto const& gmt_zero_format_string = time_zone_names_object.get_byte_string("gmtZeroFormat"sv).value();
if (!meta_zone_object.has_value())
return {};
@ -1506,7 +1506,7 @@ static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_nam
if (!names.has_value())
return {};
auto const& name = names->get_deprecated_string(key);
auto const& name = names->get_byte_string(key);
if (name.has_value())
return cldr.unique_strings.ensure(name.value());
@ -1592,7 +1592,7 @@ static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_nam
return {};
}
static ErrorOr<void> parse_day_periods(DeprecatedString core_path, CLDR& cldr)
static ErrorOr<void> parse_day_periods(ByteString core_path, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Day_Period_Rule_Sets
LexicalPath day_periods_path(move(core_path));
@ -1622,8 +1622,8 @@ static ErrorOr<void> parse_day_periods(DeprecatedString core_path, CLDR& cldr)
if (!day_period.has_value())
return {};
auto begin = parse_hour(ranges.get_deprecated_string("_from"sv).value());
auto end = parse_hour(ranges.get_deprecated_string("_before"sv).value());
auto begin = parse_hour(ranges.get_byte_string("_from"sv).value());
auto end = parse_hour(ranges.get_byte_string("_before"sv).value());
return DayPeriod { *day_period, begin, end };
};
@ -1648,13 +1648,13 @@ static ErrorOr<void> parse_day_periods(DeprecatedString core_path, CLDR& cldr)
return {};
}
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString dates_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(ByteString core_path, ByteString dates_path, CLDR& cldr)
{
TRY(parse_hour_cycles(core_path, cldr));
TRY(parse_week_data(core_path, cldr));
TRY(parse_meta_zones(core_path, cldr));
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -1664,7 +1664,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
builder.appendff("-{}", region);
return builder.to_deprecated_string();
return builder.to_byte_string();
};
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
@ -1687,15 +1687,15 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
return {};
}
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
static ByteString format_identifier(StringView owner, ByteString identifier)
{
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
if (all_of(identifier, is_ascii_digit))
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
return ByteString::formatted("{}_{}", owner[0], identifier);
if (is_ascii_lower_alpha(identifier[0]))
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return ByteString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return identifier;
}
@ -1953,9 +1953,9 @@ struct DayPeriodData {
cldr.unique_day_period_lists.generate(generator, cldr.unique_day_periods.type_that_fits(), "s_day_period_lists"sv);
cldr.unique_hour_cycle_lists.generate(generator, cldr.unique_hour_cycle_lists.type_that_fits(), "s_hour_cycle_lists"sv);
auto append_calendars = [&](DeprecatedString name, auto const& calendars) {
auto append_calendars = [&](ByteString name, auto const& calendars) {
generator.set("name", name);
generator.set("size", DeprecatedString::number(calendars.size()));
generator.set("size", ByteString::number(calendars.size()));
generator.append(R"~~~(
static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
@ -1965,7 +1965,7 @@ static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
auto calendar = calendars.find(calendar_key)->value;
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::number(calendar));
generator.append(ByteString::number(calendar));
first = false;
}
@ -1975,7 +1975,7 @@ static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
auto append_mapping = [&](auto const& keys, auto const& map, auto type, auto name, auto mapping_getter) {
generator.set("type", type);
generator.set("name", name);
generator.set("size", DeprecatedString::number(keys.size()));
generator.set("size", ByteString::number(keys.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {)~~~");
@ -1986,7 +1986,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
auto mapping = mapping_getter(value);
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::number(mapping));
generator.append(ByteString::number(mapping));
first = false;
}
@ -2008,7 +2008,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
generator.append("\n");
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) -> ErrorOr<void> {
HashValueMap<DeprecatedString> hashes;
HashValueMap<ByteString> hashes;
TRY(hashes.try_ensure_capacity(values.size()));
for (auto const& value : values)

View file

@ -6,8 +6,8 @@
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/AllOf.h>
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/Format.h>
#include <AK/HashMap.h>
@ -22,14 +22,14 @@
#include <LibCore/Directory.h>
#include <LibFileSystem/FileSystem.h>
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
static ByteString format_identifier(StringView owner, ByteString identifier)
{
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
if (all_of(identifier, is_ascii_digit))
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
return ByteString::formatted("{}_{}", owner[0], identifier);
if (is_ascii_lower_alpha(identifier[0]))
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return ByteString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return identifier;
}
@ -153,9 +153,9 @@ using KeywordList = Vector<size_t>;
using ListPatternList = Vector<size_t>;
struct LocaleData {
DeprecatedString language;
Optional<DeprecatedString> territory;
Optional<DeprecatedString> variant;
ByteString language;
Optional<ByteString> territory;
Optional<ByteString> variant;
size_t display_patterns { 0 };
size_t languages { 0 };
size_t territories { 0 };
@ -195,25 +195,25 @@ struct CLDR {
UniqueStorage<ListPatternList> unique_list_pattern_lists;
UniqueStorage<TextLayout> unique_text_layouts;
HashMap<DeprecatedString, LocaleData> locales;
HashMap<ByteString, LocaleData> locales;
Vector<Alias> locale_aliases;
Vector<DeprecatedString> languages;
Vector<ByteString> languages;
HashMap<StringView, size_t> language_indices;
Vector<DeprecatedString> territories;
Vector<ByteString> territories;
HashMap<StringView, size_t> territory_indices;
Vector<DeprecatedString> scripts;
Vector<ByteString> scripts;
HashMap<StringView, size_t> script_indices;
Vector<DeprecatedString> variants;
Vector<ByteString> variants;
HashMap<StringView, size_t> variant_indices;
Vector<DeprecatedString> currencies;
Vector<ByteString> currencies;
HashMap<StringView, size_t> currency_indices;
Vector<DeprecatedString> date_fields;
Vector<ByteString> date_fields;
HashMap<StringView, size_t> date_fields_indices;
Vector<Alias> date_field_aliases {
@ -224,17 +224,17 @@ struct CLDR {
{ "zone"sv, "timeZoneName"sv },
};
HashMap<DeprecatedString, Vector<DeprecatedString>> keywords;
HashMap<DeprecatedString, Vector<Alias>> keyword_aliases;
HashMap<DeprecatedString, DeprecatedString> keyword_names;
HashMap<ByteString, Vector<ByteString>> keywords;
HashMap<ByteString, Vector<Alias>> keyword_aliases;
HashMap<ByteString, ByteString> keyword_names;
Vector<DeprecatedString> list_pattern_types;
Vector<DeprecatedString> character_orders;
HashMap<DeprecatedString, size_t> language_aliases;
HashMap<DeprecatedString, size_t> territory_aliases;
HashMap<DeprecatedString, size_t> script_aliases;
HashMap<DeprecatedString, size_t> variant_aliases;
HashMap<DeprecatedString, size_t> subdivision_aliases;
Vector<ByteString> list_pattern_types;
Vector<ByteString> character_orders;
HashMap<ByteString, size_t> language_aliases;
HashMap<ByteString, size_t> territory_aliases;
HashMap<ByteString, size_t> script_aliases;
HashMap<ByteString, size_t> variant_aliases;
HashMap<ByteString, size_t> subdivision_aliases;
Vector<LanguageMapping> complex_mappings;
Vector<LanguageMapping> likely_subtags;
size_t max_variant_size { 0 };
@ -253,9 +253,9 @@ struct CLDR {
})
// NOTE: We return a pointer only because ErrorOr cannot store references. You may safely assume the pointer is non-null.
ErrorOr<JsonValue const*> read_json_file_with_cache(DeprecatedString const& path)
ErrorOr<JsonValue const*> read_json_file_with_cache(ByteString const& path)
{
static HashMap<DeprecatedString, JsonValue> parsed_json_cache;
static HashMap<ByteString, JsonValue> parsed_json_cache;
if (auto parsed_json = parsed_json_cache.get(path); parsed_json.has_value())
return &parsed_json.value();
@ -273,7 +273,7 @@ static ErrorOr<LanguageMapping> parse_language_mapping(CLDR& cldr, StringView ke
return LanguageMapping { move(parsed_key), move(parsed_alias) };
}
static ErrorOr<void> parse_core_aliases(DeprecatedString core_supplemental_path, CLDR& cldr)
static ErrorOr<void> parse_core_aliases(ByteString core_supplemental_path, CLDR& cldr)
{
LexicalPath core_aliases_path(move(core_supplemental_path));
core_aliases_path = core_aliases_path.append("aliases.json"sv);
@ -285,7 +285,7 @@ static ErrorOr<void> parse_core_aliases(DeprecatedString core_supplemental_path,
auto append_aliases = [&](auto& alias_object, auto& alias_map) {
alias_object.for_each_member([&](auto const& key, JsonValue const& value) {
auto alias = value.as_object().get_deprecated_string("_replacement"sv).value();
auto alias = value.as_object().get_byte_string("_replacement"sv).value();
if (key.contains('-')) {
auto mapping = TRY_OR_DISCARD(parse_language_mapping(cldr, key, alias));
@ -307,7 +307,7 @@ static ErrorOr<void> parse_core_aliases(DeprecatedString core_supplemental_path,
return {};
}
static ErrorOr<void> parse_likely_subtags(DeprecatedString core_supplemental_path, CLDR& cldr)
static ErrorOr<void> parse_likely_subtags(ByteString core_supplemental_path, CLDR& cldr)
{
LexicalPath likely_subtags_path(move(core_supplemental_path));
likely_subtags_path = likely_subtags_path.append("likelySubtags.json"sv);
@ -326,7 +326,7 @@ static ErrorOr<void> parse_likely_subtags(DeprecatedString core_supplemental_pat
return {};
}
static ErrorOr<void> parse_identity(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_identity(ByteString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath locale_display_names_path(move(locale_path)); // Note: Every JSON file defines identity data, so we can use any of them.
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
@ -335,10 +335,10 @@ static ErrorOr<void> parse_identity(DeprecatedString locale_path, CLDR& cldr, Lo
auto const& main_object = locale_display_names.as_object().get_object("main"sv).value();
auto const& locale_object = main_object.get_object(locale_display_names_path.parent().basename()).value();
auto const& identity_object = locale_object.get_object("identity"sv).value();
auto const& language_string = identity_object.get_deprecated_string("language"sv).value();
auto const& territory_string = identity_object.get_deprecated_string("territory"sv);
auto const& script_string = identity_object.get_deprecated_string("script"sv);
auto const& variant_string = identity_object.get_deprecated_string("variant"sv);
auto const& language_string = identity_object.get_byte_string("language"sv).value();
auto const& territory_string = identity_object.get_byte_string("territory"sv);
auto const& script_string = identity_object.get_byte_string("script"sv);
auto const& variant_string = identity_object.get_byte_string("variant"sv);
locale.language = language_string;
@ -372,7 +372,7 @@ static ErrorOr<void> parse_identity(DeprecatedString locale_path, CLDR& cldr, Lo
return {};
}
static ErrorOr<void> parse_locale_display_patterns(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_display_patterns(ByteString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath locale_display_names_path(move(locale_path));
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
@ -382,8 +382,8 @@ static ErrorOr<void> parse_locale_display_patterns(DeprecatedString locale_path,
auto const& locale_object = main_object.get_object(locale_display_names_path.parent().basename()).value();
auto const& locale_display_names_object = locale_object.get_object("localeDisplayNames"sv).value();
auto const& locale_display_patterns_object = locale_display_names_object.get_object("localeDisplayPattern"sv).value();
auto const& locale_pattern = locale_display_patterns_object.get_deprecated_string("localePattern"sv).value();
auto const& locale_separator = locale_display_patterns_object.get_deprecated_string("localeSeparator"sv).value();
auto const& locale_pattern = locale_display_patterns_object.get_byte_string("localePattern"sv).value();
auto const& locale_separator = locale_display_patterns_object.get_byte_string("localeSeparator"sv).value();
DisplayPattern patterns {};
patterns.locale_pattern = cldr.unique_strings.ensure(locale_pattern);
@ -393,7 +393,7 @@ static ErrorOr<void> parse_locale_display_patterns(DeprecatedString locale_path,
return {};
}
static ErrorOr<void> preprocess_languages(DeprecatedString locale_path, CLDR& cldr)
static ErrorOr<void> preprocess_languages(ByteString locale_path, CLDR& cldr)
{
LexicalPath languages_path(move(locale_path));
languages_path = languages_path.append("languages.json"sv);
@ -417,7 +417,7 @@ static ErrorOr<void> preprocess_languages(DeprecatedString locale_path, CLDR& cl
return {};
}
static ErrorOr<void> preprocess_currencies(DeprecatedString numbers_path, CLDR& cldr)
static ErrorOr<void> preprocess_currencies(ByteString numbers_path, CLDR& cldr)
{
LexicalPath currencies_path(move(numbers_path));
currencies_path = currencies_path.append("currencies.json"sv);
@ -445,7 +445,7 @@ static bool is_sanctioned_date_field(StringView field)
return field.is_one_of("era"sv, "year"sv, "quarter"sv, "month"sv, "week"sv, "weekday"sv, "day"sv, "dayperiod"sv, "hour"sv, "minute"sv, "second"sv, "zone"sv);
}
static ErrorOr<void> preprocess_date_fields(DeprecatedString dates_path, CLDR& cldr)
static ErrorOr<void> preprocess_date_fields(ByteString dates_path, CLDR& cldr)
{
LexicalPath date_fields_path(move(dates_path));
date_fields_path = date_fields_path.append("dateFields.json"sv);
@ -469,7 +469,7 @@ static ErrorOr<void> preprocess_date_fields(DeprecatedString dates_path, CLDR& c
return {};
}
static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_path, CLDR& cldr)
static ErrorOr<void> parse_unicode_extension_keywords(ByteString bcp47_path, CLDR& cldr)
{
constexpr auto desired_keywords = Array { "ca"sv, "co"sv, "hc"sv, "kf"sv, "kn"sv, "nu"sv };
auto keywords = TRY(read_json_file(bcp47_path));
@ -483,7 +483,7 @@ static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_pat
if (!desired_keywords.span().contains_slow(key))
return;
auto const& name = value.as_object().get_deprecated_string("_alias"sv).value();
auto const& name = value.as_object().get_byte_string("_alias"sv).value();
cldr.keyword_names.set(key, name);
auto& keywords = cldr.keywords.ensure(key);
@ -505,12 +505,12 @@ static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_pat
if (key == "nu"sv && keyword.is_one_of("finance"sv, "native"sv, "traditio"sv))
return;
if (auto const& preferred = properties.as_object().get_deprecated_string("_preferred"sv); preferred.has_value()) {
if (auto const& preferred = properties.as_object().get_byte_string("_preferred"sv); preferred.has_value()) {
cldr.keyword_aliases.ensure(key).append({ preferred.value(), keyword });
return;
}
if (auto const& alias = properties.as_object().get_deprecated_string("_alias"sv); alias.has_value())
if (auto const& alias = properties.as_object().get_byte_string("_alias"sv); alias.has_value())
cldr.keyword_aliases.ensure(key).append({ keyword, alias.value() });
keywords.append(keyword);
@ -520,7 +520,7 @@ static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_pat
return {};
}
static Optional<DeprecatedString> find_keyword_alias(StringView key, StringView calendar, CLDR& cldr)
static Optional<ByteString> find_keyword_alias(StringView key, StringView calendar, CLDR& cldr)
{
auto it = cldr.keyword_aliases.find(key);
if (it == cldr.keyword_aliases.end())
@ -533,7 +533,7 @@ static Optional<DeprecatedString> find_keyword_alias(StringView key, StringView
return alias->name;
}
static ErrorOr<void> parse_locale_languages(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_languages(ByteString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath languages_path(move(locale_path));
languages_path = languages_path.append("languages.json"sv);
@ -567,7 +567,7 @@ static ErrorOr<void> parse_locale_languages(DeprecatedString locale_path, CLDR&
return {};
}
static ErrorOr<void> parse_locale_territories(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_territories(ByteString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath territories_path(move(locale_path));
territories_path = territories_path.append("territories.json"sv);
@ -598,7 +598,7 @@ static ErrorOr<void> parse_locale_territories(DeprecatedString locale_path, CLDR
return {};
}
static ErrorOr<void> parse_locale_scripts(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_scripts(ByteString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath scripts_path(move(locale_path));
scripts_path = scripts_path.append("scripts.json"sv);
@ -629,7 +629,7 @@ static ErrorOr<void> parse_locale_scripts(DeprecatedString locale_path, CLDR& cl
return {};
}
static ErrorOr<void> parse_locale_list_patterns(DeprecatedString misc_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_list_patterns(ByteString misc_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath list_patterns_path(move(misc_path));
list_patterns_path = list_patterns_path.append("listPatterns.json"sv);
@ -664,10 +664,10 @@ static ErrorOr<void> parse_locale_list_patterns(DeprecatedString misc_path, CLDR
auto type = list_pattern_type(key);
auto style = list_pattern_style(key);
auto start = cldr.unique_strings.ensure(value.as_object().get_deprecated_string("start"sv).value());
auto middle = cldr.unique_strings.ensure(value.as_object().get_deprecated_string("middle"sv).value());
auto end = cldr.unique_strings.ensure(value.as_object().get_deprecated_string("end"sv).value());
auto pair = cldr.unique_strings.ensure(value.as_object().get_deprecated_string("2"sv).value());
auto start = cldr.unique_strings.ensure(value.as_object().get_byte_string("start"sv).value());
auto middle = cldr.unique_strings.ensure(value.as_object().get_byte_string("middle"sv).value());
auto end = cldr.unique_strings.ensure(value.as_object().get_byte_string("end"sv).value());
auto pair = cldr.unique_strings.ensure(value.as_object().get_byte_string("2"sv).value());
if (!cldr.list_pattern_types.contains_slow(type))
cldr.list_pattern_types.append(type);
@ -680,7 +680,7 @@ static ErrorOr<void> parse_locale_list_patterns(DeprecatedString misc_path, CLDR
return {};
}
static ErrorOr<void> parse_locale_layout(DeprecatedString misc_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_layout(ByteString misc_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath layout_path(move(misc_path));
layout_path = layout_path.append("layout.json"sv);
@ -699,7 +699,7 @@ static ErrorOr<void> parse_locale_layout(DeprecatedString misc_path, CLDR& cldr,
VERIFY_NOT_REACHED();
};
auto character_order = orientation_object.get_deprecated_string("characterOrder"sv).value();
auto character_order = orientation_object.get_byte_string("characterOrder"sv).value();
TextLayout layout {};
layout.character_order = text_layout_character_order(character_order);
@ -711,7 +711,7 @@ static ErrorOr<void> parse_locale_layout(DeprecatedString misc_path, CLDR& cldr,
return {};
}
static ErrorOr<void> parse_locale_currencies(DeprecatedString numbers_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_currencies(ByteString numbers_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath currencies_path(move(numbers_path));
currencies_path = currencies_path.append("currencies.json"sv);
@ -735,10 +735,10 @@ static ErrorOr<void> parse_locale_currencies(DeprecatedString numbers_path, CLDR
numeric_currencies.resize(cldr.currencies.size());
currencies_object.for_each_member([&](auto const& key, JsonValue const& value) {
auto long_name = value.as_object().get_deprecated_string("displayName"sv).value_or(key);
auto short_name = value.as_object().get_deprecated_string("symbol"sv).value_or(key);
auto narrow_name = value.as_object().get_deprecated_string("symbol-alt-narrow"sv);
auto numeric_name = value.as_object().get_deprecated_string("displayName-count-other"sv);
auto long_name = value.as_object().get_byte_string("displayName"sv).value_or(key);
auto short_name = value.as_object().get_byte_string("symbol"sv).value_or(key);
auto narrow_name = value.as_object().get_byte_string("symbol-alt-narrow"sv);
auto numeric_name = value.as_object().get_byte_string("displayName-count-other"sv);
auto index = cldr.currency_indices.get(key).value();
long_currencies[index] = cldr.unique_strings.ensure(move(long_name));
@ -754,7 +754,7 @@ static ErrorOr<void> parse_locale_currencies(DeprecatedString numbers_path, CLDR
return {};
}
static ErrorOr<void> parse_locale_calendars(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_calendars(ByteString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath locale_display_names_path(move(locale_path));
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
@ -789,7 +789,7 @@ static ErrorOr<void> parse_locale_calendars(DeprecatedString locale_path, CLDR&
return {};
}
static ErrorOr<void> parse_locale_date_fields(DeprecatedString dates_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_date_fields(ByteString dates_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath date_fields_path(move(dates_path));
date_fields_path = date_fields_path.append("dateFields.json"sv);
@ -813,9 +813,9 @@ static ErrorOr<void> parse_locale_date_fields(DeprecatedString dates_path, CLDR&
if (!is_sanctioned_date_field(key))
return;
auto const& long_name = value.as_object().get_deprecated_string("displayName"sv).value();
auto const& short_name = fields_object.get_object(DeprecatedString::formatted("{}-short", key))->get_deprecated_string("displayName"sv).value();
auto const& narrow_name = fields_object.get_object(DeprecatedString::formatted("{}-narrow", key))->get_deprecated_string("displayName"sv).value();
auto const& long_name = value.as_object().get_byte_string("displayName"sv).value();
auto const& short_name = fields_object.get_object(ByteString::formatted("{}-short", key))->get_byte_string("displayName"sv).value();
auto const& narrow_name = fields_object.get_object(ByteString::formatted("{}-narrow", key))->get_byte_string("displayName"sv).value();
auto index = cldr.date_fields_indices.get(key).value();
long_date_fields[index] = cldr.unique_strings.ensure(long_name);
@ -829,7 +829,7 @@ static ErrorOr<void> parse_locale_date_fields(DeprecatedString dates_path, CLDR&
return {};
}
static ErrorOr<void> parse_number_system_keywords(DeprecatedString locale_numbers_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_number_system_keywords(ByteString locale_numbers_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath numbers_path(move(locale_numbers_path));
numbers_path = numbers_path.append("numbers.json"sv);
@ -838,12 +838,12 @@ static ErrorOr<void> parse_number_system_keywords(DeprecatedString locale_number
auto const& main_object = numbers.as_object().get_object("main"sv).value();
auto const& locale_object = main_object.get_object(numbers_path.parent().basename()).value();
auto const& locale_numbers_object = locale_object.get_object("numbers"sv).value();
auto const& default_numbering_system_object = locale_numbers_object.get_deprecated_string("defaultNumberingSystem"sv).value();
auto const& default_numbering_system_object = locale_numbers_object.get_byte_string("defaultNumberingSystem"sv).value();
auto const& other_numbering_systems_object = locale_numbers_object.get_object("otherNumberingSystems"sv).value();
KeywordList keywords {};
auto append_numbering_system = [&](DeprecatedString system_name) {
auto append_numbering_system = [&](ByteString system_name) {
if (auto system_alias = find_keyword_alias("nu"sv, system_name, cldr); system_alias.has_value())
system_name = system_alias.release_value();
@ -868,7 +868,7 @@ static ErrorOr<void> parse_number_system_keywords(DeprecatedString locale_number
return {};
}
static ErrorOr<void> parse_calendar_keywords(DeprecatedString locale_dates_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_calendar_keywords(ByteString locale_dates_path, CLDR& cldr, LocaleData& locale)
{
KeywordList keywords {};
@ -934,7 +934,7 @@ static void fill_in_collation_keywords(CLDR& cldr, LocaleData& locale)
locale.collation_numeric_keywords = kn_index;
}
static ErrorOr<void> parse_default_content_locales(DeprecatedString core_path, CLDR& cldr)
static ErrorOr<void> parse_default_content_locales(ByteString core_path, CLDR& cldr)
{
LexicalPath default_content_path(move(core_path));
default_content_path = default_content_path.append("defaultContent.json"sv);
@ -983,7 +983,7 @@ static ErrorOr<void> define_aliases_without_scripts(CLDR& cldr)
if ((parsed_locale.language == 0) || (parsed_locale.script == 0) || (parsed_locale.region == 0))
return {};
auto locale_without_script = DeprecatedString::formatted("{}-{}",
auto locale_without_script = ByteString::formatted("{}-{}",
cldr.unique_strings.get(parsed_locale.language),
cldr.unique_strings.get(parsed_locale.region));
@ -1008,7 +1008,7 @@ static ErrorOr<void> define_aliases_without_scripts(CLDR& cldr)
return {};
}
static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedString core_path, DeprecatedString locale_names_path, DeprecatedString misc_path, DeprecatedString numbers_path, DeprecatedString dates_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(ByteString bcp47_path, ByteString core_path, ByteString locale_names_path, ByteString misc_path, ByteString numbers_path, ByteString dates_path, CLDR& cldr)
{
LexicalPath core_supplemental_path(core_path);
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
@ -1017,7 +1017,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedSt
TRY(parse_core_aliases(core_supplemental_path.string(), cldr));
TRY(parse_likely_subtags(core_supplemental_path.string(), cldr));
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -1027,7 +1027,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedSt
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
builder.appendff("-{}", region);
return builder.to_deprecated_string();
return builder.to_byte_string();
};
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
@ -1156,7 +1156,7 @@ namespace Locale {
for (auto& keyword : cldr.keywords) {
auto const& keyword_name = cldr.keyword_names.find(keyword.key)->value;
auto enum_name = DeprecatedString::formatted("Keyword{}", format_identifier({}, keyword_name));
auto enum_name = ByteString::formatted("Keyword{}", format_identifier({}, keyword_name));
if (auto aliases = cldr.keyword_aliases.find(keyword.key); aliases != cldr.keyword_aliases.end())
generate_enum(generator, format_identifier, enum_name, {}, keyword.value, aliases->value);
@ -1179,9 +1179,9 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::InputBufferedF
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("string_index_type"sv, string_index_type);
generator.set("locales_size"sv, DeprecatedString::number(cldr.locales.size()));
generator.set("territories_size", DeprecatedString::number(cldr.territories.size()));
generator.set("variants_size", DeprecatedString::number(cldr.max_variant_size));
generator.set("locales_size"sv, ByteString::number(cldr.locales.size()));
generator.set("territories_size", ByteString::number(cldr.territories.size()));
generator.set("variants_size", ByteString::number(cldr.max_variant_size));
generator.append(R"~~~(
#include <AK/Array.h>
@ -1285,7 +1285,7 @@ ReadonlySpan<StringView> get_available_keyword_values(StringView key)
cldr.unique_text_layouts.generate(generator, "TextLayout"sv, "s_text_layouts"sv, 30);
auto append_index = [&](auto index) {
generator.append(DeprecatedString::formatted(", {}", index));
generator.append(ByteString::formatted(", {}", index));
};
auto append_list_and_size = [&](auto const& list) {
@ -1298,16 +1298,16 @@ ReadonlySpan<StringView> get_available_keyword_values(StringView key)
generator.append(", {");
for (auto const& item : list) {
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::number(item));
generator.append(ByteString::number(item));
first = false;
}
generator.append(DeprecatedString::formatted(" }}, {}", list.size()));
generator.append(ByteString::formatted(" }}, {}", list.size()));
};
auto append_mapping = [&](auto const& keys, auto const& map, auto type, auto name, auto mapping_getter) {
generator.set("type", type);
generator.set("name", name);
generator.set("size", DeprecatedString::number(keys.size()));
generator.set("size", ByteString::number(keys.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {)~~~");
@ -1318,7 +1318,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
auto mapping = mapping_getter(value);
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::number(mapping));
generator.append(ByteString::number(mapping));
first = false;
}
@ -1396,7 +1396,7 @@ struct LanguageMapping {
)~~~");
auto append_complex_mapping = [&](StringView name, auto& mappings) {
generator.set("size", DeprecatedString::number(mappings.size()));
generator.set("size", ByteString::number(mappings.size()));
generator.set("name"sv, name);
generator.append(R"~~~(
@ -1416,14 +1416,14 @@ static constexpr Array<LanguageMapping, @size@> s_@name@ { {
});
for (auto const& mapping : mappings) {
generator.set("language"sv, DeprecatedString::number(mapping.key.language));
generator.set("language"sv, ByteString::number(mapping.key.language));
generator.append(" { { @language@");
append_index(mapping.key.script);
append_index(mapping.key.region);
append_list_and_size(mapping.key.variants);
generator.set("language"sv, DeprecatedString::number(mapping.alias.language));
generator.set("language"sv, ByteString::number(mapping.alias.language));
generator.append(" }, { @language@");
append_index(mapping.alias.script);
@ -1563,7 +1563,7 @@ Optional<StringView> get_locale_@enum_snake@_mapping(StringView locale, StringVi
};
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) -> ErrorOr<void> {
HashValueMap<DeprecatedString> hashes;
HashValueMap<ByteString> hashes;
TRY(hashes.try_ensure_capacity(values.size()));
for (auto const& value : values)
@ -1621,8 +1621,8 @@ Optional<StringView> get_locale_@enum_snake@_mapping(StringView locale, StringVi
for (auto const& keyword : cldr.keywords) {
auto const& keyword_name = cldr.keyword_names.find(keyword.key)->value;
auto enum_name = DeprecatedString::formatted("Keyword{}", format_identifier({}, keyword_name));
auto enum_snake = DeprecatedString::formatted("keyword_{}", keyword.key);
auto enum_name = ByteString::formatted("Keyword{}", format_identifier({}, keyword_name));
auto enum_snake = ByteString::formatted("keyword_{}", keyword.key);
if (auto aliases = cldr.keyword_aliases.find(keyword.key); aliases != cldr.keyword_aliases.end())
TRY(append_from_string(enum_name, enum_snake, keyword.value, aliases->value));

View file

@ -7,8 +7,8 @@
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/AllOf.h>
#include <AK/Array.h>
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Find.h>
#include <AK/Format.h>
#include <AK/HashFunctions.h>
@ -85,7 +85,7 @@ struct AK::Formatter<NumberFormat> : Formatter<FormatString> {
format.zero_format_index,
format.positive_format_index,
format.negative_format_index,
identifier_indices.to_deprecated_string());
identifier_indices.to_byte_string());
}
};
@ -215,7 +215,7 @@ struct AK::Traits<Unit> : public DefaultTraits<Unit> {
struct LocaleData {
Vector<size_t> number_systems;
HashMap<DeprecatedString, size_t> units {};
HashMap<ByteString, size_t> units {};
u8 minimum_grouping_digits { 0 };
};
@ -227,14 +227,14 @@ struct CLDR {
UniqueStorage<NumberSystem> unique_systems;
UniqueStorage<Unit> unique_units;
HashMap<DeprecatedString, Array<u32, 10>> number_system_digits;
Vector<DeprecatedString> number_systems;
HashMap<ByteString, Array<u32, 10>> number_system_digits;
Vector<ByteString> number_systems;
HashMap<DeprecatedString, LocaleData> locales;
HashMap<ByteString, LocaleData> locales;
size_t max_identifier_count { 0 };
};
static ErrorOr<void> parse_number_system_digits(DeprecatedString core_supplemental_path, CLDR& cldr)
static ErrorOr<void> parse_number_system_digits(ByteString core_supplemental_path, CLDR& cldr)
{
LexicalPath number_systems_path(move(core_supplemental_path));
number_systems_path = number_systems_path.append("numberingSystems.json"sv);
@ -244,11 +244,11 @@ static ErrorOr<void> parse_number_system_digits(DeprecatedString core_supplement
auto const& number_systems_object = supplemental_object.get_object("numberingSystems"sv).value();
number_systems_object.for_each_member([&](auto const& number_system, auto const& digits_object) {
auto type = digits_object.as_object().get_deprecated_string("_type"sv).value();
auto type = digits_object.as_object().get_byte_string("_type"sv).value();
if (type != "numeric"sv)
return;
auto digits = digits_object.as_object().get_deprecated_string("_digits"sv).value();
auto digits = digits_object.as_object().get_byte_string("_digits"sv).value();
Utf8View utf8_digits { digits };
VERIFY(utf8_digits.length() == 10);
@ -266,7 +266,7 @@ static ErrorOr<void> parse_number_system_digits(DeprecatedString core_supplement
return {};
}
static DeprecatedString parse_identifiers(DeprecatedString pattern, StringView replacement, CLDR& cldr, NumberFormat& format)
static ByteString parse_identifiers(ByteString pattern, StringView replacement, CLDR& cldr, NumberFormat& format)
{
static constexpr Utf8View whitespace { "\u0020\u00a0\u200f"sv };
@ -312,7 +312,7 @@ static DeprecatedString parse_identifiers(DeprecatedString pattern, StringView r
cldr.max_identifier_count = max(cldr.max_identifier_count, format.identifier_indices.size());
}
pattern = DeprecatedString::formatted("{}{{{}:{}}}{}",
pattern = ByteString::formatted("{}{{{}:{}}}{}",
*start_index > 0 ? pattern.substring_view(0, *start_index) : ""sv,
replacement,
replacement_index,
@ -320,13 +320,13 @@ static DeprecatedString parse_identifiers(DeprecatedString pattern, StringView r
}
}
static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
static void parse_number_pattern(Vector<ByteString> patterns, CLDR& cldr, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
{
// https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
// https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
VERIFY((patterns.size() == 1) || (patterns.size() == 2));
auto replace_patterns = [&](DeprecatedString pattern) {
auto replace_patterns = [&](ByteString pattern) {
static HashMap<StringView, StringView> replacements = {
{ "{0}"sv, "{number}"sv },
{ "{1}"sv, "{currency}"sv },
@ -340,7 +340,7 @@ static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr,
for (auto const& replacement : replacements)
pattern = pattern.replace(replacement.key, replacement.value, ReplaceMode::All);
if (auto start_number_index = pattern.find_any_of("#0"sv, DeprecatedString::SearchDirection::Forward); start_number_index.has_value()) {
if (auto start_number_index = pattern.find_any_of("#0"sv, ByteString::SearchDirection::Forward); start_number_index.has_value()) {
auto end_number_index = *start_number_index + 1;
for (; end_number_index < pattern.length(); ++end_number_index) {
@ -367,7 +367,7 @@ static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr,
}
}
pattern = DeprecatedString::formatted("{}{{number}}{}",
pattern = ByteString::formatted("{}{{number}}{}",
*start_number_index > 0 ? pattern.substring_view(0, *start_number_index) : ""sv,
pattern.substring_view(end_number_index));
@ -384,19 +384,19 @@ static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr,
};
auto zero_format = replace_patterns(move(patterns[0]));
format.positive_format_index = cldr.unique_strings.ensure(DeprecatedString::formatted("{{plusSign}}{}", zero_format));
format.positive_format_index = cldr.unique_strings.ensure(ByteString::formatted("{{plusSign}}{}", zero_format));
if (patterns.size() == 2) {
auto negative_format = replace_patterns(move(patterns[1]));
format.negative_format_index = cldr.unique_strings.ensure(move(negative_format));
} else {
format.negative_format_index = cldr.unique_strings.ensure(DeprecatedString::formatted("{{minusSign}}{}", zero_format));
format.negative_format_index = cldr.unique_strings.ensure(ByteString::formatted("{{minusSign}}{}", zero_format));
}
format.zero_format_index = cldr.unique_strings.ensure(move(zero_format));
}
static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr, NumberFormatType type, size_t& format_index, NumberSystem* number_system_for_groupings = nullptr)
static void parse_number_pattern(Vector<ByteString> patterns, CLDR& cldr, NumberFormatType type, size_t& format_index, NumberSystem* number_system_for_groupings = nullptr)
{
NumberFormat format {};
parse_number_pattern(move(patterns), cldr, type, format, number_system_for_groupings);
@ -404,7 +404,7 @@ static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr,
format_index = cldr.unique_formats.ensure(move(format));
}
static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_number_systems(ByteString locale_numbers_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath numbers_path(move(locale_numbers_path));
numbers_path = numbers_path.append("numbers.json"sv);
@ -413,7 +413,7 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
auto const& main_object = numbers.as_object().get_object("main"sv).value();
auto const& locale_object = main_object.get_object(numbers_path.parent().basename()).value();
auto const& locale_numbers_object = locale_object.get_object("numbers"sv).value();
auto const& minimum_grouping_digits = locale_numbers_object.get_deprecated_string("minimumGroupingDigits"sv).value();
auto const& minimum_grouping_digits = locale_numbers_object.get_byte_string("minimumGroupingDigits"sv).value();
Vector<Optional<NumberSystem>> number_systems;
number_systems.resize(cldr.number_systems.size());
@ -517,9 +517,9 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
// The range separator does not appear in the symbols list, we have to extract it from
// the range pattern.
auto misc_patterns_key = DeprecatedString::formatted("{}{}", misc_patterns_prefix, system);
auto misc_patterns_key = ByteString::formatted("{}{}", misc_patterns_prefix, system);
auto misc_patterns = locale_numbers_object.get_object(misc_patterns_key).value();
auto range_separator = misc_patterns.get_deprecated_string("range"sv).value();
auto range_separator = misc_patterns.get_byte_string("range"sv).value();
auto begin_index = range_separator.find("{0}"sv).value() + "{0}"sv.length();
auto end_index = range_separator.find("{1}"sv).value();
@ -536,7 +536,7 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
auto system = key.substring(decimal_formats_prefix.length());
auto& number_system = ensure_number_system(system);
auto format_object = value.as_object().get_deprecated_string("standard"sv).value();
auto format_object = value.as_object().get_byte_string("standard"sv).value();
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.decimal_format, &number_system);
auto const& long_format = value.as_object().get_object("long"sv)->get_object("decimalFormat"sv).value();
@ -548,10 +548,10 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
auto system = key.substring(currency_formats_prefix.length());
auto& number_system = ensure_number_system(system);
auto format_object = value.as_object().get_deprecated_string("standard"sv).value();
auto format_object = value.as_object().get_byte_string("standard"sv).value();
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.currency_format);
format_object = value.as_object().get_deprecated_string("accounting"sv).value();
format_object = value.as_object().get_byte_string("accounting"sv).value();
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.accounting_format);
number_system.currency_unit_formats = parse_number_format(value.as_object());
@ -559,13 +559,13 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
auto system = key.substring(percent_formats_prefix.length());
auto& number_system = ensure_number_system(system);
auto format_object = value.as_object().get_deprecated_string("standard"sv).value();
auto format_object = value.as_object().get_byte_string("standard"sv).value();
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.percent_format);
} else if (key.starts_with(scientific_formats_prefix)) {
auto system = key.substring(scientific_formats_prefix.length());
auto& number_system = ensure_number_system(system);
auto format_object = value.as_object().get_deprecated_string("standard"sv).value();
auto format_object = value.as_object().get_byte_string("standard"sv).value();
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.scientific_format);
}
});
@ -584,7 +584,7 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
return {};
}
static ErrorOr<void> parse_units(DeprecatedString locale_units_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_units(ByteString locale_units_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath units_path(move(locale_units_path));
units_path = units_path.append("units.json"sv);
@ -597,7 +597,7 @@ static ErrorOr<void> parse_units(DeprecatedString locale_units_path, CLDR& cldr,
auto const& short_object = locale_units_object.get_object("short"sv).value();
auto const& narrow_object = locale_units_object.get_object("narrow"sv).value();
HashMap<DeprecatedString, Unit> units;
HashMap<ByteString, Unit> units;
auto ensure_unit = [&](auto const& unit) -> Unit& {
return units.ensure(unit, [&]() {
@ -687,7 +687,7 @@ static ErrorOr<void> parse_units(DeprecatedString locale_units_path, CLDR& cldr,
return {};
}
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString numbers_path, DeprecatedString units_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(ByteString core_path, ByteString numbers_path, ByteString units_path, CLDR& cldr)
{
LexicalPath core_supplemental_path(move(core_path));
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
@ -695,7 +695,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
TRY(parse_number_system_digits(core_supplemental_path.string(), cldr));
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -705,7 +705,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
builder.appendff("-{}", region);
return builder.to_deprecated_string();
return builder.to_byte_string();
};
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", numbers_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
@ -729,7 +729,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
return {};
}
static DeprecatedString format_identifier(StringView, DeprecatedString identifier)
static ByteString format_identifier(StringView, ByteString identifier)
{
return identifier.to_titlecase();
}
@ -765,7 +765,7 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::InputBufferedF
generator.set("number_format_index_type"sv, cldr.unique_formats.type_that_fits());
generator.set("number_format_list_index_type"sv, cldr.unique_format_lists.type_that_fits());
generator.set("numeric_symbol_list_index_type"sv, cldr.unique_symbols.type_that_fits());
generator.set("identifier_count", DeprecatedString::number(cldr.max_identifier_count));
generator.set("identifier_count", ByteString::number(cldr.max_identifier_count));
generator.append(R"~~~(
#include <AK/Array.h>
@ -848,22 +848,22 @@ struct Unit {
auto locales = cldr.locales.keys();
quick_sort(locales);
generator.set("size", DeprecatedString::number(locales.size()));
generator.set("size", ByteString::number(locales.size()));
generator.append(R"~~~(
static constexpr Array<u8, @size@> s_minimum_grouping_digits { { )~~~");
bool first = true;
for (auto const& locale : locales) {
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::number(cldr.locales.find(locale)->value.minimum_grouping_digits));
generator.append(ByteString::number(cldr.locales.find(locale)->value.minimum_grouping_digits));
first = false;
}
generator.append(" } };\n");
auto append_map = [&](DeprecatedString name, auto type, auto const& map) {
auto append_map = [&](ByteString name, auto type, auto const& map) {
generator.set("name", name);
generator.set("type", type);
generator.set("size", DeprecatedString::number(map.size()));
generator.set("size", ByteString::number(map.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {)~~~");
@ -872,9 +872,9 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
for (auto const& item : map) {
generator.append(first ? " "sv : ", "sv);
if constexpr (requires { item.value; })
generator.append(DeprecatedString::number(item.value));
generator.append(ByteString::number(item.value));
else
generator.append(DeprecatedString::number(item));
generator.append(ByteString::number(item));
first = false;
}

View file

@ -5,7 +5,7 @@
*/
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
#include <AK/JsonValue.h>
@ -18,14 +18,14 @@
#include <LibFileSystem/FileSystem.h>
#include <LibLocale/PluralRules.h>
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
static ByteString format_identifier(StringView owner, ByteString identifier)
{
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
if (all_of(identifier, is_ascii_digit))
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
return ByteString::formatted("{}_{}", owner[0], identifier);
if (is_ascii_lower_alpha(identifier[0]))
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return ByteString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return identifier;
}
@ -38,20 +38,20 @@ struct Relation {
Inequality,
};
DeprecatedString const& modulus_variable_name() const
ByteString const& modulus_variable_name() const
{
VERIFY(modulus.has_value());
if (!cached_modulus_variable_name.has_value())
cached_modulus_variable_name = DeprecatedString::formatted("mod_{}_{}", symbol, *modulus);
cached_modulus_variable_name = ByteString::formatted("mod_{}_{}", symbol, *modulus);
return *cached_modulus_variable_name;
}
DeprecatedString const& exponential_variable_name() const
ByteString const& exponential_variable_name() const
{
if (!cached_exponential_variable_name.has_value())
cached_exponential_variable_name = DeprecatedString::formatted("exp_{}", symbol);
cached_exponential_variable_name = ByteString::formatted("exp_{}", symbol);
return *cached_exponential_variable_name;
}
@ -64,25 +64,25 @@ struct Relation {
else if (symbol == 'e' || symbol == 'c')
generator.append(exponential_variable_name());
else
generator.append(DeprecatedString::formatted("ops.{}", Locale::PluralOperands::symbol_to_variable_name(symbol)));
generator.append(ByteString::formatted("ops.{}", Locale::PluralOperands::symbol_to_variable_name(symbol)));
};
auto append_value = [&](u32 value) {
append_variable_name();
generator.append(" == "sv);
generator.append(DeprecatedString::number(value));
generator.append(ByteString::number(value));
};
auto append_range = [&](auto const& range) {
// This check avoids generating "0 <= unsigned_value", which is always true.
if (range[0] != 0 || Locale::PluralOperands::symbol_requires_floating_point_modulus(symbol)) {
generator.append(DeprecatedString::formatted("{} <= ", range[0]));
generator.append(ByteString::formatted("{} <= ", range[0]));
append_variable_name();
generator.append(" && "sv);
}
append_variable_name();
generator.append(DeprecatedString::formatted(" <= {}", range[1]));
generator.append(ByteString::formatted(" <= {}", range[1]));
};
if (type == Type::Inequality)
@ -105,7 +105,7 @@ struct Relation {
generator.append(")"sv);
}
void generate_precomputed_variables(SourceGenerator& generator, HashTable<DeprecatedString>& generated_variables) const
void generate_precomputed_variables(SourceGenerator& generator, HashTable<ByteString>& generated_variables) const
{
// FIXME: How do we handle the exponential symbols? They seem unused by ECMA-402.
if (symbol == 'e' || symbol == 'c') {
@ -127,7 +127,7 @@ struct Relation {
generated_variables.set(variable);
generator.set("variable"sv, move(variable));
generator.set("operand"sv, Locale::PluralOperands::symbol_to_variable_name(symbol));
generator.set("modulus"sv, DeprecatedString::number(*modulus));
generator.set("modulus"sv, ByteString::number(*modulus));
if (Locale::PluralOperands::symbol_requires_floating_point_modulus(symbol)) {
generator.append(R"~~~(
@ -144,8 +144,8 @@ struct Relation {
Vector<Comparator> comparators;
private:
mutable Optional<DeprecatedString> cached_modulus_variable_name;
mutable Optional<DeprecatedString> cached_exponential_variable_name;
mutable Optional<ByteString> cached_modulus_variable_name;
mutable Optional<ByteString> cached_exponential_variable_name;
};
struct Condition {
@ -170,7 +170,7 @@ struct Condition {
}
}
void generate_precomputed_variables(SourceGenerator& generator, HashTable<DeprecatedString>& generated_variables) const
void generate_precomputed_variables(SourceGenerator& generator, HashTable<ByteString>& generated_variables) const
{
for (auto const& conjunctions : relations) {
for (auto const& relation : conjunctions)
@ -182,18 +182,18 @@ struct Condition {
};
struct Range {
DeprecatedString start;
DeprecatedString end;
DeprecatedString category;
ByteString start;
ByteString end;
ByteString category;
};
using Conditions = HashMap<DeprecatedString, Condition>;
using Conditions = HashMap<ByteString, Condition>;
using Ranges = Vector<Range>;
struct LocaleData {
static DeprecatedString generated_method_name(StringView form, StringView locale)
static ByteString generated_method_name(StringView form, StringView locale)
{
return DeprecatedString::formatted("{}_plurality_{}", form, format_identifier({}, locale));
return ByteString::formatted("{}_plurality_{}", form, format_identifier({}, locale));
}
Conditions& rules_for_form(StringView form)
@ -213,7 +213,7 @@ struct LocaleData {
struct CLDR {
UniqueStringStorage unique_strings;
HashMap<DeprecatedString, LocaleData> locales;
HashMap<ByteString, LocaleData> locales;
};
static Relation parse_relation(StringView relation)
@ -321,7 +321,7 @@ static void parse_condition(StringView category, StringView rule, Conditions& ru
});
}
static ErrorOr<void> parse_plural_rules(DeprecatedString core_supplemental_path, StringView file_name, CLDR& cldr)
static ErrorOr<void> parse_plural_rules(ByteString core_supplemental_path, StringView file_name, CLDR& cldr)
{
static constexpr auto form_prefix = "plurals-type-"sv;
static constexpr auto rule_prefix = "pluralRule-count-"sv;
@ -356,7 +356,7 @@ static ErrorOr<void> parse_plural_rules(DeprecatedString core_supplemental_path,
}
// https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Ranges
static ErrorOr<void> parse_plural_ranges(DeprecatedString core_supplemental_path, CLDR& cldr)
static ErrorOr<void> parse_plural_ranges(ByteString core_supplemental_path, CLDR& cldr)
{
static constexpr auto start_segment = "-start-"sv;
static constexpr auto end_segment = "-end-"sv;
@ -392,13 +392,13 @@ static ErrorOr<void> parse_plural_ranges(DeprecatedString core_supplemental_path
return {};
}
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString locale_names_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(ByteString core_path, ByteString locale_names_path, CLDR& cldr)
{
LexicalPath core_supplemental_path(move(core_path));
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
VERIFY(FileSystem::is_directory(core_supplemental_path.string()));
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -408,7 +408,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
builder.appendff("-{}", region);
return builder.to_deprecated_string();
return builder.to_byte_string();
};
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
@ -484,7 +484,7 @@ static PluralCategory default_range(PluralCategory, PluralCategory end)
return;
generator.set("method"sv, LocaleData::generated_method_name(form, locale));
HashTable<DeprecatedString> generated_variables;
HashTable<ByteString> generated_variables;
generator.append(R"~~~(
static PluralCategory @method@([[maybe_unused]] PluralOperands ops)
@ -539,7 +539,7 @@ static PluralCategory @method@(PluralCategory start, PluralCategory end)
generator.set("type"sv, type);
generator.set("form"sv, form);
generator.set("default"sv, default_);
generator.set("size"sv, DeprecatedString::number(locales.size()));
generator.set("size"sv, ByteString::number(locales.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> s_@form@_functions { {)~~~");
@ -564,7 +564,7 @@ static constexpr Array<@type@, @size@> s_@form@_functions { {)~~~");
auto append_categories = [&](auto const& name, auto const& rules) {
generator.set("name", name);
generator.set("size", DeprecatedString::number(rules.size() + 1));
generator.set("size", ByteString::number(rules.size() + 1));
generator.append(R"~~~(
static constexpr Array<PluralCategory, @size@> @name@ { { PluralCategory::Other)~~~");

View file

@ -5,7 +5,7 @@
*/
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Format.h>
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
@ -39,9 +39,9 @@ struct RelativeTimeFormat {
&& (pattern == other.pattern);
}
DeprecatedString time_unit;
DeprecatedString style;
DeprecatedString plurality;
ByteString time_unit;
ByteString style;
ByteString plurality;
size_t tense_or_number { 0 };
size_t pattern { 0 };
};
@ -73,10 +73,10 @@ struct CLDR {
UniqueStringStorage unique_strings;
UniqueStorage<RelativeTimeFormat> unique_formats;
HashMap<DeprecatedString, LocaleData> locales;
HashMap<ByteString, LocaleData> locales;
};
static ErrorOr<void> parse_date_fields(DeprecatedString locale_dates_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_date_fields(ByteString locale_dates_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath date_fields_path(move(locale_dates_path));
date_fields_path = date_fields_path.append("dateFields.json"sv);
@ -135,9 +135,9 @@ static ErrorOr<void> parse_date_fields(DeprecatedString locale_dates_path, CLDR&
return {};
}
static ErrorOr<void> parse_all_locales(DeprecatedString dates_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(ByteString dates_path, CLDR& cldr)
{
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -147,7 +147,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString dates_path, CLDR& cldr)
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
builder.appendff("-{}", region);
return builder.to_deprecated_string();
return builder.to_byte_string();
};
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
@ -225,9 +225,9 @@ struct RelativeTimeFormatImpl {
cldr.unique_formats.generate(generator, "RelativeTimeFormatImpl"sv, "s_relative_time_formats"sv, 10);
auto append_list = [&](DeprecatedString name, auto const& list) {
auto append_list = [&](ByteString name, auto const& list) {
generator.set("name", name);
generator.set("size", DeprecatedString::number(list.size()));
generator.set("size", ByteString::number(list.size()));
generator.append(R"~~~(
static constexpr Array<@relative_time_format_index_type@, @size@> @name@ { {)~~~");
@ -235,7 +235,7 @@ static constexpr Array<@relative_time_format_index_type@, @size@> @name@ { {)~~~
bool first = true;
for (auto index : list) {
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::number(index));
generator.append(ByteString::number(index));
first = false;
}

View file

@ -5,8 +5,8 @@
*/
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/ByteString.h>
#include <AK/DateConstants.h>
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/Format.h>
#include <AK/HashMap.h>
@ -36,7 +36,7 @@ struct TimeZoneOffset {
i64 offset { 0 };
Optional<DateTime> until;
Optional<DeprecatedString> dst_rule;
Optional<ByteString> dst_rule;
Optional<i32> dst_rule_index;
i64 dst_offset { 0 };
@ -56,17 +56,17 @@ struct DaylightSavingsOffset {
struct TimeZoneData {
UniqueStringStorage unique_strings;
HashMap<DeprecatedString, Vector<TimeZoneOffset>> time_zones;
Vector<DeprecatedString> time_zone_names;
HashMap<ByteString, Vector<TimeZoneOffset>> time_zones;
Vector<ByteString> time_zone_names;
Vector<Alias> time_zone_aliases;
HashMap<DeprecatedString, Vector<DaylightSavingsOffset>> dst_offsets;
Vector<DeprecatedString> dst_offset_names;
HashMap<ByteString, Vector<DaylightSavingsOffset>> dst_offsets;
Vector<ByteString> dst_offset_names;
HashMap<DeprecatedString, TimeZone::Location> time_zone_coordinates;
HashMap<ByteString, TimeZone::Location> time_zone_coordinates;
HashMap<DeprecatedString, Vector<size_t>> time_zone_regions;
Vector<DeprecatedString> time_zone_region_names;
HashMap<ByteString, Vector<size_t>> time_zone_regions;
Vector<ByteString> time_zone_region_names;
Vector<TimeZone::TimeZoneIdentifier> time_zones_and_links;
};
@ -112,10 +112,10 @@ struct AK::Formatter<DaylightSavingsOffset> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, DaylightSavingsOffset const& dst_offset)
{
auto format_time = [&](auto year) {
return DeprecatedString::formatted("AK::UnixDateTime::from_unix_time_parts({}, 1, 1, 0, 0, 0, 0)", year);
return ByteString::formatted("AK::UnixDateTime::from_unix_time_parts({}, 1, 1, 0, 0, 0, 0)", year);
};
static DeprecatedString max_year_as_time("max_year_as_time"sv);
static ByteString max_year_as_time("max_year_as_time"sv);
return Formatter<FormatString>::format(builder,
"{{ {}, {}, {}, {}, {} }}"sv,
@ -439,7 +439,7 @@ static void set_dst_rule_indices(TimeZoneData& time_zone_data)
}
}
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
static ByteString format_identifier(StringView owner, ByteString identifier)
{
constexpr auto gmt_time_zones = Array { "Etc/GMT"sv, "GMT"sv };
@ -448,9 +448,9 @@ static DeprecatedString format_identifier(StringView owner, DeprecatedString ide
auto offset = identifier.substring_view(gmt_time_zone.length());
if (offset.starts_with('+'))
identifier = DeprecatedString::formatted("{}_Ahead_{}", gmt_time_zone, offset.substring_view(1));
identifier = ByteString::formatted("{}_Ahead_{}", gmt_time_zone, offset.substring_view(1));
else if (offset.starts_with('-'))
identifier = DeprecatedString::formatted("{}_Behind_{}", gmt_time_zone, offset.substring_view(1));
identifier = ByteString::formatted("{}_Behind_{}", gmt_time_zone, offset.substring_view(1));
}
}
@ -458,9 +458,9 @@ static DeprecatedString format_identifier(StringView owner, DeprecatedString ide
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
if (all_of(identifier, is_ascii_digit))
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
return ByteString::formatted("{}_{}", owner[0], identifier);
if (is_ascii_lower_alpha(identifier[0]))
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return ByteString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return identifier;
}
@ -568,14 +568,14 @@ struct DaylightSavingsOffset {
auto append_offsets = [&](auto const& name, auto type, auto const& offsets) {
generator.set("name", name);
generator.set("type", type);
generator.set("size", DeprecatedString::number(offsets.size()));
generator.set("size", ByteString::number(offsets.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {
)~~~");
for (auto const& offset : offsets)
generator.append(DeprecatedString::formatted(" {},\n", offset));
generator.append(ByteString::formatted(" {},\n", offset));
generator.append("} };\n");
};
@ -597,7 +597,7 @@ static constexpr Array<@type@, @size@> @name@ { {
auto const& time_zones = time_zone_data.time_zone_regions.find(value)->value;
generator.set("name", name);
generator.set("size", DeprecatedString::number(time_zones.size()));
generator.set("size", ByteString::number(time_zones.size()));
generator.append(R"~~~(
static constexpr Array<@string_index_type@, @size@> @name@ { {)~~~");
@ -605,14 +605,14 @@ static constexpr Array<@string_index_type@, @size@> @name@ { {)~~~");
bool first = true;
for (auto const& time_zone : time_zones) {
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::number(time_zone));
generator.append(ByteString::number(time_zone));
first = false;
}
generator.append(" } };");
});
generator.set("size", DeprecatedString::number(time_zone_data.time_zone_names.size()));
generator.set("size", ByteString::number(time_zone_data.time_zone_names.size()));
generator.append(R"~~~(
static constexpr Array<Location, @size@> s_time_zone_locations { {
)~~~");
@ -620,12 +620,12 @@ static constexpr Array<Location, @size@> s_time_zone_locations { {
for (auto const& time_zone : time_zone_data.time_zone_names) {
auto location = time_zone_data.time_zone_coordinates.get(time_zone).value_or({});
generator.append(DeprecatedString::formatted(" {},\n", location));
generator.append(ByteString::formatted(" {},\n", location));
}
generator.append("} };\n");
auto append_string_conversions = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) -> ErrorOr<void> {
HashValueMap<DeprecatedString> hashes;
HashValueMap<ByteString> hashes;
TRY(hashes.try_ensure_capacity(values.size()));
auto hash = [](auto const& value) {
@ -750,10 +750,10 @@ Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone,
auto const& time_zone_offset = find_time_zone_offset(time_zone, time);
Array<NamedOffset, 2> named_offsets;
auto format_name = [](auto format, auto offset) -> DeprecatedString {
auto format_name = [](auto format, auto offset) -> ByteString {
if (offset == 0)
return decode_string(format).replace("{}"sv, ""sv, ReplaceMode::FirstOnly);
return DeprecatedString::formatted(decode_string(format), decode_string(offset));
return ByteString::formatted(decode_string(format), decode_string(offset));
};
auto set_named_offset = [&](auto& named_offset, auto dst_offset, auto in_dst, auto format, auto offset) {

View file

@ -6,7 +6,7 @@
#include "GeneratorUtil.h"
#include <AK/AnyOf.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/QuickSort.h>
#include <AK/SourceGenerator.h>
#include <AK/StringUtils.h>
@ -20,11 +20,11 @@ struct Emoji {
size_t name { 0 };
Optional<size_t> image_path;
Unicode::EmojiGroup group;
DeprecatedString subgroup;
ByteString subgroup;
u32 display_order { 0 };
Vector<u32> code_points;
DeprecatedString encoded_code_points;
DeprecatedString status;
ByteString encoded_code_points;
ByteString status;
size_t code_point_array_index { 0 };
};
@ -45,8 +45,8 @@ static void set_image_path_for_emoji(StringView emoji_resource_path, EmojiData&
builder.appendff("U+{:X}", code_point);
}
auto file = DeprecatedString::formatted("{}.png", builder.to_deprecated_string());
auto path = DeprecatedString::formatted("{}/{}", emoji_resource_path, file);
auto file = ByteString::formatted("{}.png", builder.to_byte_string());
auto path = ByteString::formatted("{}/{}", emoji_resource_path, file);
if (!FileSystem::exists(path))
return;
@ -61,7 +61,7 @@ static ErrorOr<void> parse_emoji_test_data(Core::InputBufferedFile& file, EmojiD
Array<u8, 1024> buffer;
Unicode::EmojiGroup group;
DeprecatedString subgroup;
ByteString subgroup;
u32 display_order { 0 };
while (TRY(file.can_read_line())) {
@ -157,7 +157,7 @@ static ErrorOr<void> parse_emoji_serenity_data(Core::InputBufferedFile& file, Em
return {};
}));
auto name = builder.to_deprecated_string();
auto name = builder.to_byte_string();
if (!any_of(name, is_ascii_lower_alpha))
name = name.to_titlecase();
@ -218,7 +218,7 @@ static ErrorOr<void> generate_emoji_data_implementation(Core::InputBufferedFile&
SourceGenerator generator { builder };
generator.set("string_index_type"sv, emoji_data.unique_strings.type_that_fits());
generator.set("emojis_size"sv, DeprecatedString::number(emoji_data.emojis.size()));
generator.set("emojis_size"sv, ByteString::number(emoji_data.emojis.size()));
generator.append(R"~~~(
#include <AK/Array.h>
@ -238,7 +238,7 @@ namespace Unicode {
for (auto const& emoji : emoji_data.emojis) {
total_code_point_count += emoji.code_points.size();
}
generator.set("total_code_point_count", DeprecatedString::number(total_code_point_count));
generator.set("total_code_point_count", ByteString::number(total_code_point_count));
generator.append(R"~~~(
static constexpr Array<u32, @total_code_point_count@> s_emoji_code_points { {)~~~");
@ -247,7 +247,7 @@ static constexpr Array<u32, @total_code_point_count@> s_emoji_code_points { {)~~
for (auto const& emoji : emoji_data.emojis) {
for (auto code_point : emoji.code_points) {
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::formatted("{:#x}", code_point));
generator.append(ByteString::formatted("{:#x}", code_point));
first = false;
}
}
@ -288,12 +288,12 @@ struct EmojiData {
static constexpr Array<EmojiData, @emojis_size@> s_emojis { {)~~~");
for (auto const& emoji : emoji_data.emojis) {
generator.set("name"sv, DeprecatedString::number(emoji.name));
generator.set("image_path"sv, DeprecatedString::number(emoji.image_path.value_or(0)));
generator.set("group"sv, DeprecatedString::number(to_underlying(emoji.group)));
generator.set("display_order"sv, DeprecatedString::number(emoji.display_order));
generator.set("code_point_start"sv, DeprecatedString::number(emoji.code_point_array_index));
generator.set("code_point_count"sv, DeprecatedString::number(emoji.code_points.size()));
generator.set("name"sv, ByteString::number(emoji.name));
generator.set("image_path"sv, ByteString::number(emoji.image_path.value_or(0)));
generator.set("group"sv, ByteString::number(to_underlying(emoji.group)));
generator.set("display_order"sv, ByteString::number(emoji.display_order));
generator.set("code_point_start"sv, ByteString::number(emoji.code_point_array_index));
generator.set("code_point_count"sv, ByteString::number(emoji.code_points.size()));
generator.append(R"~~~(
{ @name@, @image_path@, @group@, @display_order@, @code_point_start@, @code_point_count@ },)~~~");
@ -370,7 +370,7 @@ static ErrorOr<void> generate_emoji_installation(Core::InputBufferedFile& file,
generator.append("@emoji@"sv);
generator.append(" - "sv);
generator.append(DeprecatedString::join(" "sv, emoji.code_points, "U+{:X}"sv));
generator.append(ByteString::join(" "sv, emoji.code_points, "U+{:X}"sv));
generator.append(" @name@ (@status@)\n"sv);
}

View file

@ -7,8 +7,8 @@
#include "GeneratorUtil.h"
#include <AK/AllOf.h>
#include <AK/Array.h>
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/Find.h>
#include <AK/HashMap.h>
@ -28,8 +28,8 @@ struct SpecialCasing {
Vector<u32> lowercase_mapping;
Vector<u32> uppercase_mapping;
Vector<u32> titlecase_mapping;
DeprecatedString locale;
DeprecatedString condition;
ByteString locale;
ByteString condition;
};
// https://www.unicode.org/reports/tr44/#CaseFolding.txt
@ -42,13 +42,13 @@ struct CaseFolding {
// https://www.unicode.org/reports/tr44/#Character_Decomposition_Mappings
struct CodePointDecomposition {
// `tag` is a string since it's used for codegen as an enum value.
DeprecatedString tag { "Canonical"sv };
ByteString tag { "Canonical"sv };
size_t decomposition_index { 0 };
size_t decomposition_size { 0 };
};
// https://www.unicode.org/reports/tr44/#PropList.txt
using PropList = HashMap<DeprecatedString, Vector<Unicode::CodePointRange>>;
using PropList = HashMap<ByteString, Vector<Unicode::CodePointRange>>;
// https://www.unicode.org/reports/tr44/#DerivedNormalizationProps.txt
enum class QuickCheck {
@ -63,7 +63,7 @@ struct Normalization {
QuickCheck quick_check { QuickCheck::Yes };
};
using NormalizationProps = HashMap<DeprecatedString, Vector<Normalization>>;
using NormalizationProps = HashMap<ByteString, Vector<Normalization>>;
struct CodePointName {
Unicode::CodePointRange code_point_range;
@ -92,16 +92,16 @@ struct CasingTable {
// https://www.unicode.org/reports/tr44/#UnicodeData.txt
struct CodePointData {
u32 code_point { 0 };
DeprecatedString name;
ByteString name;
Optional<size_t> abbreviation;
DeprecatedString bidi_class;
ByteString bidi_class;
Optional<CodePointDecomposition> decomposition_mapping;
Optional<i8> numeric_value_decimal;
Optional<i8> numeric_value_digit;
Optional<i8> numeric_value_numeric;
bool bidi_mirrored { false };
DeprecatedString unicode_1_name;
DeprecatedString iso_comment;
ByteString unicode_1_name;
ByteString iso_comment;
CasingTable casing;
};
@ -127,7 +127,7 @@ struct CodePointTables {
struct CodePointBidiClass {
Unicode::CodePointRange code_point_range;
DeprecatedString bidi_class;
ByteString bidi_class;
};
struct UnicodeData {
@ -135,12 +135,12 @@ struct UnicodeData {
u32 code_points_with_decomposition_mapping { 0 };
Vector<u32> decomposition_mappings;
Vector<DeprecatedString> compatibility_tags;
Vector<ByteString> compatibility_tags;
Vector<SpecialCasing> special_casing;
u32 largest_special_casing_mapping_size { 0 };
Vector<DeprecatedString> conditions;
Vector<DeprecatedString> locales;
Vector<ByteString> conditions;
Vector<ByteString> locales;
Vector<CaseFolding> case_folding;
u32 largest_case_folding_mapping_size { 0 };
@ -190,11 +190,11 @@ struct UnicodeData {
CodePointTables<PropertyTable> word_break_tables;
CodePointTables<PropertyTable> sentence_break_tables;
HashTable<DeprecatedString> bidirectional_classes;
HashTable<ByteString> bidirectional_classes;
Vector<CodePointBidiClass> code_point_bidirectional_classes;
};
static DeprecatedString sanitize_entry(DeprecatedString const& entry)
static ByteString sanitize_entry(ByteString const& entry)
{
auto sanitized = entry.replace("-"sv, "_"sv, ReplaceMode::All);
sanitized = sanitized.replace(" "sv, "_"sv, ReplaceMode::All);
@ -209,7 +209,7 @@ static DeprecatedString sanitize_entry(DeprecatedString const& entry)
next_is_upper = ch == '_';
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
static ErrorOr<void> parse_special_casing(Core::InputBufferedFile& file, UnicodeData& unicode_data)
@ -248,7 +248,7 @@ static ErrorOr<void> parse_special_casing(Core::InputBufferedFile& file, Unicode
}
if (!casing.locale.is_empty()) {
casing.locale = DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
casing.locale = ByteString::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
if (!unicode_data.locales.contains_slow(casing.locale))
unicode_data.locales.append(casing.locale);
@ -380,7 +380,7 @@ static ErrorOr<void> parse_prop_list(Core::InputBufferedFile& file, PropList& pr
static ErrorOr<void> parse_alias_list(Core::InputBufferedFile& file, PropList const& prop_list, Vector<Alias>& prop_aliases)
{
DeprecatedString current_property;
ByteString current_property;
Array<u8, 1024> buffer;
auto append_alias = [&](auto alias, auto property) {
@ -455,7 +455,7 @@ static ErrorOr<void> parse_name_aliases(Core::InputBufferedFile& file, UnicodeDa
return {};
}
static ErrorOr<void> parse_value_alias_list(Core::InputBufferedFile& file, StringView desired_category, Vector<DeprecatedString> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true, bool sanitize_alias = false)
static ErrorOr<void> parse_value_alias_list(Core::InputBufferedFile& file, StringView desired_category, Vector<ByteString> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true, bool sanitize_alias = false)
{
TRY(file.seek(0, SeekMode::SetPosition));
Array<u8, 1024> buffer;
@ -518,7 +518,7 @@ static ErrorOr<void> parse_normalization_props(Core::InputBufferedFile& file, Un
VERIFY((segments.size() == 2) || (segments.size() == 3));
auto code_point_range = parse_code_point_range(segments[0].trim_whitespace());
auto property = segments[1].trim_whitespace().to_deprecated_string();
auto property = segments[1].trim_whitespace().to_byte_string();
Vector<u32> value;
QuickCheck quick_check = QuickCheck::Yes;
@ -620,7 +620,7 @@ static Optional<CodePointDecomposition> parse_decomposition_mapping(StringView s
if (parts.first().starts_with('<')) {
auto const tag = parts.take_first().trim("<>"sv);
mapping.tag = DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(tag[0]), tag.substring_view(1));
mapping.tag = ByteString::formatted("{:c}{}", to_ascii_uppercase(tag[0]), tag.substring_view(1));
if (!unicode_data.compatibility_tags.contains_slow(mapping.tag))
unicode_data.compatibility_tags.append(mapping.tag);
@ -755,15 +755,15 @@ static ErrorOr<void> generate_unicode_data_header(Core::InputBufferedFile& file,
{
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("special_casing_mapping_size", DeprecatedString::number(unicode_data.largest_special_casing_mapping_size));
generator.set("case_folding_mapping_size", DeprecatedString::number(unicode_data.largest_case_folding_mapping_size));
generator.set("special_casing_mapping_size", ByteString::number(unicode_data.largest_special_casing_mapping_size));
generator.set("case_folding_mapping_size", ByteString::number(unicode_data.largest_case_folding_mapping_size));
auto generate_enum = [&](StringView name, StringView default_, auto values, Vector<Alias> aliases = {}) {
quick_sort(values);
quick_sort(aliases, [](auto& alias1, auto& alias2) { return alias1.alias < alias2.alias; });
generator.set("name", name);
generator.set("underlying", DeprecatedString::formatted("{}UnderlyingType", name));
generator.set("underlying", ByteString::formatted("{}UnderlyingType", name));
generator.set("type", ((values.size() + !default_.is_empty()) < 256) ? "u8"sv : "u16"sv);
generator.append(R"~~~(
@ -872,8 +872,8 @@ static ErrorOr<void> generate_unicode_data_implementation(Core::InputBufferedFil
SourceGenerator generator { builder };
generator.set("string_index_type"sv, unicode_data.unique_strings.type_that_fits());
generator.set("special_casing_size", DeprecatedString::number(unicode_data.special_casing.size()));
generator.set("case_folding_size", DeprecatedString::number(unicode_data.case_folding.size()));
generator.set("special_casing_size", ByteString::number(unicode_data.special_casing.size()));
generator.set("case_folding_size", ByteString::number(unicode_data.case_folding.size()));
generator.set("CODE_POINT_TABLES_LSB_COUNT", TRY(String::number(CODE_POINT_TABLES_LSB_COUNT)));
generator.set("CODE_POINT_TABLES_LSB_MASK", TRY(String::formatted("{:#x}", CODE_POINT_TABLES_LSB_MASK)));
@ -884,7 +884,7 @@ static ErrorOr<void> generate_unicode_data_implementation(Core::InputBufferedFil
#include <AK/CharacterTypes.h>
#include <AK/Optional.h>
#include <AK/Span.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/StringView.h>
#include <LibUnicode/CharacterTypes.h>
#include <LibUnicode/UnicodeData.h>
@ -905,17 +905,17 @@ namespace Unicode {
generator.append(", {");
for (auto const& item : list) {
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::formatted(format, item));
generator.append(ByteString::formatted(format, item));
first = false;
}
generator.append(DeprecatedString::formatted(" }}, {}", list.size()));
generator.append(ByteString::formatted(" }}, {}", list.size()));
};
generator.append(R"~~~(
static constexpr Array<SpecialCasing, @special_casing_size@> s_special_case { {)~~~");
for (auto const& casing : unicode_data.special_casing) {
generator.set("code_point", DeprecatedString::formatted("{:#x}", casing.code_point));
generator.set("code_point", ByteString::formatted("{:#x}", casing.code_point));
generator.append(R"~~~(
{ @code_point@)~~~");
@ -939,7 +939,7 @@ static constexpr Array<SpecialCasing, @special_casing_size@> s_special_case { {)
static constexpr Array<CaseFolding, @case_folding_size@> s_case_folding { {)~~~");
for (auto const& folding : unicode_data.case_folding) {
generator.set("code_point", DeprecatedString::formatted("{:#x}", folding.code_point));
generator.set("code_point", ByteString::formatted("{:#x}", folding.code_point));
generator.set("status", folding.status);
generator.append(R"~~~(
{ @code_point@, CaseFoldingStatus::@status@)~~~");
@ -1015,15 +1015,15 @@ struct CodePointBidiClassComparator : public CodePointRangeComparator {
)~~~");
generator.set("decomposition_mappings_size", DeprecatedString::number(unicode_data.decomposition_mappings.size()));
generator.set("decomposition_mappings_size", ByteString::number(unicode_data.decomposition_mappings.size()));
generator.append("\nstatic constexpr Array<u32, @decomposition_mappings_size@> s_decomposition_mappings_data { ");
generator.append(DeprecatedString::join(", "sv, unicode_data.decomposition_mappings, "{:#x}"sv));
generator.append(ByteString::join(", "sv, unicode_data.decomposition_mappings, "{:#x}"sv));
generator.append(" };\n");
auto append_code_point_mappings = [&](StringView name, StringView mapping_type, u32 size, auto mapping_getter) {
generator.set("name", name);
generator.set("mapping_type", mapping_type);
generator.set("size", DeprecatedString::number(size));
generator.set("size", ByteString::number(size));
generator.append(R"~~~(
static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
@ -1046,16 +1046,16 @@ static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
if (mappings_in_current_row++ > 0)
generator.append(" ");
generator.set("code_point", DeprecatedString::formatted("{:#x}", data.code_point));
generator.set("code_point", ByteString::formatted("{:#x}", data.code_point));
generator.append("{ @code_point@");
if constexpr (IsSame<decltype(mapping), Optional<u32>> || IsSame<decltype(mapping), Optional<size_t>>) {
generator.set("mapping", DeprecatedString::formatted("{:#x}", *mapping));
generator.set("mapping", ByteString::formatted("{:#x}", *mapping));
generator.append(", @mapping@ },");
} else if constexpr (IsSame<decltype(mapping), Optional<CodePointDecomposition>>) {
generator.set("tag", mapping->tag);
generator.set("start", DeprecatedString::number(mapping->decomposition_index));
generator.set("size", DeprecatedString::number(mapping->decomposition_size));
generator.set("start", ByteString::number(mapping->decomposition_index));
generator.set("size", ByteString::number(mapping->decomposition_size));
generator.append(", CompatibilityFormattingTag::@tag@, @start@, @size@ },");
} else {
append_list_and_size(mapping, "&s_@name@[{}]"sv);
@ -1195,7 +1195,7 @@ static constexpr Array<@type@, @size@> @name@ { {
generator.set("type", type);
generator.set("name", name);
generator.set("size", DeprecatedString::number(display_names.size()));
generator.set("size", ByteString::number(display_names.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {
@ -1204,9 +1204,9 @@ static constexpr Array<@type@, @size@> @name@ { {
if (values_in_current_row++ > 0)
generator.append(", ");
generator.set("first", DeprecatedString::formatted("{:#x}", display_name.code_point_range.first));
generator.set("last", DeprecatedString::formatted("{:#x}", display_name.code_point_range.last));
generator.set("name", DeprecatedString::number(display_name.name));
generator.set("first", ByteString::formatted("{:#x}", display_name.code_point_range.first));
generator.set("last", ByteString::formatted("{:#x}", display_name.code_point_range.last));
generator.set("name", ByteString::number(display_name.name));
generator.append("{ { @first@, @last@ }, @name@ }");
if (values_in_current_row == max_values_per_row) {
@ -1226,7 +1226,7 @@ static constexpr Array<@type@, @size@> @name@ { {
constexpr size_t max_bidi_classes_per_row = 20;
size_t bidi_classes_in_current_row = 0;
generator.set("size"sv, DeprecatedString::number(unicode_data.code_point_bidirectional_classes.size()));
generator.set("size"sv, ByteString::number(unicode_data.code_point_bidirectional_classes.size()));
generator.append(R"~~~(
static constexpr Array<BidiClassData, @size@> s_bidirectional_classes { {
)~~~");
@ -1234,8 +1234,8 @@ static constexpr Array<BidiClassData, @size@> s_bidirectional_classes { {
if (bidi_classes_in_current_row++ > 0)
generator.append(", ");
generator.set("first", DeprecatedString::formatted("{:#x}", data.code_point_range.first));
generator.set("last", DeprecatedString::formatted("{:#x}", data.code_point_range.last));
generator.set("first", ByteString::formatted("{:#x}", data.code_point_range.first));
generator.set("last", ByteString::formatted("{:#x}", data.code_point_range.last));
generator.set("bidi_class", data.bidi_class);
generator.append("{ { @first@, @last@ }, BidirectionalClass::@bidi_class@ }");
@ -1274,13 +1274,13 @@ ReadonlySpan<BlockName> block_display_names()
return display_names.span();
}
Optional<DeprecatedString> code_point_display_name(u32 code_point)
Optional<ByteString> code_point_display_name(u32 code_point)
{
if (auto const* entry = binary_search(s_code_point_display_names, code_point, nullptr, CodePointNameComparator {})) {
auto display_name = decode_string(entry->display_name);
if (display_name.ends_with("{:X}"sv))
return DeprecatedString::formatted(display_name, code_point);
return ByteString::formatted(display_name, code_point);
return display_name;
}
@ -1409,7 +1409,7 @@ bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
ValueFromStringOptions options {};
for (auto const& prop : prop_list) {
if constexpr (IsSame<RemoveCVReference<decltype(prop)>, DeprecatedString>) {
if constexpr (IsSame<RemoveCVReference<decltype(prop)>, ByteString>) {
hashes.set(CaseInsensitiveASCIIStringViewTraits::hash(prop), prop);
options.sensitivity = CaseSensitivity::CaseInsensitive;
} else {

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Function.h>
#include <AK/HashFunctions.h>
#include <AK/HashMap.h>
@ -101,7 +101,7 @@ public:
{
generator.set("type"sv, type);
generator.set("name"sv, name);
generator.set("size"sv, DeprecatedString::number(m_storage.size()));
generator.set("size"sv, ByteString::number(m_storage.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@ + 1> @name@ { {
@ -113,10 +113,10 @@ static constexpr Array<@type@, @size@ + 1> @name@ { {
if (values_in_current_row++ > 0)
generator.append(", ");
if constexpr (IsSame<StorageType, DeprecatedString>)
generator.append(DeprecatedString::formatted("\"{}\"sv", value));
if constexpr (IsSame<StorageType, ByteString>)
generator.append(ByteString::formatted("\"{}\"sv", value));
else
generator.append(DeprecatedString::formatted("{}", value));
generator.append(ByteString::formatted("{}", value));
if (values_in_current_row == max_values_per_row) {
values_in_current_row = 0;
@ -138,8 +138,8 @@ static constexpr Array<@type@, @size@ + 1> @name@ { {
for (size_t i = 0; i < m_storage.size(); ++i) {
auto const& list = m_storage[i];
generator.set("index"sv, DeprecatedString::number(i));
generator.set("size"sv, DeprecatedString::number(list.size()));
generator.set("index"sv, ByteString::number(i));
generator.set("size"sv, ByteString::number(list.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@@index@ { {)~~~");
@ -147,14 +147,14 @@ static constexpr Array<@type@, @size@> @name@@index@ { {)~~~");
bool first = true;
for (auto const& value : list) {
generator.append(first ? " "sv : ", "sv);
generator.append(DeprecatedString::formatted("{}", value));
generator.append(ByteString::formatted("{}", value));
first = false;
}
generator.append(" } };");
}
generator.set("size"sv, DeprecatedString::number(m_storage.size()));
generator.set("size"sv, ByteString::number(m_storage.size()));
generator.append(R"~~~(
@ -168,7 +168,7 @@ static constexpr Array<ReadonlySpan<@type@>, @size@ + 1> @name@ { {
if (values_in_current_row++ > 0)
generator.append(", ");
generator.set("index"sv, DeprecatedString::number(i));
generator.set("index"sv, ByteString::number(i));
generator.append("@name@@index@.span()");
if (values_in_current_row == max_values_per_row) {
@ -187,8 +187,8 @@ protected:
HashMap<StorageType, size_t> m_storage_indices;
};
class UniqueStringStorage : public UniqueStorage<DeprecatedString> {
using Base = UniqueStorage<DeprecatedString>;
class UniqueStringStorage : public UniqueStorage<ByteString> {
using Base = UniqueStorage<ByteString>;
public:
// The goal of the string table generator is to ensure the table is located within the read-only
@ -204,7 +204,7 @@ public:
if (values_in_current_row++ > 0)
generator.append(", ");
generator.append(DeprecatedString::formatted("{:#x}", value));
generator.append(ByteString::formatted("{:#x}", value));
if (values_in_current_row == max_values_per_row) {
values_in_current_row = 0;
@ -224,7 +224,7 @@ public:
next_index += string.length() + 2;
}
generator.set("size", DeprecatedString::number(next_index));
generator.set("size", ByteString::number(next_index));
generator.append(R"~~~(
static constexpr Array<u8, @size@> s_encoded_strings { {
)~~~");
@ -242,7 +242,7 @@ static constexpr Array<u8, @size@> s_encoded_strings { {
} };
)~~~");
generator.set("size", DeprecatedString::number(string_indices.size()));
generator.set("size", ByteString::number(string_indices.size()));
generator.append(R"~~~(
static constexpr Array<u32, @size@> s_encoded_string_indices { {
)~~~");
@ -276,8 +276,8 @@ static constexpr StringView decode_string(size_t index)
};
struct Alias {
DeprecatedString name;
DeprecatedString alias;
ByteString name;
ByteString alias;
};
struct CanonicalLanguageID {
@ -385,11 +385,11 @@ void generate_value_from_string(SourceGenerator& generator, StringView method_na
{
ensure_from_string_types_are_generated(generator);
generator.set("method_name", DeprecatedString::formatted(method_name_format, value_name));
generator.set("method_name", ByteString::formatted(method_name_format, value_name));
generator.set("value_type", value_type);
generator.set("value_name", value_name);
generator.set("return_type", options.return_type.has_value() ? *options.return_type : value_type);
generator.set("size", DeprecatedString::number(hashes.size()));
generator.set("size", ByteString::number(hashes.size()));
generator.append(R"~~~(
Optional<@return_type@> @method_name@(StringView key)
@ -408,11 +408,11 @@ Optional<@return_type@> @method_name@(StringView key)
generator.append(" ");
if constexpr (IsIntegral<ValueType>)
generator.set("value"sv, DeprecatedString::number(hashes.get(hash_key).value()));
generator.set("value"sv, ByteString::number(hashes.get(hash_key).value()));
else
generator.set("value"sv, DeprecatedString::formatted("{}::{}", value_type, hashes.get(hash_key).value()));
generator.set("value"sv, ByteString::formatted("{}::{}", value_type, hashes.get(hash_key).value()));
generator.set("hash"sv, DeprecatedString::number(hash_key));
generator.set("hash"sv, ByteString::number(hash_key));
generator.append("{ @hash@U, @value@ },"sv);
if (values_in_current_row == max_values_per_row) {
@ -421,7 +421,7 @@ Optional<@return_type@> @method_name@(StringView key)
}
}
generator.set("return_statement", DeprecatedString::formatted(options.return_format, "value->value"sv));
generator.set("return_statement", ByteString::formatted(options.return_format, "value->value"sv));
generator.append(R"~~~(
} };
)~~~");
@ -445,9 +445,9 @@ Optional<@return_type@> @method_name@(StringView key)
}
template<typename IdentifierFormatter>
void generate_value_to_string(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, IdentifierFormatter&& format_identifier, ReadonlySpan<DeprecatedString> values)
void generate_value_to_string(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, IdentifierFormatter&& format_identifier, ReadonlySpan<ByteString> values)
{
generator.set("method_name", DeprecatedString::formatted(method_name_format, value_name));
generator.set("method_name", ByteString::formatted(method_name_format, value_name));
generator.set("value_type", value_type);
generator.set("value_name", value_name);
@ -475,7 +475,7 @@ StringView @method_name@(@value_type@ @value_name@)
}
template<typename IdentifierFormatter>
void generate_enum(SourceGenerator& generator, IdentifierFormatter&& format_identifier, StringView name, StringView default_, Vector<DeprecatedString>& values, Vector<Alias> aliases = {})
void generate_enum(SourceGenerator& generator, IdentifierFormatter&& format_identifier, StringView name, StringView default_, Vector<ByteString>& values, Vector<Alias> aliases = {})
{
quick_sort(values, [](auto const& value1, auto const& value2) { return value1.to_lowercase() < value2.to_lowercase(); });
quick_sort(aliases, [](auto const& alias1, auto const& alias2) { return alias1.alias.to_lowercase() < alias2.alias.to_lowercase(); });
@ -514,20 +514,20 @@ template<typename LocalesType, typename IdentifierFormatter, typename ListFormat
void generate_mapping(SourceGenerator& generator, LocalesType const& locales, StringView type, StringView name, StringView format, IdentifierFormatter&& format_identifier, ListFormatter&& format_list)
{
auto format_mapping_name = [&](StringView format, StringView name) {
DeprecatedString mapping_name;
ByteString mapping_name;
if constexpr (IsNullPointer<IdentifierFormatter>)
mapping_name = name.replace("-"sv, "_"sv, ReplaceMode::All);
else
mapping_name = format_identifier(type, name);
return DeprecatedString::formatted(format, mapping_name.to_lowercase());
return ByteString::formatted(format, mapping_name.to_lowercase());
};
Vector<DeprecatedString> mapping_names;
Vector<ByteString> mapping_names;
for (auto const& locale : locales) {
DeprecatedString mapping_name;
ByteString mapping_name;
if constexpr (requires { locale.key; }) {
mapping_name = format_mapping_name(format, locale.key);
@ -544,7 +544,7 @@ void generate_mapping(SourceGenerator& generator, LocalesType const& locales, St
generator.set("type", type);
generator.set("name", name);
generator.set("size", DeprecatedString::number(locales.size()));
generator.set("size", ByteString::number(locales.size()));
generator.append(R"~~~(
static constexpr Array<ReadonlySpan<@type@>, @size@> @name@ { {
)~~~");
@ -589,9 +589,9 @@ ReadonlySpan<StringView> @name@()
first = false;
if (auto it = aliases.find_if([&](auto const& alias) { return alias.alias == value; }); it != aliases.end())
generator.append(DeprecatedString::formatted("\"{}\"sv", it->name));
generator.append(ByteString::formatted("\"{}\"sv", it->name));
else
generator.append(DeprecatedString::formatted("\"{}\"sv", value));
generator.append(ByteString::formatted("\"{}\"sv", value));
}
generator.append(R"~~~( };

View file

@ -112,7 +112,7 @@ static StringView sequence_storage_type_to_cpp_storage_type_name(SequenceStorage
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface);
static DeprecatedString union_type_to_variant(UnionType const& union_type, Interface const& interface)
static ByteString union_type_to_variant(UnionType const& union_type, Interface const& interface)
{
StringBuilder builder;
builder.append("Variant<"sv);
@ -132,16 +132,16 @@ static DeprecatedString union_type_to_variant(UnionType const& union_type, Inter
builder.append(", Empty"sv);
builder.append('>');
return builder.to_deprecated_string();
return builder.to_byte_string();
}
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
{
if (is_platform_object(type) || type.name() == "WindowProxy"sv)
return { .name = DeprecatedString::formatted("JS::Handle<{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
return { .name = ByteString::formatted("JS::Handle<{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
if (is_javascript_builtin(type))
return { .name = DeprecatedString::formatted("JS::Handle<JS::{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
return { .name = ByteString::formatted("JS::Handle<JS::{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
if (interface.callback_functions.contains(type.name()))
return { .name = "JS::Handle<WebIDL::CallbackType>", .sequence_storage_type = SequenceStorageType::MarkedVector };
@ -200,7 +200,7 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
if (sequence_cpp_type.sequence_storage_type == SequenceStorageType::MarkedVector)
return { .name = storage_type_name, .sequence_storage_type = SequenceStorageType::Vector };
return { .name = DeprecatedString::formatted("{}<{}>", storage_type_name, sequence_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
return { .name = ByteString::formatted("{}<{}>", storage_type_name, sequence_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
}
if (type.name() == "record") {
@ -210,7 +210,7 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
auto record_key_cpp_type = idl_type_name_to_cpp_type(record_key_type, interface);
auto record_value_cpp_type = idl_type_name_to_cpp_type(record_value_type, interface);
return { .name = DeprecatedString::formatted("OrderedHashMap<{}, {}>", record_key_cpp_type.name, record_value_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
return { .name = ByteString::formatted("OrderedHashMap<{}, {}>", record_key_cpp_type.name, record_value_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
}
if (is<UnionType>(type)) {
@ -229,13 +229,13 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
TODO();
}
static DeprecatedString make_input_acceptable_cpp(DeprecatedString const& input)
static ByteString make_input_acceptable_cpp(ByteString const& input)
{
if (input.is_one_of("class", "template", "for", "default", "char", "namespace", "delete", "inline")) {
StringBuilder builder;
builder.append(input);
builder.append('_');
return builder.to_deprecated_string();
return builder.to_byte_string();
}
return input.replace("-"sv, "_"sv, ReplaceMode::All);
@ -266,7 +266,7 @@ static void generate_include_for(auto& generator, auto& path)
}
LexicalPath include_path { path_string };
forked_generator.set("include.path", DeprecatedString::formatted("{}/{}.h", include_path.dirname(), include_path.title()));
forked_generator.set("include.path", ByteString::formatted("{}/{}.h", include_path.dirname(), include_path.title()));
forked_generator.append(R"~~~(
#include <@include.path@>
)~~~");
@ -275,7 +275,7 @@ static void generate_include_for(auto& generator, auto& path)
static void emit_includes_for_all_imports(auto& interface, auto& generator, bool is_iterator = false)
{
Queue<RemoveCVReference<decltype(interface)> const*> interfaces;
HashTable<DeprecatedString> paths_imported;
HashTable<ByteString> paths_imported;
interfaces.enqueue(&interface);
@ -297,13 +297,13 @@ static void emit_includes_for_all_imports(auto& interface, auto& generator, bool
}
if (is_iterator) {
auto iterator_path = DeprecatedString::formatted("{}Iterator", interface.fully_qualified_name.replace("::"sv, "/"sv, ReplaceMode::All));
auto iterator_path = ByteString::formatted("{}Iterator", interface.fully_qualified_name.replace("::"sv, "/"sv, ReplaceMode::All));
generate_include_for_iterator(generator, iterator_path);
}
}
template<typename ParameterType>
static void generate_to_string(SourceGenerator& scoped_generator, ParameterType const& parameter, bool variadic, bool optional, Optional<DeprecatedString> const& optional_default_value)
static void generate_to_string(SourceGenerator& scoped_generator, ParameterType const& parameter, bool variadic, bool optional, Optional<ByteString> const& optional_default_value)
{
if (variadic) {
scoped_generator.append(R"~~~(
@ -363,7 +363,7 @@ static void generate_to_string(SourceGenerator& scoped_generator, ParameterType
}
template<typename ParameterType>
static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter, DeprecatedString const& js_name, DeprecatedString const& js_suffix, DeprecatedString const& cpp_name, IDL::Interface const& interface, bool legacy_null_to_empty_string = false, bool optional = false, Optional<DeprecatedString> optional_default_value = {}, bool variadic = false, size_t recursion_depth = 0)
static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter, ByteString const& js_name, ByteString const& js_suffix, ByteString const& cpp_name, IDL::Interface const& interface, bool legacy_null_to_empty_string = false, bool optional = false, Optional<ByteString> optional_default_value = {}, bool variadic = false, size_t recursion_depth = 0)
{
auto scoped_generator = generator.fork();
auto acceptable_cpp_name = make_input_acceptable_cpp(cpp_name);
@ -698,7 +698,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto default_value_cpp_name = enumeration.translated_cpp_names.get(enum_member_name);
VERIFY(default_value_cpp_name.has_value());
enum_generator.set("enum.default.cpp_value", *default_value_cpp_name);
enum_generator.set("js_name.as_string", DeprecatedString::formatted("{}{}_string", enum_generator.get("js_name"sv), enum_generator.get("js_suffix"sv)));
enum_generator.set("js_name.as_string", ByteString::formatted("{}{}_string", enum_generator.get("js_name"sv), enum_generator.get("js_suffix"sv)));
enum_generator.append(R"~~~(
@parameter.type.name@ @cpp_name@ { @parameter.type.name@::@enum.default.cpp_value@ };
)~~~");
@ -761,8 +761,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
for (auto& member : current_dictionary->members) {
dictionary_generator.set("member_key", member.name);
auto member_js_name = make_input_acceptable_cpp(member.name.to_snakecase());
auto member_value_name = DeprecatedString::formatted("{}_value_{}", member_js_name, i);
auto member_property_value_name = DeprecatedString::formatted("{}_property_value_{}", member_js_name, i);
auto member_value_name = ByteString::formatted("{}_value_{}", member_js_name, i);
auto member_property_value_name = ByteString::formatted("{}_property_value_{}", member_js_name, i);
dictionary_generator.set("member_name", member_js_name);
dictionary_generator.set("member_value_name", member_value_name);
dictionary_generator.set("member_property_value_name", member_property_value_name);
@ -848,7 +848,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto sequence_generator = scoped_generator.fork();
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
sequence_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
sequence_generator.set("recursion_depth", ByteString::number(recursion_depth));
// An ECMAScript value V is converted to an IDL sequence<T> value as follows:
// 1. If Type(V) is not Object, throw a TypeError.
@ -900,7 +900,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, @js_name@@js_suffix@.to_string_without_side_effects());
)~~~");
parameterized_type.generate_sequence_from_iterable(sequence_generator, DeprecatedString::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), DeprecatedString::formatted("{}{}", js_name, js_suffix), DeprecatedString::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
parameterized_type.generate_sequence_from_iterable(sequence_generator, ByteString::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), ByteString::formatted("{}{}", js_name, js_suffix), ByteString::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
if (optional) {
sequence_generator.append(R"~~~(
@ -913,7 +913,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto record_generator = scoped_generator.fork();
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
record_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
record_generator.set("recursion_depth", ByteString::number(recursion_depth));
// A record can only have two types: key type and value type.
VERIFY(parameterized_type.parameters().size() == 2);
@ -963,7 +963,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
)~~~");
IDL::Parameter key_parameter { .type = parameterized_type.parameters()[0], .name = acceptable_cpp_name, .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(record_generator, key_parameter, "key", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("typed_key{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
generate_to_cpp(record_generator, key_parameter, "key", ByteString::number(recursion_depth), ByteString::formatted("typed_key{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
record_generator.append(R"~~~(
auto value@recursion_depth@ = TRY(@js_name@@js_suffix@_object.get(property_key@recursion_depth@));
@ -971,7 +971,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// FIXME: Record value types should be TypeWithExtendedAttributes, which would allow us to get [LegacyNullToEmptyString] here.
IDL::Parameter value_parameter { .type = parameterized_type.parameters()[1], .name = acceptable_cpp_name, .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(record_generator, value_parameter, "value", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("typed_value{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
generate_to_cpp(record_generator, value_parameter, "value", ByteString::number(recursion_depth), ByteString::formatted("typed_value{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
record_generator.append(R"~~~(
@cpp_name@.set(typed_key@recursion_depth@, typed_value@recursion_depth@);
@ -984,7 +984,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto& union_type = verify_cast<IDL::UnionType>(*parameter.type);
union_generator.set("union_type", union_type_to_variant(union_type, interface));
union_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
union_generator.set("recursion_depth", ByteString::number(recursion_depth));
// NOTE: This is handled out here as we need the dictionary conversion code for the {} optional default value.
// 3. Let types be the flattened member types of the union type.
@ -1036,9 +1036,9 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
to_variant_captures.append("&vm, &realm"sv);
if (dictionary_type)
to_variant_captures.append(DeprecatedString::formatted(", &{}{}_to_dictionary", js_name, js_suffix));
to_variant_captures.append(ByteString::formatted(", &{}{}_to_dictionary", js_name, js_suffix));
union_generator.set("to_variant_captures", to_variant_captures.to_deprecated_string());
union_generator.set("to_variant_captures", to_variant_captures.to_byte_string());
union_generator.append(R"~~~(
auto @js_name@@js_suffix@_to_variant = [@to_variant_captures@](JS::Value @js_name@@js_suffix@) -> JS::ThrowCompletionOr<@union_type@> {
@ -1211,7 +1211,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (method) {
)~~~");
sequence_type->generate_sequence_from_iterable(union_generator, acceptable_cpp_name, DeprecatedString::formatted("{}{}", js_name, js_suffix), "method", interface, recursion_depth + 1);
sequence_type->generate_sequence_from_iterable(union_generator, acceptable_cpp_name, ByteString::formatted("{}{}", js_name, js_suffix), "method", interface, recursion_depth + 1);
union_generator.append(R"~~~(
@ -1296,8 +1296,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
)~~~");
// NOTE: generate_to_cpp doesn't use the parameter name.
// NOTE: generate_to_cpp will use to_{u32,etc.} which uses to_number internally and will thus use TRY, but it cannot throw as we know we are dealing with a number.
IDL::Parameter parameter { .type = *numeric_type, .name = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, DeprecatedString::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
IDL::Parameter parameter { .type = *numeric_type, .name = ByteString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, ByteString::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
union_generator.append(R"~~~(
return { @js_name@@js_suffix@_number };
@ -1361,8 +1361,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// NOTE: generate_to_cpp doesn't use the parameter name.
// NOTE: generate_to_cpp will use to_{u32,etc.} which uses to_number internally and will thus use TRY, but it cannot throw as we know we are dealing with a number.
IDL::Parameter parameter { .type = *numeric_type, .name = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_numeric_type_generator, parameter, "x", DeprecatedString::empty(), "x_number", interface, false, false, {}, false, recursion_depth + 1);
IDL::Parameter parameter { .type = *numeric_type, .name = ByteString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_numeric_type_generator, parameter, "x", ByteString::empty(), "x_number", interface, false, false, {}, false, recursion_depth + 1);
union_numeric_type_generator.append(R"~~~(
return x_number;
@ -1372,8 +1372,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// NOTE: generate_to_cpp doesn't use the parameter name.
// NOTE: generate_to_cpp will use to_{u32,etc.} which uses to_number internally and will thus use TRY, but it cannot throw as we know we are dealing with a number.
IDL::Parameter parameter { .type = *numeric_type, .name = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, DeprecatedString::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
IDL::Parameter parameter { .type = *numeric_type, .name = ByteString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, ByteString::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
union_generator.append(R"~~~(
return { @js_name@@js_suffix@_number };
@ -1457,21 +1457,21 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
}
}
static void generate_argument_count_check(SourceGenerator& generator, DeprecatedString const& function_name, size_t argument_count)
static void generate_argument_count_check(SourceGenerator& generator, ByteString const& function_name, size_t argument_count)
{
if (argument_count == 0)
return;
auto argument_count_check_generator = generator.fork();
argument_count_check_generator.set("function.name", function_name);
argument_count_check_generator.set("function.nargs", DeprecatedString::number(argument_count));
argument_count_check_generator.set("function.nargs", ByteString::number(argument_count));
if (argument_count == 1) {
argument_count_check_generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountOne");
argument_count_check_generator.set(".arg_count_suffix", "");
} else {
argument_count_check_generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountMany");
argument_count_check_generator.set(".arg_count_suffix", DeprecatedString::formatted(", \"{}\"", argument_count));
argument_count_check_generator.set(".arg_count_suffix", ByteString::formatted(", \"{}\"", argument_count));
}
argument_count_check_generator.append(R"~~~(
@ -1484,7 +1484,7 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
{
auto arguments_generator = generator.fork();
Vector<DeprecatedString> parameter_names;
Vector<ByteString> parameter_names;
size_t argument_index = 0;
for (auto& parameter : parameters) {
auto parameter_name = make_input_acceptable_cpp(parameter.name.to_snakecase());
@ -1492,18 +1492,18 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
if (parameter.variadic) {
// JS::MarkedVector is non-copyable, and the implementations likely want ownership of the
// list, so we move() it into the parameter list.
parameter_names.append(DeprecatedString::formatted("move({})", parameter_name));
parameter_names.append(ByteString::formatted("move({})", parameter_name));
} else {
parameter_names.append(move(parameter_name));
arguments_generator.set("argument.index", DeprecatedString::number(argument_index));
arguments_generator.set("argument.index", ByteString::number(argument_index));
arguments_generator.append(R"~~~(
auto arg@argument.index@ = vm.argument(@argument.index@);
)~~~");
}
bool legacy_null_to_empty_string = parameter.extended_attributes.contains("LegacyNullToEmptyString");
generate_to_cpp(generator, parameter, "arg", DeprecatedString::number(argument_index), parameter.name.to_snakecase(), interface, legacy_null_to_empty_string, parameter.optional, parameter.optional_default_value, parameter.variadic, 0);
generate_to_cpp(generator, parameter, "arg", ByteString::number(argument_index), parameter.name.to_snakecase(), interface, legacy_null_to_empty_string, parameter.optional, parameter.optional_default_value, parameter.variadic, 0);
++argument_index;
}
@ -1511,13 +1511,13 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
}
// https://webidl.spec.whatwg.org/#create-sequence-from-iterable
void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& generator, DeprecatedString const& cpp_name, DeprecatedString const& iterable_cpp_name, DeprecatedString const& iterator_method_cpp_name, IDL::Interface const& interface, size_t recursion_depth) const
void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& generator, ByteString const& cpp_name, ByteString const& iterable_cpp_name, ByteString const& iterator_method_cpp_name, IDL::Interface const& interface, size_t recursion_depth) const
{
auto sequence_generator = generator.fork();
sequence_generator.set("cpp_name", cpp_name);
sequence_generator.set("iterable_cpp_name", iterable_cpp_name);
sequence_generator.set("iterator_method_cpp_name", iterator_method_cpp_name);
sequence_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
sequence_generator.set("recursion_depth", ByteString::number(recursion_depth));
auto sequence_cpp_type = idl_type_name_to_cpp_type(parameters().first(), interface);
sequence_generator.set("sequence.type", sequence_cpp_type.name);
sequence_generator.set("sequence.storage_type", sequence_storage_type_to_cpp_storage_type_name(sequence_cpp_type.sequence_storage_type));
@ -1558,7 +1558,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge
// FIXME: Sequences types should be TypeWithExtendedAttributes, which would allow us to get [LegacyNullToEmptyString] here.
IDL::Parameter parameter { .type = parameters().first(), .name = iterable_cpp_name, .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(sequence_generator, parameter, "next_item", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("sequence_item{}", recursion_depth), interface, false, false, {}, false, recursion_depth);
generate_to_cpp(sequence_generator, parameter, "next_item", ByteString::number(recursion_depth), ByteString::formatted("sequence_item{}", recursion_depth), interface, false, false, {}, false, recursion_depth);
sequence_generator.append(R"~~~(
@cpp_name@.append(sequence_item@recursion_depth@);
@ -1571,13 +1571,13 @@ enum class WrappingReference {
Yes,
};
static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString const& value, IDL::Type const& type, IDL::Interface const& interface, StringView result_expression, WrappingReference wrapping_reference = WrappingReference::No, size_t recursion_depth = 0)
static void generate_wrap_statement(SourceGenerator& generator, ByteString const& value, IDL::Type const& type, IDL::Interface const& interface, StringView result_expression, WrappingReference wrapping_reference = WrappingReference::No, size_t recursion_depth = 0)
{
auto scoped_generator = generator.fork();
scoped_generator.set("value", value);
if (!libweb_interface_namespaces.span().contains_slow(type.name())) {
if (is_javascript_builtin(type))
scoped_generator.set("type", DeprecatedString::formatted("JS::{}", type.name()));
scoped_generator.set("type", ByteString::formatted("JS::{}", type.name()));
else
scoped_generator.set("type", type.name());
} else {
@ -1586,10 +1586,10 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
builder.append(type.name());
builder.append("::"sv);
builder.append(type.name());
scoped_generator.set("type", builder.to_deprecated_string());
scoped_generator.set("type", builder.to_byte_string());
}
scoped_generator.set("result_expression", result_expression);
scoped_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
scoped_generator.set("recursion_depth", ByteString::number(recursion_depth));
if (type.name() == "undefined") {
scoped_generator.append(R"~~~(
@ -1665,7 +1665,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
auto* wrapped_element@recursion_depth@ = &(*element@recursion_depth@);
)~~~");
} else {
generate_wrap_statement(scoped_generator, DeprecatedString::formatted("element{}", recursion_depth), sequence_generic_type.parameters().first(), interface, DeprecatedString::formatted("auto wrapped_element{} =", recursion_depth), WrappingReference::Yes, recursion_depth + 1);
generate_wrap_statement(scoped_generator, ByteString::formatted("element{}", recursion_depth), sequence_generic_type.parameters().first(), interface, ByteString::formatted("auto wrapped_element{} =", recursion_depth), WrappingReference::Yes, recursion_depth + 1);
}
scoped_generator.append(R"~~~(
@ -1730,7 +1730,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
)~~~");
// NOTE: While we are using const&, the underlying type for wrappable types in unions is (Nonnull)RefPtr, which are not references.
generate_wrap_statement(union_generator, DeprecatedString::formatted("visited_union_value{}", recursion_depth), current_union_type, interface, "return"sv, WrappingReference::No, recursion_depth + 1);
generate_wrap_statement(union_generator, ByteString::formatted("visited_union_value{}", recursion_depth), current_union_type, interface, "return"sv, WrappingReference::No, recursion_depth + 1);
// End of current visit lambda.
// The last lambda cannot have a trailing comma on the closing brace, unless the type is nullable, where an extra lambda will be generated for the Empty case.
@ -1760,7 +1760,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
} else if (interface.enumerations.contains(type.name())) {
// Handle Enum? values, which were null-checked above
if (type.is_nullable())
scoped_generator.set("value", DeprecatedString::formatted("{}.value()", value));
scoped_generator.set("value", ByteString::formatted("{}.value()", value));
scoped_generator.append(R"~~~(
@result_expression@ JS::PrimitiveString::create(vm, Bindings::idl_enum_to_string(@value@));
)~~~");
@ -1796,18 +1796,18 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
while (true) {
for (auto& member : current_dictionary->members) {
dictionary_generator.set("member_key", member.name);
auto member_key_js_name = DeprecatedString::formatted("{}{}", make_input_acceptable_cpp(member.name.to_snakecase()), recursion_depth);
auto member_key_js_name = ByteString::formatted("{}{}", make_input_acceptable_cpp(member.name.to_snakecase()), recursion_depth);
dictionary_generator.set("member_name", member_key_js_name);
auto member_value_js_name = DeprecatedString::formatted("{}_value", member_key_js_name);
auto member_value_js_name = ByteString::formatted("{}_value", member_key_js_name);
dictionary_generator.set("member_value", member_value_js_name);
auto wrapped_value_name = DeprecatedString::formatted("wrapped_{}", member_value_js_name);
auto wrapped_value_name = ByteString::formatted("wrapped_{}", member_value_js_name);
dictionary_generator.set("wrapped_value_name", wrapped_value_name);
dictionary_generator.append(R"~~~(
JS::Value @wrapped_value_name@;
)~~~");
generate_wrap_statement(dictionary_generator, DeprecatedString::formatted("{}.{}", value, member.name.to_snakecase()), member.type, interface, DeprecatedString::formatted("{} =", wrapped_value_name), WrappingReference::No, recursion_depth + 1);
generate_wrap_statement(dictionary_generator, ByteString::formatted("{}.{}", value, member.name.to_snakecase()), member.type, interface, ByteString::formatted("{} =", wrapped_value_name), WrappingReference::No, recursion_depth + 1);
dictionary_generator.append(R"~~~(
MUST(dictionary_object@recursion_depth@->create_data_property("@member_key@", @wrapped_value_name@));
@ -1856,23 +1856,23 @@ static void generate_return_statement(SourceGenerator& generator, IDL::Type cons
return generate_wrap_statement(generator, "retval", return_type, interface, "return"sv);
}
static void generate_variable_statement(SourceGenerator& generator, DeprecatedString const& variable_name, IDL::Type const& value_type, DeprecatedString const& value_name, IDL::Interface const& interface)
static void generate_variable_statement(SourceGenerator& generator, ByteString const& variable_name, IDL::Type const& value_type, ByteString const& value_name, IDL::Interface const& interface)
{
auto variable_generator = generator.fork();
variable_generator.set("variable_name", variable_name);
variable_generator.append(R"~~~(
JS::Value @variable_name@;
)~~~");
return generate_wrap_statement(generator, value_name, value_type, interface, DeprecatedString::formatted("{} = ", variable_name));
return generate_wrap_statement(generator, value_name, value_type, interface, ByteString::formatted("{} = ", variable_name));
}
static void generate_function(SourceGenerator& generator, IDL::Function const& function, StaticFunction is_static_function, DeprecatedString const& class_name, DeprecatedString const& interface_fully_qualified_name, IDL::Interface const& interface)
static void generate_function(SourceGenerator& generator, IDL::Function const& function, StaticFunction is_static_function, ByteString const& class_name, ByteString const& interface_fully_qualified_name, IDL::Interface const& interface)
{
auto function_generator = generator.fork();
function_generator.set("class_name", class_name);
function_generator.set("interface_fully_qualified_name", interface_fully_qualified_name);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(function.name.to_snakecase()));
function_generator.set("overload_suffix", function.is_overloaded ? DeprecatedString::number(function.overload_index) : DeprecatedString::empty());
function_generator.set("overload_suffix", function.is_overloaded ? ByteString::number(function.overload_index) : ByteString::empty());
if (function.extended_attributes.contains("ImplementedAs")) {
auto implemented_as = function.extended_attributes.get("ImplementedAs").value();
@ -1941,7 +1941,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@@overload_suffi
if (arguments_builder.is_empty())
function_generator.set(".arguments", "vm");
else
function_generator.set(".arguments", DeprecatedString::formatted("vm, {}", arguments_builder.string_view()));
function_generator.set(".arguments", ByteString::formatted("vm, {}", arguments_builder.string_view()));
function_generator.append(R"~~~(
[[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return @interface_fully_qualified_name@::@function.cpp_name@(@.arguments@); }));
@ -2082,7 +2082,7 @@ static Vector<EffectiveOverloadSet::Item> compute_the_effective_overload_set(aut
return overloads;
}
static DeprecatedString generate_constructor_for_idl_type(Type const& type)
static ByteString generate_constructor_for_idl_type(Type const& type)
{
auto append_type_list = [](auto& builder, auto const& type_list) {
bool first = true;
@ -2099,14 +2099,14 @@ static DeprecatedString generate_constructor_for_idl_type(Type const& type)
switch (type.kind()) {
case Type::Kind::Plain:
return DeprecatedString::formatted("make_ref_counted<IDL::Type>(\"{}\", {})", type.name(), type.is_nullable());
return ByteString::formatted("make_ref_counted<IDL::Type>(\"{}\", {})", type.name(), type.is_nullable());
case Type::Kind::Parameterized: {
auto const& parameterized_type = type.as_parameterized();
StringBuilder builder;
builder.appendff("make_ref_counted<IDL::ParameterizedType>(\"{}\", {}, Vector<NonnullRefPtr<IDL::Type const>> {{", type.name(), type.is_nullable());
append_type_list(builder, parameterized_type.parameters());
builder.append("})"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
case Type::Kind::Union: {
auto const& union_type = type.as_union();
@ -2114,7 +2114,7 @@ static DeprecatedString generate_constructor_for_idl_type(Type const& type)
builder.appendff("make_ref_counted<IDL::UnionType>(\"{}\", {}, Vector<NonnullRefPtr<IDL::Type const>> {{", type.name(), type.is_nullable());
append_type_list(builder, union_type.member_types());
builder.append("})"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
}
@ -2145,7 +2145,7 @@ static size_t resolve_distinguishing_argument_index(Interface const& interface,
VERIFY_NOT_REACHED();
}
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, IDL::Interface const& interface, DeprecatedString const& class_name)
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, IDL::Interface const& interface, ByteString const& class_name)
{
auto function_generator = generator.fork();
function_generator.set("class_name", class_name);
@ -2161,7 +2161,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
auto maximum_argument_count = 0u;
for (auto const& overload : overloads_set)
maximum_argument_count = max(maximum_argument_count, overload.types.size());
function_generator.set("max_argument_count", DeprecatedString::number(maximum_argument_count));
function_generator.set("max_argument_count", ByteString::number(maximum_argument_count));
function_generator.appendln(" switch (min(@max_argument_count@, vm.argument_count())) {");
// Generate the effective overload set for each argument count.
@ -2182,8 +2182,8 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
if (effective_overload_set.size() > 1)
distinguishing_argument_index = resolve_distinguishing_argument_index(interface, effective_overload_set, argument_count);
function_generator.set("current_argument_count", DeprecatedString::number(argument_count));
function_generator.set("overload_count", DeprecatedString::number(effective_overload_set.size()));
function_generator.set("current_argument_count", ByteString::number(argument_count));
function_generator.set("overload_count", ByteString::number(effective_overload_set.size()));
function_generator.appendln(R"~~~(
case @current_argument_count@: {
Vector<IDL::EffectiveOverloadSet::Item> overloads;
@ -2221,14 +2221,14 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
types_builder.append("}"sv);
optionality_builder.append("}"sv);
function_generator.set("overload.callable_id", DeprecatedString::number(overload.callable_id));
function_generator.set("overload.types", types_builder.to_deprecated_string());
function_generator.set("overload.optionality_values", optionality_builder.to_deprecated_string());
function_generator.set("overload.callable_id", ByteString::number(overload.callable_id));
function_generator.set("overload.types", types_builder.to_byte_string());
function_generator.set("overload.optionality_values", optionality_builder.to_byte_string());
function_generator.appendln(" overloads.empend(@overload.callable_id@, @overload.types@, @overload.optionality_values@);");
}
function_generator.set("overload_set.distinguishing_argument_index", DeprecatedString::number(distinguishing_argument_index));
function_generator.set("overload_set.distinguishing_argument_index", ByteString::number(distinguishing_argument_index));
function_generator.append(R"~~~(
effective_overload_set.emplace(move(overloads), @overload_set.distinguishing_argument_index@);
break;
@ -2247,7 +2247,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
)~~~");
for (auto i = 0u; i < overload_set.value.size(); ++i) {
function_generator.set("overload_id", DeprecatedString::number(i));
function_generator.set("overload_id", ByteString::number(i));
function_generator.append(R"~~~(
case @overload_id@:
return @function.name:snakecase@@overload_id@(vm);
@ -2274,7 +2274,7 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const
)~~~");
if (overload_set.value.size() > 1) {
for (auto i = 0u; i < overload_set.value.size(); ++i) {
function_generator.set("overload_suffix", DeprecatedString::number(i));
function_generator.set("overload_suffix", ByteString::number(i));
function_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
)~~~");
@ -2420,7 +2420,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
continue;
auto attribute_generator = function_generator.fork();
auto return_value_name = DeprecatedString::formatted("{}_retval", attribute.name.to_snakecase());
auto return_value_name = ByteString::formatted("{}_retval", attribute.name.to_snakecase());
attribute_generator.set("attribute.name", attribute.name);
attribute_generator.set("attribute.return_value_name", return_value_name);
@ -2466,7 +2466,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
)~~~");
}
generate_wrap_statement(attribute_generator, return_value_name, attribute.type, interface_in_chain, DeprecatedString::formatted("auto {}_wrapped =", return_value_name));
generate_wrap_statement(attribute_generator, return_value_name, attribute.type, interface_in_chain, ByteString::formatted("auto {}_wrapped =", return_value_name));
attribute_generator.append(R"~~~(
MUST(result->create_data_property("@attribute.name@", @attribute.return_value_name@_wrapped));
@ -2477,7 +2477,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
auto constant_generator = function_generator.fork();
constant_generator.set("constant.name", constant.name);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface_in_chain, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
generate_wrap_statement(constant_generator, constant.value, constant.type, interface_in_chain, ByteString::formatted("auto constant_{}_value =", constant.name));
constant_generator.append(R"~~~(
MUST(result->create_data_property("@constant.name@", constant_@constant.name@_value));
@ -2487,7 +2487,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
}
// https://webidl.spec.whatwg.org/#default-tojson-steps
static void generate_default_to_json_function(SourceGenerator& generator, DeprecatedString const& class_name, IDL::Interface const& start_interface)
static void generate_default_to_json_function(SourceGenerator& generator, ByteString const& class_name, IDL::Interface const& start_interface)
{
// NOTE: This is done heavily out of order since the spec mixes parse time and run time type information together.
@ -2526,7 +2526,7 @@ static void generate_named_properties_object_declarations(IDL::Interface const&
{
SourceGenerator generator { builder };
generator.set("named_properties_class", DeprecatedString::formatted("{}Properties", interface.name));
generator.set("named_properties_class", ByteString::formatted("{}Properties", interface.name));
generator.append(R"~~~(
class @named_properties_class@ : public JS::Object {
@ -2557,7 +2557,7 @@ static void generate_named_properties_object_definitions(IDL::Interface const& i
generator.set("name", interface.name);
generator.set("parent_name", interface.parent_name);
generator.set("prototype_base_class", interface.prototype_base_class);
generator.set("named_properties_class", DeprecatedString::formatted("{}Properties", interface.name));
generator.set("named_properties_class", ByteString::formatted("{}Properties", interface.name));
// https://webidl.spec.whatwg.org/#create-a-named-properties-object
generator.append(R"~~~(
@ -2701,11 +2701,11 @@ static void generate_prototype_or_global_mixin_definitions(IDL::Interface const&
generator.set("prototype_name", interface.prototype_class); // Used for Global Mixin
if (interface.pair_iterator_types.has_value()) {
generator.set("iterator_name", DeprecatedString::formatted("{}Iterator", interface.name));
generator.set("iterator_name", ByteString::formatted("{}Iterator", interface.name));
}
if (is_global_interface) {
generator.set("named_properties_class", DeprecatedString::formatted("{}Properties", interface.name));
generator.set("named_properties_class", ByteString::formatted("{}Properties", interface.name));
// Doing this with macros is not super nice, but simplifies codegen a lot.
generator.append(R"~~~(
#define define_direct_property (object.define_direct_property)
@ -2785,7 +2785,7 @@ void @class_name@::initialize(JS::Realm& realm)
auto constant_generator = generator.fork();
constant_generator.set("constant.name", constant.name);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, ByteString::formatted("auto constant_{}_value =", constant.name));
constant_generator.append(R"~~~(
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
@ -2797,7 +2797,7 @@ void @class_name@::initialize(JS::Realm& realm)
auto function_generator = generator.fork();
function_generator.set("function.name", overload_set.key);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
function_generator.set("function.length", ByteString::number(get_shortest_function_length(overload_set.value)));
// FIXME: What if only some of the overloads are Unscopable?
if (any_of(overload_set.value, [](auto const& function) { return function.extended_attributes.contains("Unscopable"); })) {
@ -3351,7 +3351,7 @@ private:
)~~~");
if (overload_set.value.size() > 1) {
for (auto i = 0u; i < overload_set.value.size(); ++i) {
function_generator.set("overload_suffix", DeprecatedString::number(i));
function_generator.set("overload_suffix", ByteString::number(i));
function_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
)~~~");
@ -3451,7 +3451,7 @@ void @namespace_class@::initialize(JS::Realm& realm)
auto function_generator = generator.fork();
function_generator.set("function.name", overload_set.key);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
function_generator.set("function.length", ByteString::number(get_shortest_function_length(overload_set.value)));
function_generator.append(R"~~~(
define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, default_attributes);
@ -3521,7 +3521,7 @@ private:
)~~~");
if (overload_set.value.size() > 1) {
for (auto i = 0u; i < overload_set.value.size(); ++i) {
function_generator.set("overload_suffix", DeprecatedString::number(i));
function_generator.set("overload_suffix", ByteString::number(i));
function_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
)~~~");
@ -3694,7 +3694,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> @constructor_class@::constru
}
}
generator.set("constructor.length", DeprecatedString::number(shortest_length));
generator.set("constructor.length", ByteString::number(shortest_length));
generator.append(R"~~~(
auto& vm = this->vm();
@ -3778,7 +3778,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> @constructor_class@::constru
generator.set(".arg_count_suffix", "");
} else {
generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountMany");
generator.set(".arg_count_suffix", DeprecatedString::formatted(", \"{}\"", shortest_length));
generator.set(".arg_count_suffix", ByteString::formatted(", \"{}\"", shortest_length));
}
generator.append(R"~~~(
@ -3943,7 +3943,7 @@ void @constructor_class@::initialize(JS::Realm& realm)
auto constant_generator = generator.fork();
constant_generator.set("constant.name", constant.name);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, ByteString::formatted("auto constant_{}_value =", constant.name));
constant_generator.append(R"~~~(
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
@ -3955,7 +3955,7 @@ void @constructor_class@::initialize(JS::Realm& realm)
auto function_generator = generator.fork();
function_generator.set("function.name", overload_set.key);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
function_generator.set("function.length", ByteString::number(get_shortest_function_length(overload_set.value)));
function_generator.append(R"~~~(
define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, default_attributes);
@ -4172,7 +4172,7 @@ void @prototype_class@::initialize(JS::Realm& realm)
Base::initialize(realm);
)~~~");
if (interface.supports_named_properties()) {
generator.set("named_properties_class", DeprecatedString::formatted("{}Properties", interface.name));
generator.set("named_properties_class", ByteString::formatted("{}Properties", interface.name));
generator.set("namespaced_name", interface.namespaced_name);
generator.append(R"~~~(
define_direct_property(vm().well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm(), "@namespaced_name@"_string), JS::Attribute::Configurable);
@ -4198,7 +4198,7 @@ void generate_iterator_prototype_header(IDL::Interface const& interface, StringB
VERIFY(interface.pair_iterator_types.has_value());
SourceGenerator generator { builder };
generator.set("prototype_class", DeprecatedString::formatted("{}IteratorPrototype", interface.name));
generator.set("prototype_class", ByteString::formatted("{}IteratorPrototype", interface.name));
generator.append(R"~~~(
#pragma once
@ -4228,12 +4228,12 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface,
VERIFY(interface.pair_iterator_types.has_value());
SourceGenerator generator { builder };
generator.set("name", DeprecatedString::formatted("{}Iterator", interface.name));
generator.set("name", ByteString::formatted("{}Iterator", interface.name));
generator.set("parent_name", interface.parent_name);
generator.set("prototype_class", DeprecatedString::formatted("{}IteratorPrototype", interface.name));
generator.set("prototype_class", ByteString::formatted("{}IteratorPrototype", interface.name));
generator.set("prototype_base_class", interface.prototype_base_class);
generator.set("fully_qualified_name", DeprecatedString::formatted("{}Iterator", interface.fully_qualified_name));
generator.set("possible_include_path", DeprecatedString::formatted("{}Iterator", interface.name.replace("::"sv, "/"sv, ReplaceMode::All)));
generator.set("fully_qualified_name", ByteString::formatted("{}Iterator", interface.fully_qualified_name));
generator.set("possible_include_path", ByteString::formatted("{}Iterator", interface.name.replace("::"sv, "/"sv, ReplaceMode::All)));
generator.append(R"~~~(
#include <AK/Function.h>

View file

@ -78,7 +78,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
builder.append(namespace_);
builder.append("::"sv);
builder.append(interface.name);
interface.fully_qualified_name = builder.to_deprecated_string();
interface.fully_qualified_name = builder.to_byte_string();
} else {
interface.fully_qualified_name = interface.name;
}

View file

@ -56,8 +56,8 @@ namespace Web::ARIA {
JsonObject const& value_object = value.as_object();
auto class_definition_generator = generator.fork();
class_definition_generator.set("spec_link"sv, value_object.get_deprecated_string("specLink"sv).value());
class_definition_generator.set("description"sv, value_object.get_deprecated_string("description"sv).value());
class_definition_generator.set("spec_link"sv, value_object.get_byte_string("specLink"sv).value());
class_definition_generator.set("description"sv, value_object.get_byte_string("description"sv).value());
class_definition_generator.set("name"sv, name);
class_definition_generator.append(R"~~~(
// @spec_link@

View file

@ -77,7 +77,7 @@ enum class ValueID;
enum_generator.appendln("enum class @name:titlecase@ : @enum_type@ {");
for (auto& member : members.values()) {
auto member_name = member.to_deprecated_string();
auto member_name = member.to_byte_string();
// Don't include aliases in the enum.
if (member_name.contains('='))
continue;
@ -126,7 +126,7 @@ Optional<@name:titlecase@> value_id_to_@name:snakecase@(ValueID value_id)
for (auto& member : members.values()) {
auto member_generator = enum_generator.fork();
auto member_name = member.to_deprecated_string();
auto member_name = member.to_byte_string();
if (member_name.contains('=')) {
auto parts = member_name.split_view('=');
member_generator.set("valueid:titlecase", title_casify(parts[0]));
@ -154,7 +154,7 @@ ValueID to_value_id(@name:titlecase@ @name:snakecase@_value)
for (auto& member : members.values()) {
auto member_generator = enum_generator.fork();
auto member_name = member.to_deprecated_string();
auto member_name = member.to_byte_string();
if (member_name.contains('='))
continue;
member_generator.set("member:titlecase", title_casify(member_name));
@ -178,7 +178,7 @@ StringView to_string(@name:titlecase@ value)
for (auto& member : members.values()) {
auto member_generator = enum_generator.fork();
auto member_name = member.to_deprecated_string();
auto member_name = member.to_byte_string();
if (member_name.contains('='))
continue;
member_generator.set("member:css", member_name);

View file

@ -182,7 +182,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
// Generate some type checks
VERIFY(parameters.size() == 1);
auto& parameter_data = parameters[0].as_object();
auto parameter_type_string = parameter_data.get_deprecated_string("type"sv).value();
auto parameter_type_string = parameter_data.get_byte_string("type"sv).value();
function_generator.set("type_check", generate_calculation_type_check("argument_type"sv, parameter_type_string));
function_generator.append(R"~~~(
if (!(@type_check@)) {
@ -231,11 +231,11 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
StringView previous_parameter_type_string;
parameters.for_each([&](JsonValue const& parameter_value) {
auto& parameter = parameter_value.as_object();
auto parameter_type_string = parameter.get_deprecated_string("type"sv).value();
auto parameter_type_string = parameter.get_byte_string("type"sv).value();
auto parameter_required = parameter.get_bool("required"sv).value();
auto parameter_generator = function_generator.fork();
parameter_generator.set("parameter_name", parameter.get_deprecated_string("name"sv).value());
parameter_generator.set("parameter_name", parameter.get_byte_string("name"sv).value());
parameter_generator.set("parameter_index", MUST(String::number(parameter_index)));
bool parameter_is_calculation;
@ -245,7 +245,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
parameter_generator.set("parse_function", "parse_rounding_strategy(arguments[argument_index])"_string);
parameter_generator.set("check_function", ".has_value()"_string);
parameter_generator.set("release_function", ".release_value()"_string);
if (auto default_value = parameter.get_deprecated_string("default"sv); default_value.has_value()) {
if (auto default_value = parameter.get_byte_string("default"sv); default_value.has_value()) {
parameter_generator.set("parameter_default", MUST(String::formatted(" = RoundingStrategy::{}", title_casify(default_value.value()))));
} else {
parameter_generator.set("parameter_default", ""_string);
@ -260,7 +260,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
// NOTE: We have exactly one default value in the data right now, and it's a `<calc-constant>`,
// so that's all we handle.
if (auto default_value = parameter.get_deprecated_string("default"sv); default_value.has_value()) {
if (auto default_value = parameter.get_byte_string("default"sv); default_value.has_value()) {
parameter_generator.set("parameter_default", MUST(String::formatted(" = ConstantCalculationNode::create(CalculationNode::constant_type_from_string(\"{}\"sv).value())", default_value.value())));
} else {
parameter_generator.set("parameter_default", ""_string);
@ -343,7 +343,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
parameter_index = 0;
parameters.for_each([&](JsonValue const& parameter_value) {
auto& parameter = parameter_value.as_object();
auto parameter_type_string = parameter.get_deprecated_string("type"sv).value();
auto parameter_type_string = parameter.get_byte_string("type"sv).value();
auto parameter_generator = function_generator.fork();
parameter_generator.set("parameter_index"sv, MUST(String::number(parameter_index)));

View file

@ -140,7 +140,7 @@ bool media_feature_type_is_range(MediaFeatureID media_feature_id)
auto member_generator = generator.fork();
member_generator.set("name:titlecase", title_casify(name));
VERIFY(feature.has("type"sv));
auto feature_type = feature.get_deprecated_string("type"sv);
auto feature_type = feature.get_byte_string("type"sv);
VERIFY(feature_type.has_value());
member_generator.set("is_range", feature_type.value() == "range" ? "true"_string : "false"_string);
member_generator.append(R"~~~(

View file

@ -43,7 +43,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto properties = json.as_object();
// Check we're in alphabetical order
DeprecatedString most_recent_name = "";
ByteString most_recent_name = "";
properties.for_each_member([&](auto& name, auto&) {
if (name < most_recent_name) {
warnln("`{}` is in the wrong position in `{}`. Please keep this list alphabetical!", name, properties_json_path);
@ -65,7 +65,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
void replace_logical_aliases(JsonObject& properties)
{
AK::HashMap<DeprecatedString, DeprecatedString> logical_aliases;
AK::HashMap<ByteString, ByteString> logical_aliases;
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
const auto& value_as_object = value.as_object();
@ -73,7 +73,7 @@ void replace_logical_aliases(JsonObject& properties)
if (logical_alias_for.has_value()) {
auto const& aliased_properties = logical_alias_for.value();
for (auto const& aliased_property : aliased_properties.values()) {
logical_aliases.set(name, aliased_property.to_deprecated_string());
logical_aliases.set(name, aliased_property.to_byte_string());
}
}
});
@ -116,8 +116,8 @@ enum class PropertyID {
All,
)~~~");
Vector<DeprecatedString> shorthand_property_ids;
Vector<DeprecatedString> longhand_property_ids;
Vector<ByteString> shorthand_property_ids;
Vector<ByteString> longhand_property_ids;
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
@ -518,7 +518,7 @@ NonnullRefPtr<StyleValue> property_initial_value(JS::Realm& context_realm, Prope
dbgln("No initial value specified for property '{}'", name);
VERIFY_NOT_REACHED();
}
auto initial_value = object.get_deprecated_string("initial"sv);
auto initial_value = object.get_byte_string("initial"sv);
VERIFY(initial_value.has_value());
auto& initial_value_string = initial_value.value();
@ -739,7 +739,7 @@ Optional<ValueType> property_resolves_percentages_relative_to(PropertyID propert
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
if (auto resolved_type = value.as_object().get_deprecated_string("percentages-resolve-to"sv); resolved_type.has_value()) {
if (auto resolved_type = value.as_object().get_byte_string("percentages-resolve-to"sv); resolved_type.has_value()) {
auto property_generator = generator.fork();
property_generator.set("name:titlecase", title_casify(name));
property_generator.set("resolved_type:titlecase", title_casify(resolved_type.value()));
@ -768,7 +768,7 @@ size_t property_maximum_value_count(PropertyID property_id)
VERIFY(max_values.has_value() && max_values->is_number() && !max_values->is_double());
auto property_generator = generator.fork();
property_generator.set("name:titlecase", title_casify(name));
property_generator.set("max_values", max_values->to_deprecated_string());
property_generator.set("max_values", max_values->to_byte_string());
property_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
return @max_values@;
@ -834,10 +834,10 @@ Vector<PropertyID> longhands_for_shorthand(PropertyID property_id)
first = false;
else
builder.append(", "sv);
builder.appendff("PropertyID::{}", title_casify(longhand.to_deprecated_string()));
builder.appendff("PropertyID::{}", title_casify(longhand.to_byte_string()));
return IterationDecision::Continue;
});
property_generator.set("longhands", builder.to_deprecated_string());
property_generator.set("longhands", builder.to_byte_string());
property_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
return { @longhands@ };

View file

@ -147,7 +147,7 @@ PseudoClassMetadata pseudo_class_metadata(PseudoClass pseudo_class)
pseudo_classes_data.for_each_member([&](auto& name, JsonValue const& value) {
auto member_generator = generator.fork();
auto& pseudo_class = value.as_object();
auto argument_string = pseudo_class.get_deprecated_string("argument"sv).value();
auto argument_string = pseudo_class.get_byte_string("argument"sv).value();
bool is_valid_as_identifier = argument_string.is_empty();
bool is_valid_as_function = !argument_string.is_empty();

View file

@ -169,7 +169,7 @@ TransformFunctionMetadata transform_function_metadata(TransformFunction transfor
JsonArray const& parameters = value.as_object().get_array("parameters"sv).value();
bool first = true;
parameters.for_each([&](JsonValue const& value) {
GenericLexer lexer { value.as_object().get_deprecated_string("type"sv).value() };
GenericLexer lexer { value.as_object().get_byte_string("type"sv).value() };
VERIFY(lexer.consume_specific('<'));
auto parameter_type_name = lexer.consume_until('>');
VERIFY(lexer.consume_specific('>'));
@ -189,7 +189,7 @@ TransformFunctionMetadata transform_function_metadata(TransformFunction transfor
member_generator.append(first ? " "sv : ", "sv);
first = false;
member_generator.append(MUST(String::formatted("{{ TransformFunctionParameterType::{}, {}}}", parameter_type, value.as_object().get("required"sv)->to_deprecated_string())));
member_generator.append(MUST(String::formatted("{{ TransformFunctionParameterType::{}, {}}}", parameter_type, value.as_object().get("required"sv)->to_byte_string())));
});
member_generator.append(R"~~~( }

View file

@ -57,7 +57,7 @@ enum class ValueID {
identifier_data.for_each([&](auto& name) {
auto member_generator = generator.fork();
member_generator.set("name:titlecase", title_casify(name.to_deprecated_string()));
member_generator.set("name:titlecase", title_casify(name.to_byte_string()));
member_generator.append(R"~~~(
@name:titlecase@,
@ -105,8 +105,8 @@ HashMap<StringView, ValueID, AK::CaseInsensitiveASCIIStringViewTraits> g_stringv
identifier_data.for_each([&](auto& name) {
auto member_generator = generator.fork();
member_generator.set("name", name.to_deprecated_string());
member_generator.set("name:titlecase", title_casify(name.to_deprecated_string()));
member_generator.set("name", name.to_byte_string());
member_generator.set("name:titlecase", title_casify(name.to_byte_string()));
member_generator.append(R"~~~(
{"@name@"sv, ValueID::@name:titlecase@},
)~~~");
@ -126,8 +126,8 @@ StringView string_from_value_id(ValueID value_id) {
identifier_data.for_each([&](auto& name) {
auto member_generator = generator.fork();
member_generator.set("name", name.to_deprecated_string());
member_generator.set("name:titlecase", title_casify(name.to_deprecated_string()));
member_generator.set("name", name.to_byte_string());
member_generator.set("name:titlecase", title_casify(name.to_byte_string()));
member_generator.append(R"~~~(
case ValueID::@name:titlecase@:
return "@name@"sv;

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/LexicalPath.h>
#include <AK/SourceGenerator.h>
#include <AK/StringBuilder.h>
@ -15,11 +15,11 @@
#include <LibMain/Main.h>
static ErrorOr<void> add_to_interface_sets(IDL::Interface&, Vector<IDL::Interface&>& intrinsics, Vector<IDL::Interface&>& window_exposed, Vector<IDL::Interface&>& dedicated_worker_exposed, Vector<IDL::Interface&>& shared_worker_exposed);
static DeprecatedString s_error_string;
static ByteString s_error_string;
struct LegacyConstructor {
DeprecatedString name;
DeprecatedString constructor_class;
ByteString name;
ByteString constructor_class;
};
static void consume_whitespace(GenericLexer& lexer)
@ -52,7 +52,7 @@ static Optional<LegacyConstructor> const& lookup_legacy_constructor(IDL::Interfa
consume_whitespace(function_lexer);
auto name = function_lexer.consume_until([](auto ch) { return is_ascii_space(ch) || ch == '('; });
auto constructor_class = DeprecatedString::formatted("{}Constructor", name);
auto constructor_class = ByteString::formatted("{}Constructor", name);
s_legacy_constructors.set(interface.name, LegacyConstructor { name, move(constructor_class) });
return s_legacy_constructors.get(interface.name).value();
@ -264,7 +264,7 @@ static ErrorOr<void> generate_exposed_interface_header(StringView class_name, St
StringBuilder builder;
SourceGenerator generator(builder);
generator.set("global_object_snake_name", DeprecatedString(class_name).to_snakecase());
generator.set("global_object_snake_name", ByteString(class_name).to_snakecase());
generator.append(R"~~~(
#pragma once
@ -278,7 +278,7 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object&);
)~~~");
auto generated_header_path = LexicalPath(output_path).append(DeprecatedString::formatted("{}ExposedInterfaces.h", class_name)).string();
auto generated_header_path = LexicalPath(output_path).append(ByteString::formatted("{}ExposedInterfaces.h", class_name)).string();
auto generated_header_file = TRY(Core::File::open(generated_header_path, Core::File::OpenMode::Write));
TRY(generated_header_file->write_until_depleted(generator.as_string_view().bytes()));
@ -291,7 +291,7 @@ static ErrorOr<void> generate_exposed_interface_implementation(StringView class_
SourceGenerator generator(builder);
generator.set("global_object_name", class_name);
generator.set("global_object_snake_name", DeprecatedString(class_name).to_snakecase());
generator.set("global_object_snake_name", ByteString(class_name).to_snakecase());
generator.append(R"~~~(
#include <LibJS/Runtime/Object.h>
@ -366,7 +366,7 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object& global)
}
)~~~");
auto generated_implementation_path = LexicalPath(output_path).append(DeprecatedString::formatted("{}ExposedInterfaces.cpp", class_name)).string();
auto generated_implementation_path = LexicalPath(output_path).append(ByteString::formatted("{}ExposedInterfaces.cpp", class_name)).string();
auto generated_implementation_file = TRY(Core::File::open(generated_implementation_path, Core::File::OpenMode::Write));
TRY(generated_implementation_file->write_until_depleted(generator.as_string_view().bytes()));
@ -379,7 +379,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
StringView output_path;
StringView base_path;
Vector<DeprecatedString> paths;
Vector<ByteString> paths;
args_parser.add_option(output_path, "Path to output generated files into", "output-path", 'o', "output-path");
args_parser.add_option(base_path, "Path to root of IDL file tree", "base-path", 'b', "base-path");
@ -392,16 +392,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
const LexicalPath lexical_base(base_path);
// Read in all IDL files, we must own the storage for all of these for the lifetime of the program
Vector<DeprecatedString> file_contents;
for (DeprecatedString const& path : paths) {
Vector<ByteString> file_contents;
for (ByteString const& path : paths) {
auto file_or_error = Core::File::open(path, Core::File::OpenMode::Read);
if (file_or_error.is_error()) {
s_error_string = DeprecatedString::formatted("Unable to open file {}", path);
s_error_string = ByteString::formatted("Unable to open file {}", path);
return Error::from_string_view(s_error_string.view());
}
auto file = file_or_error.release_value();
auto string = MUST(file->read_until_eof());
file_contents.append(DeprecatedString(ReadonlyBytes(string)));
file_contents.append(ByteString(ReadonlyBytes(string)));
}
VERIFY(paths.size() == file_contents.size());
@ -453,7 +453,7 @@ static ErrorOr<ExposedTo> parse_exposure_set(IDL::Interface& interface)
auto maybe_exposed = interface.extended_attributes.get("Exposed");
if (!maybe_exposed.has_value()) {
s_error_string = DeprecatedString::formatted("Interface {} is missing extended attribute Exposed", interface.name);
s_error_string = ByteString::formatted("Interface {} is missing extended attribute Exposed", interface.name);
return Error::from_string_view(s_error_string.view());
}
auto exposed = maybe_exposed.value().trim_whitespace();
@ -485,18 +485,18 @@ static ErrorOr<ExposedTo> parse_exposure_set(IDL::Interface& interface)
} else if (candidate == "AudioWorklet"sv) {
whom |= ExposedTo::AudioWorklet;
} else {
s_error_string = DeprecatedString::formatted("Unknown Exposed attribute candidate {} in {} in {}", candidate, exposed, interface.name);
s_error_string = ByteString::formatted("Unknown Exposed attribute candidate {} in {} in {}", candidate, exposed, interface.name);
return Error::from_string_view(s_error_string.view());
}
}
if (whom == ExposedTo::Nobody) {
s_error_string = DeprecatedString::formatted("Unknown Exposed attribute {} in {}", exposed, interface.name);
s_error_string = ByteString::formatted("Unknown Exposed attribute {} in {}", exposed, interface.name);
return Error::from_string_view(s_error_string.view());
}
return whom;
}
s_error_string = DeprecatedString::formatted("Unknown Exposed attribute {} in {}", exposed, interface.name);
s_error_string = ByteString::formatted("Unknown Exposed attribute {} in {}", exposed, interface.name);
return Error::from_string_view(s_error_string.view());
}

View file

@ -52,7 +52,7 @@ String camel_casify(StringView dashy_name)
String snake_casify(StringView dashy_name)
{
// FIXME: We don't really need to convert dashy_name to a String first, but currently
// all the `replace` functions that take a StringView return DeprecatedString.
// all the `replace` functions that take a StringView return ByteString.
return MUST(MUST(String::from_utf8(dashy_name)).replace("-"sv, "_"sv, ReplaceMode::All));
}

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/GenericLexer.h>
#include <AK/HashTable.h>
#include <AK/OwnPtr.h>
@ -22,8 +22,8 @@ struct Range {
};
struct StateTransition {
Optional<DeprecatedString> new_state;
Optional<DeprecatedString> action;
Optional<ByteString> new_state;
Optional<ByteString> action;
};
struct MatchedAction {
@ -32,18 +32,18 @@ struct MatchedAction {
};
struct State {
DeprecatedString name;
ByteString name;
Vector<MatchedAction> actions;
Optional<DeprecatedString> entry_action;
Optional<DeprecatedString> exit_action;
Optional<ByteString> entry_action;
Optional<ByteString> exit_action;
};
struct StateMachine {
DeprecatedString name;
DeprecatedString initial_state;
ByteString name;
ByteString initial_state;
Vector<State> states;
Optional<State> anywhere;
Optional<DeprecatedString> namespaces;
Optional<ByteString> namespaces;
};
static OwnPtr<StateMachine>
@ -159,7 +159,7 @@ parse_state_machine(StringView input)
consume_whitespace();
state.exit_action = consume_identifier();
} else if (lexer.next_is('@')) {
auto directive = consume_identifier().to_deprecated_string();
auto directive = consume_identifier().to_byte_string();
fprintf(stderr, "Unimplemented @ directive %s\n", directive.characters());
exit(1);
} else {
@ -189,7 +189,7 @@ parse_state_machine(StringView input)
lexer.consume_specific('@');
state_machine->anywhere = consume_state_description();
} else if (lexer.consume_specific('@')) {
auto directive = consume_identifier().to_deprecated_string();
auto directive = consume_identifier().to_byte_string();
fprintf(stderr, "Unimplemented @ directive %s\n", directive.characters());
exit(1);
} else {
@ -238,9 +238,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
HashTable<DeprecatedString> actions(StateMachine const& machine)
HashTable<ByteString> actions(StateMachine const& machine)
{
HashTable<DeprecatedString> table;
HashTable<ByteString> table;
auto do_state = [&](State const& state) {
if (state.entry_action.has_value())
@ -302,7 +302,7 @@ void output_header(StateMachine const& machine, SourceGenerator& generator)
{
generator.set("class_name", machine.name);
generator.set("initial_state", machine.initial_state);
generator.set("state_count", DeprecatedString::number(machine.states.size() + 1));
generator.set("state_count", ByteString::number(machine.states.size() + 1));
generator.append(R"~~~(
#pragma once