summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2023-01-29 00:45:08 +0000
committerLinus Groh <mail@linusgroh.de>2023-01-29 00:57:41 +0000
commit489fe49321975b7da7552b9c791cc535443445b3 (patch)
tree206510f08657b9522e9fbbfe28d81b27d9562e37
parent476d4b4963defc3a851489801045784bc0a75a8d (diff)
downloadserenity-489fe49321975b7da7552b9c791cc535443445b3.zip
LibWeb: Fix parsing/to_string for "switch" ARIA role
I accidentally regressed this in 890b4d7, this role needs to be handled specially due to the clash with the C++ 'switch' keyword.
-rw-r--r--Userland/Libraries/LibWeb/ARIA/Roles.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/ARIA/Roles.cpp b/Userland/Libraries/LibWeb/ARIA/Roles.cpp
index 061194191e..b032e0351f 100644
--- a/Userland/Libraries/LibWeb/ARIA/Roles.cpp
+++ b/Userland/Libraries/LibWeb/ARIA/Roles.cpp
@@ -11,9 +11,12 @@ namespace Web::ARIA {
StringView role_name(Role role)
{
+ // Note: Role::switch_ is mapped to "switch" (due to C++ keyword clash)
switch (role) {
-#define __ENUMERATE_ARIA_ROLE(name) \
- case Role::name: \
+#define __ENUMERATE_ARIA_ROLE(name) \
+ case Role::name: \
+ if constexpr (Role::name == Role::switch_) \
+ return "switch"sv; \
return #name##sv;
ENUMERATE_ARIA_ROLES
#undef __ENUMERATE_ARIA_ROLE
@@ -24,9 +27,15 @@ StringView role_name(Role role)
Optional<Role> role_from_string(StringView role_name)
{
-#define __ENUMERATE_ARIA_ROLE(name) \
- if (role_name.equals_ignoring_case(#name##sv)) \
- return Role::name;
+ // Note: "switch" is mapped to Role::switch_ (due to C++ keyword clash)
+#define __ENUMERATE_ARIA_ROLE(name) \
+ if constexpr (Role::name == Role::switch_) { \
+ if (role_name.equals_ignoring_case("switch"sv)) \
+ return Role::switch_; \
+ } else { \
+ if (role_name.equals_ignoring_case(#name##sv)) \
+ return Role::name; \
+ }
ENUMERATE_ARIA_ROLES
#undef __ENUMERATE_ARIA_ROLE
return {};