mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
LibWeb: Generate CSS::property_id_from_camel_case_string()
This allows us to resolve a "camelCase" CSS property name to our own CSS::PropertyID enum. This will be used by CSSOM bindings.
This commit is contained in:
parent
30d710a0a2
commit
dadb92a155
2 changed files with 43 additions and 0 deletions
|
@ -26,6 +26,27 @@ static String title_casify(const String& dashy_name)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
static String camel_casify(StringView dashy_name)
|
||||
{
|
||||
auto parts = dashy_name.split_view('-');
|
||||
StringBuilder builder;
|
||||
bool first = true;
|
||||
for (auto& part : parts) {
|
||||
if (part.is_empty())
|
||||
continue;
|
||||
char ch = part[0];
|
||||
if (!first)
|
||||
ch = toupper(ch);
|
||||
else
|
||||
first = false;
|
||||
builder.append(ch);
|
||||
if (part.length() == 1)
|
||||
continue;
|
||||
builder.append(part.substring_view(1, part.length() - 1));
|
||||
}
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
|
@ -53,6 +74,27 @@ int main(int argc, char** argv)
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
PropertyID property_id_from_camel_case_string(StringView string)
|
||||
{
|
||||
)~~~");
|
||||
|
||||
properties.for_each_member([&](auto& name, auto& value) {
|
||||
VERIFY(value.is_object());
|
||||
|
||||
auto member_generator = generator.fork();
|
||||
member_generator.set("name", 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_case("@name:camelcase@"sv))
|
||||
return PropertyID::@name:titlecase@;
|
||||
)~~~");
|
||||
});
|
||||
|
||||
generator.append(R"~~~(
|
||||
return PropertyID::Invalid;
|
||||
}
|
||||
|
||||
PropertyID property_id_from_string(const StringView& string)
|
||||
{
|
||||
)~~~");
|
||||
|
|
|
@ -100,6 +100,7 @@ enum class PropertyID {
|
|||
generator.append(R"~~~(
|
||||
};
|
||||
|
||||
PropertyID property_id_from_camel_case_string(StringView);
|
||||
PropertyID property_id_from_string(const StringView&);
|
||||
const char* string_from_property_id(PropertyID);
|
||||
bool is_inherited_property(PropertyID);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue