summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibLocale/Locale.cpp
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-15 10:04:26 -0500
committerLinus Groh <mail@linusgroh.de>2023-01-16 10:12:37 +0000
commitedfdade9e94342c1828e99c2c89dff32eaa4b070 (patch)
tree6da1389ac0897cdee4c1f834999ba3c2fdaa593d /Userland/Libraries/LibLocale/Locale.cpp
parentb6b5ddeb3b34e88f264bdea5d910c00851c00e8d (diff)
downloadserenity-edfdade9e94342c1828e99c2c89dff32eaa4b070.zip
LibLocale: Add a method to convert LanguageID to a String
Diffstat (limited to 'Userland/Libraries/LibLocale/Locale.cpp')
-rw-r--r--Userland/Libraries/LibLocale/Locale.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/Userland/Libraries/LibLocale/Locale.cpp b/Userland/Libraries/LibLocale/Locale.cpp
index a45e4e9ec1..55df3ef85e 100644
--- a/Userland/Libraries/LibLocale/Locale.cpp
+++ b/Userland/Libraries/LibLocale/Locale.cpp
@@ -906,25 +906,31 @@ DeprecatedString resolve_most_likely_territory_alias(LanguageID const& language_
return aliases[0].to_deprecated_string();
}
-DeprecatedString LanguageID::to_deprecated_string() const
+ErrorOr<String> LanguageID::to_string() const
{
StringBuilder builder;
- auto append_segment = [&](Optional<DeprecatedString> const& segment) {
+ auto append_segment = [&](Optional<DeprecatedString> const& segment) -> ErrorOr<void> {
if (!segment.has_value())
- return;
+ return {};
if (!builder.is_empty())
- builder.append('-');
- builder.append(*segment);
+ TRY(builder.try_append('-'));
+ TRY(builder.try_append(*segment));
+ return {};
};
- append_segment(language);
- append_segment(script);
- append_segment(region);
+ TRY(append_segment(language));
+ TRY(append_segment(script));
+ TRY(append_segment(region));
for (auto const& variant : variants)
- append_segment(variant);
+ TRY(append_segment(variant));
- return builder.build();
+ return builder.to_string();
+}
+
+DeprecatedString LanguageID::to_deprecated_string() const
+{
+ return MUST(to_string()).to_deprecated_string();
}
DeprecatedString LocaleID::to_deprecated_string() const