mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +00:00
LibUnicode: Implement to_fullwidth()
in String
The implementation uses the transliterator class from icu.
This commit is contained in:
parent
5a6a7b7e5e
commit
a8a81342bb
Notes:
github-actions[bot]
2024-11-01 11:49:19 +00:00
Author: https://github.com/Grubre Commit: https://github.com/LadybirdBrowser/ladybird/commit/a8a81342bb5 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2045 Reviewed-by: https://github.com/trflynn89
2 changed files with 17 additions and 0 deletions
|
@ -101,6 +101,7 @@ public:
|
|||
ErrorOr<String> to_uppercase(Optional<StringView> const& locale = {}) const;
|
||||
ErrorOr<String> to_titlecase(Optional<StringView> const& locale = {}, TrailingCodePointTransformation trailing_code_point_transformation = TrailingCodePointTransformation::Lowercase) const;
|
||||
ErrorOr<String> to_casefold() const;
|
||||
ErrorOr<String> to_fullwidth() const;
|
||||
|
||||
[[nodiscard]] String to_ascii_lowercase() const;
|
||||
[[nodiscard]] String to_ascii_uppercase() const;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <unicode/bytestream.h>
|
||||
#include <unicode/casemap.h>
|
||||
#include <unicode/stringoptions.h>
|
||||
#include <unicode/translit.h>
|
||||
|
||||
// This file contains definitions of AK::String methods which require UCD data.
|
||||
|
||||
|
@ -85,6 +86,21 @@ ErrorOr<String> String::to_titlecase(Optional<StringView> const& locale, Trailin
|
|||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
ErrorOr<String> String::to_fullwidth() const
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
auto const transliterator = adopt_own_if_nonnull(icu::Transliterator::createInstance("Halfwidth-Fullwidth", UTRANS_FORWARD, status));
|
||||
if (Unicode::icu_failure(status)) {
|
||||
return Error::from_string_literal("Unable to create transliterator");
|
||||
}
|
||||
|
||||
auto icu_string = Unicode::icu_string(bytes_as_string_view());
|
||||
transliterator->transliterate(icu_string);
|
||||
|
||||
return Unicode::icu_string_to_string(icu_string);
|
||||
}
|
||||
|
||||
static ErrorOr<void> build_casefold_string(StringView string, StringBuilder& builder)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
|
Loading…
Reference in a new issue