diff --git a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp index bdb7ccbdfd..cded014ffe 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp @@ -235,12 +235,19 @@ namespace TimeZone { HashValueMap hashes; hashes.ensure_capacity(values.size()); - for (auto const& value : values) - hashes.set(value.hash(), format_identifier(enum_title, value)); - for (auto const& alias : aliases) - hashes.set(alias.alias.hash(), format_identifier(enum_title, alias.alias)); + auto hash = [](auto const& value) { + return CaseInsensitiveStringViewTraits::hash(value); + }; - generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes)); + for (auto const& value : values) + hashes.set(hash(value), format_identifier(enum_title, value)); + for (auto const& alias : aliases) + hashes.set(hash(alias.alias), format_identifier(enum_title, alias.alias)); + + ValueFromStringOptions options {}; + options.sensitivity = CaseSensitivity::CaseInsensitive; + + generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes), options); }; append_from_string("TimeZone"sv, "time_zone"sv, time_zone_data.time_zone_names, time_zone_data.time_zone_aliases); diff --git a/Tests/LibTimeZone/TestTimeZone.cpp b/Tests/LibTimeZone/TestTimeZone.cpp index 15a4115267..57f9f9f163 100644 --- a/Tests/LibTimeZone/TestTimeZone.cpp +++ b/Tests/LibTimeZone/TestTimeZone.cpp @@ -46,4 +46,11 @@ TEST_CASE(time_zone_from_string_link) test_link("Universal"sv, "UTC"sv); } +TEST_CASE(case_insensitive_time_zone_from_string) +{ + EXPECT_EQ(TimeZone::time_zone_from_string("UTC"sv), TimeZone::TimeZone::UTC); + EXPECT_EQ(TimeZone::time_zone_from_string("utc"sv), TimeZone::TimeZone::UTC); + EXPECT_EQ(TimeZone::time_zone_from_string("uTc"sv), TimeZone::TimeZone::UTC); +} + #endif