mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibWeb: Make (snake/title/camel) casification functions infallible
This commit is contained in:
parent
0b83717ea2
commit
20ea82bacc
9 changed files with 79 additions and 79 deletions
|
@ -58,7 +58,7 @@ namespace Web::CSS {
|
|||
generator.appendln("enum class EasingFunction {");
|
||||
TRY(easing_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
|
||||
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<EasingFunction> easing_function_from_string(StringView name)
|
|||
TRY(easing_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
|
||||
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<void> {
|
||||
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 {
|
||||
|
|
|
@ -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@:
|
||||
|
|
|
@ -55,7 +55,7 @@ enum class MathFunction {
|
|||
|
||||
TRY(functions_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
|
||||
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<CalculationNode> 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<CalculationNode> 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);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ enum class MediaFeatureID {)~~~");
|
|||
|
||||
TRY(media_feature_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
|
||||
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<MediaFeatureID> media_feature_id_from_string(StringView string)
|
|||
TRY(media_feature_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
|
||||
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<void> {
|
||||
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;)~~~");
|
||||
|
|
|
@ -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<PropertyID> 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<PropertyID> 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<StyleValue> 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<ValueType> 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<PropertyID> 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<IterationDecision> {
|
||||
|
@ -808,7 +808,7 @@ Vector<PropertyID> 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());
|
||||
|
|
|
@ -55,7 +55,7 @@ enum class PseudoClass {
|
|||
|
||||
TRY(pseudo_classes_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
|
||||
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<PseudoClass> pseudo_class_from_string(StringView string)
|
|||
TRY(pseudo_classes_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
|
||||
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<void> {
|
||||
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);
|
||||
|
|
|
@ -39,13 +39,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ErrorOr<String> 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<void> 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<void> {
|
||||
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<TransformFunction> transform_function_from_string(StringView name)
|
|||
TRY(transforms_data.try_for_each_member([&](auto& name, auto&) -> ErrorOr<void> {
|
||||
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<void> {
|
||||
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 {
|
||||
|
|
|
@ -57,7 +57,7 @@ enum class ValueID {
|
|||
|
||||
TRY(identifier_data.try_for_each([&](auto& name) -> ErrorOr<void> {
|
||||
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<StringView, ValueID, AK::CaseInsensitiveASCIIStringViewTraits> g_stringv
|
|||
TRY(identifier_data.try_for_each([&](auto& name) -> ErrorOr<void> {
|
||||
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<void> {
|
||||
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;
|
||||
|
|
|
@ -13,22 +13,22 @@
|
|||
#include <LibCore/File.h>
|
||||
#include <ctype.h>
|
||||
|
||||
ErrorOr<String> 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<String> camel_casify(StringView dashy_name)
|
||||
String camel_casify(StringView dashy_name)
|
||||
{
|
||||
auto parts = dashy_name.split_view('-');
|
||||
StringBuilder builder;
|
||||
|
@ -41,19 +41,19 @@ ErrorOr<String> 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<String> 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<JsonValue> read_entire_file_as_json(StringView filename)
|
||||
|
|
Loading…
Add table
Reference in a new issue