summaryrefslogtreecommitdiff
path: root/Meta/Lagom/Tools
diff options
context:
space:
mode:
Diffstat (limited to 'Meta/Lagom/Tools')
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp6
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h26
2 files changed, 27 insertions, 5 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp
index cd73032bda..23197e4a47 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp
@@ -1077,7 +1077,11 @@ Optional<StringView> get_locale_@enum_snake@_mapping(StringView locale, StringVi
for (auto const& alias : aliases)
hashes.set(alias.key.hash(), alias.value);
- generate_value_from_string(generator, "resolve_{}_alias"sv, s_string_index_type, enum_snake, move(hashes), "StringView"sv, "s_string_list[{}]"sv);
+ ValueFromStringOptions options {};
+ options.return_type = "StringView"sv;
+ options.return_format = "s_string_list[{}]"sv;
+
+ generate_value_from_string(generator, "resolve_{}_alias"sv, s_string_index_type, enum_snake, move(hashes), options);
};
append_from_string("Locale"sv, "locale"sv, locale_data.locales.keys(), locale_data.locale_aliases);
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h
index b1501a89f4..ead34e0c4b 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h
+++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h
@@ -293,15 +293,21 @@ struct HashValueComparator
template<typename ValueType>
using HashValueMap = HashMap<unsigned, ValueType>;
+struct ValueFromStringOptions {
+ Optional<StringView> return_type {};
+ StringView return_format { "{}"sv };
+ CaseSensitivity sensitivity { CaseSensitivity::CaseSensitive };
+};
+
template<typename ValueType>
-void generate_value_from_string(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, HashValueMap<ValueType> hashes, Optional<StringView> return_type = {}, StringView return_format = "{}"sv)
+void generate_value_from_string(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, HashValueMap<ValueType> hashes, ValueFromStringOptions options = {})
{
ensure_from_string_types_are_generated(generator);
generator.set("method_name", String::formatted(method_name_format, value_name));
generator.set("value_type", value_type);
generator.set("value_name", value_name);
- generator.set("return_type", return_type.has_value() ? *return_type : value_type);
+ generator.set("return_type", options.return_type.has_value() ? *options.return_type : value_type);
generator.set("size", String::number(hashes.size()));
generator.append(R"~~~(
@@ -334,11 +340,23 @@ Optional<@return_type@> @method_name@(StringView key)
}
}
- generator.set("return_statement", String::formatted(return_format, "value->value"sv));
+ generator.set("return_statement", String::formatted(options.return_format, "value->value"sv));
generator.append(R"~~~(
} };
+)~~~");
+
+ if (options.sensitivity == CaseSensitivity::CaseSensitive) {
+ generator.append(R"~~~(
+ auto hash = key.hash();
+)~~~");
+ } else {
+ generator.append(R"~~~(
+ auto hash = CaseInsensitiveStringViewTraits::hash(key);
+)~~~");
+ }
- if (auto const* value = binary_search(hash_pairs, key.hash(), nullptr, HashValueComparator<@value_type@> {}))
+ generator.append(R"~~~(
+ if (auto const* value = binary_search(hash_pairs, hash, nullptr, HashValueComparator<@value_type@> {}))
return @return_statement@;
return {};
}