mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:57:44 +00:00
Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
This commit is contained in:
parent
e5f09ea170
commit
3f3f45580a
762 changed files with 8315 additions and 8316 deletions
|
@ -28,9 +28,9 @@ static bool is_wrappable_type(Type const& type)
|
|||
return true;
|
||||
if (type.name == "DocumentType")
|
||||
return true;
|
||||
if (type.name.ends_with("Element"))
|
||||
if (type.name.ends_with("Element"sv))
|
||||
return true;
|
||||
if (type.name.ends_with("Event"))
|
||||
if (type.name.ends_with("Event"sv))
|
||||
return true;
|
||||
if (type.name == "ImageData")
|
||||
return true;
|
||||
|
@ -155,7 +155,7 @@ static String make_input_acceptable_cpp(String const& input)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
return input.replace("-", "_", ReplaceMode::All);
|
||||
return input.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||
}
|
||||
|
||||
static void generate_include_for_wrapper(auto& generator, auto& wrapper_name)
|
||||
|
@ -239,7 +239,7 @@ static void emit_includes_for_all_imports(auto& interface, auto& generator, bool
|
|||
|
||||
if (is_iterator) {
|
||||
auto iterator_name = String::formatted("{}Iterator", interface->name);
|
||||
auto iterator_path = String::formatted("{}Iterator", interface->fully_qualified_name.replace("::", "/", ReplaceMode::All));
|
||||
auto iterator_path = String::formatted("{}Iterator", interface->fully_qualified_name.replace("::"sv, "/"sv, ReplaceMode::All));
|
||||
generate_include_for_iterator(generator, iterator_path, iterator_name);
|
||||
}
|
||||
|
||||
|
@ -263,9 +263,9 @@ static bool should_emit_wrapper_factory(IDL::Interface const& interface)
|
|||
return false;
|
||||
if (interface.name == "DocumentType")
|
||||
return false;
|
||||
if (interface.name.ends_with("Element"))
|
||||
if (interface.name.ends_with("Element"sv))
|
||||
return false;
|
||||
if (interface.name.starts_with("CSS") && interface.name.ends_with("Rule"))
|
||||
if (interface.name.starts_with("CSS"sv) && interface.name.ends_with("Rule"sv))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -580,7 +580,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", String::formatted("{}{}_string", enum_generator.get("js_name"), enum_generator.get("js_suffix")));
|
||||
enum_generator.set("js_name.as_string", String::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@ };
|
||||
)~~~");
|
||||
|
@ -1291,7 +1291,7 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
|
|||
++argument_index;
|
||||
}
|
||||
|
||||
arguments_builder.join(", ", parameter_names);
|
||||
arguments_builder.join(", "sv, parameter_names);
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#create-sequence-from-iterable
|
||||
|
@ -1674,7 +1674,7 @@ static Optional<String> generate_arguments_match_check_for_count(Vector<IDL::Par
|
|||
}
|
||||
if (conditions.is_empty())
|
||||
return {};
|
||||
return String::formatted("({})", String::join(" && ", conditions));
|
||||
return String::formatted("({})", String::join(" && "sv, conditions));
|
||||
}
|
||||
|
||||
static String generate_arguments_match_check(Function const& function)
|
||||
|
@ -1692,7 +1692,7 @@ static String generate_arguments_match_check(Function const& function)
|
|||
if (match_check.has_value())
|
||||
options.append(match_check.release_value());
|
||||
}
|
||||
return String::join(" || ", options);
|
||||
return String::join(" || "sv, options);
|
||||
}
|
||||
|
||||
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, String const& class_name)
|
||||
|
@ -3679,7 +3679,7 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface)
|
|||
generator.set("prototype_class", String::formatted("{}IteratorPrototype", interface.name));
|
||||
generator.set("wrapper_class", String::formatted("{}IteratorWrapper", interface.name));
|
||||
generator.set("fully_qualified_name", String::formatted("{}Iterator", interface.fully_qualified_name));
|
||||
generator.set("possible_include_path", String::formatted("{}Iterator", interface.name.replace("::", "/", ReplaceMode::All)));
|
||||
generator.set("possible_include_path", String::formatted("{}Iterator", interface.name.replace("::"sv, "/"sv, ReplaceMode::All)));
|
||||
|
||||
generator.append(R"~~~(
|
||||
#include <AK/Function.h>
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
error_message.appendff("{}\n", input.substring_view(start_line, line_length));
|
||||
for (size_t i = 0; i < colno - 1; ++i)
|
||||
error_message.append(' ');
|
||||
error_message.append("\033[1;31m^\n");
|
||||
error_message.append("\033[1;31m^\n"sv);
|
||||
error_message.appendff("{}:{}: error: {}\033[0m\n", filename, lineno, message);
|
||||
|
||||
warnln("{}", error_message.string_view());
|
||||
|
@ -65,7 +65,7 @@ static String convert_enumeration_value_to_cpp_enum_member(String const& value,
|
|||
}
|
||||
|
||||
if (builder.is_empty())
|
||||
builder.append("Empty");
|
||||
builder.append("Empty"sv);
|
||||
|
||||
while (names_already_seen.contains(builder.string_view()))
|
||||
builder.append('_');
|
||||
|
@ -158,7 +158,7 @@ NonnullRefPtr<Type> Parser::parse_type()
|
|||
NonnullRefPtrVector<Type> union_member_types;
|
||||
union_member_types.append(parse_type());
|
||||
consume_whitespace();
|
||||
assert_string("or");
|
||||
assert_string("or"sv);
|
||||
consume_whitespace();
|
||||
union_member_types.append(parse_type());
|
||||
consume_whitespace();
|
||||
|
@ -185,7 +185,7 @@ NonnullRefPtr<Type> Parser::parse_type()
|
|||
if (name.equals_ignoring_case("long"sv)) {
|
||||
consume_whitespace();
|
||||
if (lexer.consume_specific("long"sv))
|
||||
name = "long long";
|
||||
name = "long long"sv;
|
||||
}
|
||||
|
||||
NonnullRefPtrVector<Type> parameters;
|
||||
|
@ -202,7 +202,7 @@ NonnullRefPtr<Type> Parser::parse_type()
|
|||
auto nullable = lexer.consume_specific('?');
|
||||
StringBuilder builder;
|
||||
if (unsigned_)
|
||||
builder.append("unsigned ");
|
||||
builder.append("unsigned "sv);
|
||||
builder.append(name);
|
||||
|
||||
if (is_parameterized_type)
|
||||
|
@ -341,7 +341,7 @@ Function Parser::parse_function(HashMap<String, String>& extended_attributes, In
|
|||
|
||||
void Parser::parse_constructor(Interface& interface)
|
||||
{
|
||||
assert_string("constructor");
|
||||
assert_string("constructor"sv);
|
||||
consume_whitespace();
|
||||
assert_specific('(');
|
||||
auto parameters = parse_parameters();
|
||||
|
@ -354,10 +354,10 @@ void Parser::parse_constructor(Interface& interface)
|
|||
|
||||
void Parser::parse_stringifier(HashMap<String, String>& extended_attributes, Interface& interface)
|
||||
{
|
||||
assert_string("stringifier");
|
||||
assert_string("stringifier"sv);
|
||||
consume_whitespace();
|
||||
interface.has_stringifier = true;
|
||||
if (lexer.next_is("readonly") || lexer.next_is("attribute")) {
|
||||
if (lexer.next_is("readonly"sv) || lexer.next_is("attribute"sv)) {
|
||||
parse_attribute(extended_attributes, interface);
|
||||
interface.stringifier_attribute = interface.attributes.last().name;
|
||||
} else {
|
||||
|
@ -367,12 +367,12 @@ void Parser::parse_stringifier(HashMap<String, String>& extended_attributes, Int
|
|||
|
||||
void Parser::parse_iterable(Interface& interface)
|
||||
{
|
||||
assert_string("iterable");
|
||||
assert_string("iterable"sv);
|
||||
assert_specific('<');
|
||||
auto first_type = parse_type();
|
||||
if (lexer.next_is(',')) {
|
||||
if (interface.supports_indexed_properties())
|
||||
report_parsing_error("Interfaces with a pair iterator must not supported indexed properties.", filename, input, lexer.tell());
|
||||
report_parsing_error("Interfaces with a pair iterator must not supported indexed properties."sv, filename, input, lexer.tell());
|
||||
|
||||
assert_specific(',');
|
||||
consume_whitespace();
|
||||
|
@ -380,7 +380,7 @@ void Parser::parse_iterable(Interface& interface)
|
|||
interface.pair_iterator_types = Tuple { move(first_type), move(second_type) };
|
||||
} else {
|
||||
if (!interface.supports_indexed_properties())
|
||||
report_parsing_error("Interfaces with a value iterator must supported indexed properties.", filename, input, lexer.tell());
|
||||
report_parsing_error("Interfaces with a value iterator must supported indexed properties."sv, filename, input, lexer.tell());
|
||||
|
||||
interface.value_iterator_type = move(first_type);
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ void Parser::parse_iterable(Interface& interface)
|
|||
|
||||
void Parser::parse_getter(HashMap<String, String>& extended_attributes, Interface& interface)
|
||||
{
|
||||
assert_string("getter");
|
||||
assert_string("getter"sv);
|
||||
consume_whitespace();
|
||||
auto function = parse_function(extended_attributes, interface, IsSpecialOperation::Yes);
|
||||
|
||||
|
@ -400,21 +400,21 @@ void Parser::parse_getter(HashMap<String, String>& extended_attributes, Interfac
|
|||
auto& identifier = function.parameters.first();
|
||||
|
||||
if (identifier.type->nullable)
|
||||
report_parsing_error("identifier's type must not be nullable.", filename, input, lexer.tell());
|
||||
report_parsing_error("identifier's type must not be nullable."sv, filename, input, lexer.tell());
|
||||
|
||||
if (identifier.optional)
|
||||
report_parsing_error("identifier must not be optional.", filename, input, lexer.tell());
|
||||
report_parsing_error("identifier must not be optional."sv, filename, input, lexer.tell());
|
||||
|
||||
// FIXME: Disallow variadic functions once they're supported.
|
||||
|
||||
if (identifier.type->name == "DOMString") {
|
||||
if (interface.named_property_getter.has_value())
|
||||
report_parsing_error("An interface can only have one named property getter.", filename, input, lexer.tell());
|
||||
report_parsing_error("An interface can only have one named property getter."sv, filename, input, lexer.tell());
|
||||
|
||||
interface.named_property_getter = move(function);
|
||||
} else if (identifier.type->name == "unsigned long") {
|
||||
if (interface.indexed_property_getter.has_value())
|
||||
report_parsing_error("An interface can only have one indexed property getter.", filename, input, lexer.tell());
|
||||
report_parsing_error("An interface can only have one indexed property getter."sv, filename, input, lexer.tell());
|
||||
|
||||
interface.indexed_property_getter = move(function);
|
||||
} else {
|
||||
|
@ -424,7 +424,7 @@ void Parser::parse_getter(HashMap<String, String>& extended_attributes, Interfac
|
|||
|
||||
void Parser::parse_setter(HashMap<String, String>& extended_attributes, Interface& interface)
|
||||
{
|
||||
assert_string("setter");
|
||||
assert_string("setter"sv);
|
||||
consume_whitespace();
|
||||
auto function = parse_function(extended_attributes, interface, IsSpecialOperation::Yes);
|
||||
|
||||
|
@ -434,27 +434,27 @@ void Parser::parse_setter(HashMap<String, String>& extended_attributes, Interfac
|
|||
auto& identifier = function.parameters.first();
|
||||
|
||||
if (identifier.type->nullable)
|
||||
report_parsing_error("identifier's type must not be nullable.", filename, input, lexer.tell());
|
||||
report_parsing_error("identifier's type must not be nullable."sv, filename, input, lexer.tell());
|
||||
|
||||
if (identifier.optional)
|
||||
report_parsing_error("identifier must not be optional.", filename, input, lexer.tell());
|
||||
report_parsing_error("identifier must not be optional."sv, filename, input, lexer.tell());
|
||||
|
||||
// FIXME: Disallow variadic functions once they're supported.
|
||||
|
||||
if (identifier.type->name == "DOMString") {
|
||||
if (interface.named_property_setter.has_value())
|
||||
report_parsing_error("An interface can only have one named property setter.", filename, input, lexer.tell());
|
||||
report_parsing_error("An interface can only have one named property setter."sv, filename, input, lexer.tell());
|
||||
|
||||
if (!interface.named_property_getter.has_value())
|
||||
report_parsing_error("A named property setter must be accompanied by a named property getter.", filename, input, lexer.tell());
|
||||
report_parsing_error("A named property setter must be accompanied by a named property getter."sv, filename, input, lexer.tell());
|
||||
|
||||
interface.named_property_setter = move(function);
|
||||
} else if (identifier.type->name == "unsigned long") {
|
||||
if (interface.indexed_property_setter.has_value())
|
||||
report_parsing_error("An interface can only have one indexed property setter.", filename, input, lexer.tell());
|
||||
report_parsing_error("An interface can only have one indexed property setter."sv, filename, input, lexer.tell());
|
||||
|
||||
if (!interface.indexed_property_getter.has_value())
|
||||
report_parsing_error("An indexed property setter must be accompanied by an indexed property getter.", filename, input, lexer.tell());
|
||||
report_parsing_error("An indexed property setter must be accompanied by an indexed property getter."sv, filename, input, lexer.tell());
|
||||
|
||||
interface.indexed_property_setter = move(function);
|
||||
} else {
|
||||
|
@ -464,7 +464,7 @@ void Parser::parse_setter(HashMap<String, String>& extended_attributes, Interfac
|
|||
|
||||
void Parser::parse_deleter(HashMap<String, String>& extended_attributes, Interface& interface)
|
||||
{
|
||||
assert_string("deleter");
|
||||
assert_string("deleter"sv);
|
||||
consume_whitespace();
|
||||
auto function = parse_function(extended_attributes, interface, IsSpecialOperation::Yes);
|
||||
|
||||
|
@ -474,19 +474,19 @@ void Parser::parse_deleter(HashMap<String, String>& extended_attributes, Interfa
|
|||
auto& identifier = function.parameters.first();
|
||||
|
||||
if (identifier.type->nullable)
|
||||
report_parsing_error("identifier's type must not be nullable.", filename, input, lexer.tell());
|
||||
report_parsing_error("identifier's type must not be nullable."sv, filename, input, lexer.tell());
|
||||
|
||||
if (identifier.optional)
|
||||
report_parsing_error("identifier must not be optional.", filename, input, lexer.tell());
|
||||
report_parsing_error("identifier must not be optional."sv, filename, input, lexer.tell());
|
||||
|
||||
// FIXME: Disallow variadic functions once they're supported.
|
||||
|
||||
if (identifier.type->name == "DOMString") {
|
||||
if (interface.named_property_deleter.has_value())
|
||||
report_parsing_error("An interface can only have one named property deleter.", filename, input, lexer.tell());
|
||||
report_parsing_error("An interface can only have one named property deleter."sv, filename, input, lexer.tell());
|
||||
|
||||
if (!interface.named_property_getter.has_value())
|
||||
report_parsing_error("A named property deleter must be accompanied by a named property getter.", filename, input, lexer.tell());
|
||||
report_parsing_error("A named property deleter must be accompanied by a named property getter."sv, filename, input, lexer.tell());
|
||||
|
||||
interface.named_property_deleter = move(function);
|
||||
} else {
|
||||
|
@ -576,7 +576,7 @@ void Parser::parse_interface(Interface& interface)
|
|||
|
||||
void Parser::parse_enumeration(Interface& interface)
|
||||
{
|
||||
assert_string("enum");
|
||||
assert_string("enum"sv);
|
||||
consume_whitespace();
|
||||
|
||||
Enumeration enumeration {};
|
||||
|
@ -626,7 +626,7 @@ void Parser::parse_enumeration(Interface& interface)
|
|||
|
||||
void Parser::parse_typedef(Interface& interface)
|
||||
{
|
||||
assert_string("typedef");
|
||||
assert_string("typedef"sv);
|
||||
consume_whitespace();
|
||||
|
||||
HashMap<String, String> extended_attributes;
|
||||
|
@ -645,7 +645,7 @@ void Parser::parse_typedef(Interface& interface)
|
|||
|
||||
void Parser::parse_dictionary(Interface& interface)
|
||||
{
|
||||
assert_string("dictionary");
|
||||
assert_string("dictionary"sv);
|
||||
consume_whitespace();
|
||||
|
||||
Dictionary dictionary {};
|
||||
|
@ -723,14 +723,14 @@ void Parser::parse_interface_mixin(Interface& interface)
|
|||
mixin_interface.module_own_path = interface.module_own_path;
|
||||
mixin_interface.is_mixin = true;
|
||||
|
||||
assert_string("interface");
|
||||
assert_string("interface"sv);
|
||||
consume_whitespace();
|
||||
assert_string("mixin");
|
||||
assert_string("mixin"sv);
|
||||
auto offset = lexer.tell();
|
||||
|
||||
parse_interface(mixin_interface);
|
||||
if (!mixin_interface.parent_name.is_empty())
|
||||
report_parsing_error("Mixin interfaces are not allowed to have inherited parents", filename, input, offset);
|
||||
report_parsing_error("Mixin interfaces are not allowed to have inherited parents"sv, filename, input, offset);
|
||||
|
||||
auto name = mixin_interface.name;
|
||||
interface.mixins.set(move(name), &mixin_interface);
|
||||
|
@ -738,7 +738,7 @@ void Parser::parse_interface_mixin(Interface& interface)
|
|||
|
||||
void Parser::parse_callback_function(HashMap<String, String>& extended_attributes, Interface& interface)
|
||||
{
|
||||
assert_string("callback");
|
||||
assert_string("callback"sv);
|
||||
consume_whitespace();
|
||||
|
||||
auto name = lexer.consume_until([](auto ch) { return is_ascii_space(ch); });
|
||||
|
@ -787,7 +787,7 @@ void Parser::parse_non_interface_entities(bool allow_interface, Interface& inter
|
|||
assert_specific(';');
|
||||
consume_whitespace();
|
||||
} else {
|
||||
report_parsing_error("expected 'enum' or 'dictionary'", filename, input, current_offset);
|
||||
report_parsing_error("expected 'enum' or 'dictionary'"sv, filename, input, current_offset);
|
||||
}
|
||||
} else {
|
||||
interface.extended_attributes = move(extended_attributes);
|
||||
|
|
|
@ -340,21 +340,21 @@ struct UnionType : public Type {
|
|||
String to_variant(IDL::Interface const& interface) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("Variant<");
|
||||
builder.append("Variant<"sv);
|
||||
|
||||
auto flattened_types = flattened_member_types();
|
||||
for (size_t type_index = 0; type_index < flattened_types.size(); ++type_index) {
|
||||
auto& type = flattened_types.at(type_index);
|
||||
|
||||
if (type_index > 0)
|
||||
builder.append(", ");
|
||||
builder.append(", "sv);
|
||||
|
||||
auto cpp_type = idl_type_name_to_cpp_type(type, interface);
|
||||
builder.append(cpp_type.name);
|
||||
}
|
||||
|
||||
if (includes_undefined())
|
||||
builder.append(", Empty");
|
||||
builder.append(", Empty"sv);
|
||||
|
||||
builder.append('>');
|
||||
return builder.to_string();
|
||||
|
|
|
@ -88,7 +88,7 @@ int main(int argc, char** argv)
|
|||
if (namespace_.is_one_of("Crypto", "CSS", "DOM", "DOMParsing", "Encoding", "HTML", "UIEvents", "Geometry", "HighResolutionTime", "IntersectionObserver", "NavigationTiming", "RequestIdleCallback", "ResizeObserver", "SVG", "Selection", "URL", "WebGL", "WebSockets", "XHR")) {
|
||||
StringBuilder builder;
|
||||
builder.append(namespace_);
|
||||
builder.append("::");
|
||||
builder.append("::"sv);
|
||||
builder.append(interface.name);
|
||||
interface.fully_qualified_name = builder.to_string();
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue