From 20ea82baccdcaf40bcf19531aa588772f1359acc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 21 Aug 2023 16:59:41 +0200 Subject: [PATCH] LibWeb: Make (snake/title/camel) casification functions infallible --- .../LibWeb/GenerateCSSEasingFunctions.cpp | 8 +-- .../LibWeb/GenerateCSSEnums.cpp | 22 +++---- .../LibWeb/GenerateCSSMathFunctions.cpp | 6 +- .../LibWeb/GenerateCSSMediaFeatureID.cpp | 14 ++--- .../LibWeb/GenerateCSSPropertyID.cpp | 58 +++++++++---------- .../LibWeb/GenerateCSSPseudoClass.cpp | 8 +-- .../LibWeb/GenerateCSSTransformFunctions.cpp | 16 ++--- .../LibWeb/GenerateCSSValueID.cpp | 6 +- .../CodeGenerators/LibWeb/GeneratorUtil.h | 20 +++---- 9 files changed, 79 insertions(+), 79 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEasingFunctions.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEasingFunctions.cpp index 03e869932ec..d301e5532bc 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEasingFunctions.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEasingFunctions.cpp @@ -58,7 +58,7 @@ namespace Web::CSS { generator.appendln("enum class EasingFunction {"); TRY(easing_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.appendln(" @name:titlecase@,"); return {}; })); @@ -111,7 +111,7 @@ Optional easing_function_from_string(StringView name) TRY(easing_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( if (name.equals_ignoring_ascii_case("@name@"sv)) return EasingFunction::@name:titlecase@; @@ -131,7 +131,7 @@ StringView to_string(EasingFunction easing_function) TRY(easing_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case EasingFunction::@name:titlecase@: return "@name@"sv; @@ -154,7 +154,7 @@ EasingFunctionMetadata easing_function_metadata(EasingFunction easing_function) VERIFY(value.is_object()); auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case EasingFunction::@name:titlecase@: return EasingFunctionMetadata { diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp index 7b84bf05426..19ff3441d39 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSEnums.cpp @@ -59,8 +59,8 @@ enum class ValueID; auto& members = value.as_array(); auto enum_generator = generator.fork(); - enum_generator.set("name:titlecase", TRY(title_casify(name))); - enum_generator.set("name:snakecase", TRY(snake_casify(name))); + enum_generator.set("name:titlecase", title_casify(name)); + enum_generator.set("name:snakecase", snake_casify(name)); // Find the smallest possible type to use. auto member_max_value = members.size() - 1; @@ -82,7 +82,7 @@ enum class ValueID; if (member_name.contains('=')) continue; auto member_generator = enum_generator.fork(); - member_generator.set("member:titlecase", TRY(title_casify(member_name))); + member_generator.set("member:titlecase", title_casify(member_name)); member_generator.appendln(" @member:titlecase@,"); } @@ -117,8 +117,8 @@ namespace Web::CSS { auto& members = value.as_array(); auto enum_generator = generator.fork(); - enum_generator.set("name:titlecase", TRY(title_casify(name))); - enum_generator.set("name:snakecase", TRY(snake_casify(name))); + enum_generator.set("name:titlecase", title_casify(name)); + enum_generator.set("name:snakecase", snake_casify(name)); enum_generator.append(R"~~~( Optional<@name:titlecase@> value_id_to_@name:snakecase@(ValueID value_id) @@ -130,11 +130,11 @@ Optional<@name:titlecase@> value_id_to_@name:snakecase@(ValueID value_id) auto member_name = member.to_deprecated_string(); if (member_name.contains('=')) { auto parts = member_name.split_view('='); - member_generator.set("valueid:titlecase", TRY(title_casify(parts[0]))); - member_generator.set("member:titlecase", TRY(title_casify(parts[1]))); + member_generator.set("valueid:titlecase", title_casify(parts[0])); + member_generator.set("member:titlecase", title_casify(parts[1])); } else { - member_generator.set("valueid:titlecase", TRY(title_casify(member_name))); - member_generator.set("member:titlecase", TRY(title_casify(member_name))); + member_generator.set("valueid:titlecase", title_casify(member_name)); + member_generator.set("member:titlecase", title_casify(member_name)); } member_generator.append(R"~~~( case ValueID::@valueid:titlecase@: @@ -158,7 +158,7 @@ ValueID to_value_id(@name:titlecase@ @name:snakecase@_value) auto member_name = member.to_deprecated_string(); if (member_name.contains('=')) continue; - member_generator.set("member:titlecase", TRY(title_casify(member_name))); + member_generator.set("member:titlecase", title_casify(member_name)); member_generator.append(R"~~~( case @name:titlecase@::@member:titlecase@: @@ -183,7 +183,7 @@ StringView to_string(@name:titlecase@ value) if (member_name.contains('=')) continue; member_generator.set("member:css", TRY(String::from_deprecated_string(member_name))); - member_generator.set("member:titlecase", TRY(title_casify(member_name))); + member_generator.set("member:titlecase", title_casify(member_name)); member_generator.append(R"~~~( case @name:titlecase@::@member:titlecase@: diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSMathFunctions.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSMathFunctions.cpp index 12bbf3dbad1..af9632e9d2f 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSMathFunctions.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSMathFunctions.cpp @@ -55,7 +55,7 @@ enum class MathFunction { TRY(functions_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.appendln(" @name:titlecase@,"sv); return {}; })); @@ -156,7 +156,7 @@ OwnPtr Parser::parse_math_function(PropertyID property_id, Func auto function_generator = generator.fork(); function_generator.set("name:lowercase", TRY(String::from_deprecated_string(name))); - function_generator.set("name:titlecase", TRY(title_casify(name))); + function_generator.set("name:titlecase", title_casify(name)); function_generator.appendln(" if (function.name().equals_ignoring_ascii_case(\"@name:lowercase@\"sv)) {"); if (function_data.get_bool("is-variadic"sv).value_or(false)) { // Variadic function @@ -247,7 +247,7 @@ OwnPtr Parser::parse_math_function(PropertyID property_id, Func 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()) { - parameter_generator.set("parameter_default", TRY(String::formatted(" = RoundingStrategy::{}", TRY(title_casify(default_value.value()))))); + parameter_generator.set("parameter_default", TRY(String::formatted(" = RoundingStrategy::{}", title_casify(default_value.value())))); } else { parameter_generator.set("parameter_default", ""_string); } diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSMediaFeatureID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSMediaFeatureID.cpp index 9d275fa74cb..ab54273fb6d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSMediaFeatureID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSMediaFeatureID.cpp @@ -62,7 +62,7 @@ enum class MediaFeatureID {)~~~"); TRY(media_feature_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( @name:titlecase@,)~~~"); return {}; @@ -101,7 +101,7 @@ Optional media_feature_id_from_string(StringView string) TRY(media_feature_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( if (Infra::is_ascii_case_insensitive_match(string, "@name@"sv)) return MediaFeatureID::@name:titlecase@; @@ -120,7 +120,7 @@ StringView string_from_media_feature_id(MediaFeatureID media_feature_id) TRY(media_feature_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case MediaFeatureID::@name:titlecase@: return "@name@"sv;)~~~"); @@ -141,7 +141,7 @@ bool media_feature_type_is_range(MediaFeatureID media_feature_id) auto& feature = value.as_object(); auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); VERIFY(feature.has("type"sv)); auto feature_type = feature.get_deprecated_string("type"sv); VERIFY(feature_type.has_value()); @@ -166,7 +166,7 @@ bool media_feature_accepts_type(MediaFeatureID media_feature_id, MediaFeatureVal auto& feature = member.as_object(); auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case MediaFeatureID::@name:titlecase@:)~~~"); @@ -246,7 +246,7 @@ bool media_feature_accepts_identifier(MediaFeatureID media_feature_id, ValueID i auto& feature = member.as_object(); auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case MediaFeatureID::@name:titlecase@:)~~~"); @@ -272,7 +272,7 @@ bool media_feature_accepts_identifier(MediaFeatureID media_feature_id, ValueID i TRY(append_identifier_switch_if_needed()); auto ident_generator = member_generator.fork(); - ident_generator.set("identifier:titlecase", TRY(title_casify(identifier_name))); + ident_generator.set("identifier:titlecase", title_casify(identifier_name)); ident_generator.append(R"~~~( case ValueID::@identifier:titlecase@: return true;)~~~"); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp index 7938d4f6eb6..2c4e8b5d1b5 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp @@ -124,7 +124,7 @@ enum class PropertyID { for (auto& name : shorthand_property_ids) { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( @name:titlecase@, @@ -133,21 +133,21 @@ enum class PropertyID { for (auto& name : longhand_property_ids) { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( @name:titlecase@, )~~~"); } - generator.set("first_property_id", TRY(title_casify(first_property_id))); - generator.set("last_property_id", TRY(title_casify(last_property_id))); + generator.set("first_property_id", title_casify(first_property_id)); + generator.set("last_property_id", title_casify(last_property_id)); - generator.set("first_shorthand_property_id", TRY(title_casify(shorthand_property_ids.first()))); - generator.set("last_shorthand_property_id", TRY(title_casify(shorthand_property_ids.last()))); + generator.set("first_shorthand_property_id", title_casify(shorthand_property_ids.first())); + generator.set("last_shorthand_property_id", title_casify(shorthand_property_ids.last())); - generator.set("first_longhand_property_id", TRY(title_casify(longhand_property_ids.first()))); - generator.set("last_longhand_property_id", TRY(title_casify(longhand_property_ids.last()))); + generator.set("first_longhand_property_id", title_casify(longhand_property_ids.first())); + generator.set("last_longhand_property_id", title_casify(longhand_property_ids.last())); generator.append(R"~~~( }; @@ -250,7 +250,7 @@ bool property_accepts_@css_type_name@(PropertyID property_id, [[maybe_unused]] @ continue; auto property_generator = generator.fork(); - property_generator.set("property_name:titlecase", TRY(title_casify(name))); + property_generator.set("property_name:titlecase", title_casify(name)); property_generator.append(R"~~~( case PropertyID::@property_name:titlecase@: @@ -290,7 +290,7 @@ bool property_accepts_@css_type_name@(PropertyID property_id, [[maybe_unused]] @ value_unit = default_unit_name.value(); VERIFY(lexer.is_eof()); property_generator.set("value_number", TRY(String::from_utf8(value_number))); - property_generator.set("value_unit", TRY(title_casify(value_unit))); + property_generator.set("value_unit", title_casify(value_unit)); property_generator.set("comparator", TRY(String::from_utf8(comparator))); property_generator.append("value @comparator@ @type_name@(@value_number@, @type_name@::Type::@value_unit@)"); return {}; @@ -347,8 +347,8 @@ Optional property_id_from_camel_case_string(StringView string) auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); - member_generator.set("name:camelcase", TRY(camel_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); + member_generator.set("name:camelcase", camel_casify(name)); member_generator.append(R"~~~( if (string.equals_ignoring_ascii_case("@name:camelcase@"sv)) return PropertyID::@name:titlecase@; @@ -371,7 +371,7 @@ Optional property_id_from_string(StringView string) auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( if (Infra::is_ascii_case_insensitive_match(string, "@name@"sv)) return PropertyID::@name:titlecase@; @@ -392,7 +392,7 @@ StringView string_from_property_id(PropertyID property_id) { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case PropertyID::@name:titlecase@: return "@name@"sv; @@ -423,7 +423,7 @@ bool is_inherited_property(PropertyID property_id) if (inherited) { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case PropertyID::@name:titlecase@: return true; @@ -452,7 +452,7 @@ bool property_affects_layout(PropertyID property_id) if (affects_layout) { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case PropertyID::@name:titlecase@: )~~~"); @@ -481,7 +481,7 @@ bool property_affects_stacking_context(PropertyID property_id) if (affects_stacking_context) { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case PropertyID::@name:titlecase@: )~~~"); @@ -520,7 +520,7 @@ NonnullRefPtr property_initial_value(JS::Realm& context_realm, Prope auto& initial_value_string = initial_value.value(); auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.set("initial_value_string", TRY(String::from_deprecated_string(initial_value_string))); member_generator.append( R"~~~( case PropertyID::@name:titlecase@: @@ -561,7 +561,7 @@ bool property_has_quirk(PropertyID property_id, Quirk quirk) if (!quirks.is_empty()) { auto property_generator = generator.fork(); - property_generator.set("name:titlecase", TRY(title_casify(name))); + property_generator.set("name:titlecase", title_casify(name)); property_generator.append(R"~~~( case PropertyID::@name:titlecase@: { switch (quirk) { @@ -569,7 +569,7 @@ bool property_has_quirk(PropertyID property_id, Quirk quirk) for (auto& quirk : quirks.values()) { VERIFY(quirk.is_string()); auto quirk_generator = property_generator.fork(); - quirk_generator.set("quirk:titlecase", TRY(title_casify(quirk.as_string()))); + quirk_generator.set("quirk:titlecase", title_casify(quirk.as_string())); quirk_generator.append(R"~~~( case Quirk::@quirk:titlecase@: return true; @@ -602,7 +602,7 @@ bool property_accepts_type(PropertyID property_id, ValueType value_type) if (auto maybe_valid_types = object.get_array("valid-types"sv); maybe_valid_types.has_value() && !maybe_valid_types->is_empty()) { auto& valid_types = maybe_valid_types.value(); auto property_generator = generator.fork(); - property_generator.set("name:titlecase", TRY(title_casify(name))); + property_generator.set("name:titlecase", title_casify(name)); property_generator.append(R"~~~( case PropertyID::@name:titlecase@: { switch (value_type) { @@ -682,7 +682,7 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier) auto& object = value.as_object(); auto property_generator = generator.fork(); - property_generator.set("name:titlecase", TRY(title_casify(name))); + property_generator.set("name:titlecase", title_casify(name)); property_generator.appendln(" case PropertyID::@name:titlecase@: {"); if (auto maybe_valid_identifiers = object.get_array("valid-identifiers"sv); maybe_valid_identifiers.has_value() && !maybe_valid_identifiers->is_empty()) { @@ -690,7 +690,7 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier) auto& valid_identifiers = maybe_valid_identifiers.value(); for (auto& identifier : valid_identifiers.values()) { auto identifier_generator = generator.fork(); - identifier_generator.set("identifier:titlecase", TRY(title_casify(identifier.as_string()))); + identifier_generator.set("identifier:titlecase", title_casify(identifier.as_string())); identifier_generator.appendln(" case ValueID::@identifier:titlecase@:"); } property_generator.append(R"~~~( @@ -709,7 +709,7 @@ bool property_accepts_identifier(PropertyID property_id, ValueID identifier) continue; auto type_generator = generator.fork(); - type_generator.set("type_name:snakecase", TRY(snake_casify(type_name))); + type_generator.set("type_name:snakecase", snake_casify(type_name)); type_generator.append(R"~~~( if (value_id_to_@type_name:snakecase@(identifier).has_value()) return true; @@ -737,8 +737,8 @@ Optional property_resolves_percentages_relative_to(PropertyID propert VERIFY(value.is_object()); if (auto resolved_type = value.as_object().get_deprecated_string("percentages-resolve-to"sv); resolved_type.has_value()) { auto property_generator = generator.fork(); - property_generator.set("name:titlecase", TRY(title_casify(name))); - property_generator.set("resolved_type:titlecase", TRY(title_casify(resolved_type.value()))); + property_generator.set("name:titlecase", title_casify(name)); + property_generator.set("resolved_type:titlecase", title_casify(resolved_type.value())); property_generator.append(R"~~~( case PropertyID::@name:titlecase@: return ValueType::@resolved_type:titlecase@; @@ -764,7 +764,7 @@ size_t property_maximum_value_count(PropertyID property_id) auto max_values = value.as_object().get("max-values"sv); VERIFY(max_values.has_value() && max_values->is_number() && !max_values->is_double()); auto property_generator = generator.fork(); - property_generator.set("name:titlecase", TRY(title_casify(name))); + property_generator.set("name:titlecase", title_casify(name)); property_generator.set("max_values", TRY(String::from_deprecated_string(max_values->to_deprecated_string()))); property_generator.append(R"~~~( case PropertyID::@name:titlecase@: @@ -800,7 +800,7 @@ Vector longhands_for_shorthand(PropertyID property_id) VERIFY(longhands.has_value() && longhands->is_array()); auto longhand_values = longhands->as_array(); auto property_generator = generator.fork(); - property_generator.set("name:titlecase", TRY(title_casify(name))); + property_generator.set("name:titlecase", title_casify(name)); StringBuilder builder; bool first = true; TRY(longhand_values.try_for_each([&](auto& longhand) -> ErrorOr { @@ -808,7 +808,7 @@ Vector longhands_for_shorthand(PropertyID property_id) first = false; else builder.append(", "sv); - TRY(builder.try_appendff("PropertyID::{}", TRY(title_casify(longhand.to_deprecated_string())))); + TRY(builder.try_appendff("PropertyID::{}", title_casify(longhand.to_deprecated_string()))); return IterationDecision::Continue; })); property_generator.set("longhands", builder.to_deprecated_string()); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPseudoClass.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPseudoClass.cpp index 6d043307e3b..39e0e1099e9 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPseudoClass.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPseudoClass.cpp @@ -55,7 +55,7 @@ enum class PseudoClass { TRY(pseudo_classes_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.appendln(" @name:titlecase@,"); return {}; @@ -106,7 +106,7 @@ Optional pseudo_class_from_string(StringView string) TRY(pseudo_classes_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( if (string.equals_ignoring_ascii_case("@name@"sv)) @@ -128,7 +128,7 @@ StringView pseudo_class_name(PseudoClass pseudo_class) TRY(pseudo_classes_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.append(R"~~~( case PseudoClass::@name:titlecase@: @@ -182,7 +182,7 @@ PseudoClassMetadata pseudo_class_metadata(PseudoClass pseudo_class) } } - member_generator.set("name:titlecase", TRY(title_casify(name))); + member_generator.set("name:titlecase", title_casify(name)); member_generator.set("parameter_type", parameter_type); member_generator.set("is_valid_as_function", is_valid_as_function ? "true"_string : "false"_string); member_generator.set("is_valid_as_identifier", is_valid_as_identifier ? "true"_string : "false"_string); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp index 5d28b5f9b28..7bc7c71d45f 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSTransformFunctions.cpp @@ -39,13 +39,13 @@ ErrorOr serenity_main(Main::Arguments arguments) return 0; } -static ErrorOr title_casify_transform_function(StringView input) +static String title_casify_transform_function(StringView input) { // Transform function names look like `fooBar`, so we just have to make the first character uppercase. StringBuilder builder; - TRY(builder.try_append(toupper(input[0]))); - TRY(builder.try_append(input.substring_view(1))); - return builder.to_string(); + builder.append(toupper(input[0])); + builder.append(input.substring_view(1)); + return MUST(builder.to_string()); } ErrorOr generate_header_file(JsonObject& transforms_data, Core::File& file) @@ -67,7 +67,7 @@ namespace Web::CSS { generator.appendln("enum class TransformFunction {"); TRY(transforms_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify_transform_function(name))); + member_generator.set("name:titlecase", title_casify_transform_function(name)); member_generator.appendln(" @name:titlecase@,"); return {}; })); @@ -120,7 +120,7 @@ Optional transform_function_from_string(StringView name) TRY(transforms_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify_transform_function(name))); + member_generator.set("name:titlecase", title_casify_transform_function(name)); member_generator.append(R"~~~( if (name.equals_ignoring_ascii_case("@name@"sv)) return TransformFunction::@name:titlecase@; @@ -140,7 +140,7 @@ StringView to_string(TransformFunction transform_function) TRY(transforms_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name))); - member_generator.set("name:titlecase", TRY(title_casify_transform_function(name))); + member_generator.set("name:titlecase", title_casify_transform_function(name)); member_generator.append(R"~~~( case TransformFunction::@name:titlecase@: return "@name@"sv; @@ -163,7 +163,7 @@ TransformFunctionMetadata transform_function_metadata(TransformFunction transfor VERIFY(value.is_object()); auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify_transform_function(name))); + member_generator.set("name:titlecase", title_casify_transform_function(name)); member_generator.append(R"~~~( case TransformFunction::@name:titlecase@: return TransformFunctionMetadata { diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp index f906beaea09..e680726e18d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp @@ -57,7 +57,7 @@ enum class ValueID { TRY(identifier_data.try_for_each([&](auto& name) -> ErrorOr { auto member_generator = generator.fork(); - member_generator.set("name:titlecase", TRY(title_casify(name.to_deprecated_string()))); + member_generator.set("name:titlecase", title_casify(name.to_deprecated_string())); member_generator.append(R"~~~( @name:titlecase@, @@ -97,7 +97,7 @@ HashMap g_stringv TRY(identifier_data.try_for_each([&](auto& name) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name.to_deprecated_string()))); - member_generator.set("name:titlecase", TRY(title_casify(name.to_deprecated_string()))); + member_generator.set("name:titlecase", title_casify(name.to_deprecated_string())); member_generator.append(R"~~~( {"@name@"sv, ValueID::@name:titlecase@}, )~~~"); @@ -119,7 +119,7 @@ StringView string_from_value_id(ValueID value_id) { TRY(identifier_data.try_for_each([&](auto& name) -> ErrorOr { auto member_generator = generator.fork(); member_generator.set("name", TRY(String::from_deprecated_string(name.to_deprecated_string()))); - member_generator.set("name:titlecase", TRY(title_casify(name.to_deprecated_string()))); + member_generator.set("name:titlecase", title_casify(name.to_deprecated_string())); member_generator.append(R"~~~( case ValueID::@name:titlecase@: return "@name@"sv; diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h index fed42404ba7..3cf1c7acfbf 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GeneratorUtil.h @@ -13,22 +13,22 @@ #include #include -ErrorOr title_casify(StringView dashy_name) +String title_casify(StringView dashy_name) { auto parts = dashy_name.split_view('-'); StringBuilder builder; for (auto& part : parts) { if (part.is_empty()) continue; - TRY(builder.try_append(toupper(part[0]))); + builder.append(toupper(part[0])); if (part.length() == 1) continue; - TRY(builder.try_append(part.substring_view(1, part.length() - 1))); + builder.append(part.substring_view(1, part.length() - 1)); } - return builder.to_string(); + return MUST(builder.to_string()); } -ErrorOr camel_casify(StringView dashy_name) +String camel_casify(StringView dashy_name) { auto parts = dashy_name.split_view('-'); StringBuilder builder; @@ -41,19 +41,19 @@ ErrorOr camel_casify(StringView dashy_name) ch = toupper(ch); else first = false; - TRY(builder.try_append(ch)); + builder.append(ch); if (part.length() == 1) continue; - TRY(builder.try_append(part.substring_view(1, part.length() - 1))); + builder.append(part.substring_view(1, part.length() - 1)); } - return builder.to_string(); + return MUST(builder.to_string()); } -ErrorOr snake_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. - return TRY(String::from_utf8(dashy_name)).replace("-"sv, "_"sv, ReplaceMode::All); + return MUST(MUST(String::from_utf8(dashy_name)).replace("-"sv, "_"sv, ReplaceMode::All)); } ErrorOr read_entire_file_as_json(StringView filename)