diff --git a/AK/Forward.h b/AK/Forward.h index e54d95a8ef..3fc2231aee 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -17,6 +17,8 @@ template class ByteBuffer; } +enum class TrailingCodePointTransformation : u8; + class BigEndianInputBitStream; class BigEndianOutputBitStream; class Bitmap; @@ -198,6 +200,7 @@ using AK::String; using AK::StringBuilder; using AK::StringImpl; using AK::StringView; +using AK::TrailingCodePointTransformation; using AK::Traits; using AK::UnixDateTime; using AK::URL; diff --git a/AK/String.h b/AK/String.h index e84ab8abef..42b7a8d58f 100644 --- a/AK/String.h +++ b/AK/String.h @@ -95,7 +95,7 @@ public: // Creates a new String by case-transforming this String. Using these methods require linking LibUnicode into your application. ErrorOr to_lowercase(Optional const& locale = {}) const; ErrorOr to_uppercase(Optional const& locale = {}) const; - ErrorOr to_titlecase(Optional const& locale = {}) const; + ErrorOr to_titlecase(Optional const& locale = {}, TrailingCodePointTransformation trailing_code_point_transformation = TrailingCodePointTransformation::Lowercase) const; ErrorOr to_casefold() const; // Compare this String against another string with caseless matching. Using this method requires linking LibUnicode into your application. diff --git a/AK/StringUtils.h b/AK/StringUtils.h index 190bb3293d..1bc4b865bd 100644 --- a/AK/StringUtils.h +++ b/AK/StringUtils.h @@ -54,6 +54,13 @@ enum class SplitBehavior : unsigned { }; AK_ENUM_BITWISE_OPERATORS(SplitBehavior); +enum class TrailingCodePointTransformation : u8 { + // Default behaviour; Puts the first typographic letter unit of each word, if lowercase, in titlecase; the other characters in lowercase. + Lowercase, + // Puts the first typographic letter unit of each word, if lowercase, in titlecase; other characters are unaffected. (https://drafts.csswg.org/css-text/#valdef-text-transform-capitalize) + PreserveExisting, +}; + struct MaskSpan { size_t start; size_t length; @@ -117,6 +124,7 @@ size_t count(StringView, char needle); using AK::CaseSensitivity; using AK::ReplaceMode; using AK::SplitBehavior; +using AK::TrailingCodePointTransformation; using AK::TrimMode; using AK::TrimWhitespace; #endif diff --git a/Userland/Libraries/LibUnicode/CharacterTypes.h b/Userland/Libraries/LibUnicode/CharacterTypes.h index 43219ca468..70af064ef6 100644 --- a/Userland/Libraries/LibUnicode/CharacterTypes.h +++ b/Userland/Libraries/LibUnicode/CharacterTypes.h @@ -34,13 +34,6 @@ struct BlockName { StringView display_name; }; -enum class TrailingCodePointTransformation : u8 { - // Default behaviour; Puts the first typographic letter unit of each word, if lowercase, in titlecase; the other characters in lowercase. - Lowercase, - // Puts the first typographic letter unit of each word, if lowercase, in titlecase; other characters are unaffected. (https://drafts.csswg.org/css-text/#valdef-text-transform-capitalize) - PreserveExisting, -}; - Optional code_point_display_name(u32 code_point); Optional code_point_block_display_name(u32 code_point); Optional code_point_abbreviation(u32 code_point); diff --git a/Userland/Libraries/LibUnicode/Forward.h b/Userland/Libraries/LibUnicode/Forward.h index e61e1c076d..c6c6dfd9da 100644 --- a/Userland/Libraries/LibUnicode/Forward.h +++ b/Userland/Libraries/LibUnicode/Forward.h @@ -19,7 +19,6 @@ enum class Property : u8; enum class Script : u8; enum class SentenceBreakProperty : u8; enum class WordBreakProperty : u8; -enum class TrailingCodePointTransformation : u8; struct CodePointDecomposition; struct CurrencyCode; diff --git a/Userland/Libraries/LibUnicode/String.cpp b/Userland/Libraries/LibUnicode/String.cpp index 464600ce23..c61fa7f796 100644 --- a/Userland/Libraries/LibUnicode/String.cpp +++ b/Userland/Libraries/LibUnicode/String.cpp @@ -28,10 +28,10 @@ ErrorOr String::to_uppercase(Optional const& locale) const return builder.to_string(); } -ErrorOr String::to_titlecase(Optional const& locale) const +ErrorOr String::to_titlecase(Optional const& locale, TrailingCodePointTransformation trailing_code_point_transformation) const { StringBuilder builder; - TRY(Unicode::Detail::build_titlecase_string(code_points(), builder, locale, Unicode::TrailingCodePointTransformation::Lowercase)); + TRY(Unicode::Detail::build_titlecase_string(code_points(), builder, locale, trailing_code_point_transformation)); return builder.to_string(); }