diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-15 10:04:26 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-16 10:12:37 +0000 |
commit | edfdade9e94342c1828e99c2c89dff32eaa4b070 (patch) | |
tree | 6da1389ac0897cdee4c1f834999ba3c2fdaa593d /Userland/Libraries/LibLocale/Locale.cpp | |
parent | b6b5ddeb3b34e88f264bdea5d910c00851c00e8d (diff) | |
download | serenity-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.cpp | 26 |
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 |