AK+LibUnicode: Expose TrailingCodePointTransformation in to_titlecase

Relocating the definition of this enum from LibUnicode to AK.
This commit is contained in:
Shannon Booth 2023-11-27 20:56:50 +13:00 committed by Tim Flynn
parent af7df1dbbf
commit 6b32a1f18f
Notes: sideshowbarker 2024-07-17 00:49:59 +09:00
6 changed files with 14 additions and 11 deletions

View file

@ -17,6 +17,8 @@ template<size_t inline_capacity>
class ByteBuffer; class ByteBuffer;
} }
enum class TrailingCodePointTransformation : u8;
class BigEndianInputBitStream; class BigEndianInputBitStream;
class BigEndianOutputBitStream; class BigEndianOutputBitStream;
class Bitmap; class Bitmap;
@ -198,6 +200,7 @@ using AK::String;
using AK::StringBuilder; using AK::StringBuilder;
using AK::StringImpl; using AK::StringImpl;
using AK::StringView; using AK::StringView;
using AK::TrailingCodePointTransformation;
using AK::Traits; using AK::Traits;
using AK::UnixDateTime; using AK::UnixDateTime;
using AK::URL; using AK::URL;

View file

@ -95,7 +95,7 @@ public:
// Creates a new String by case-transforming this String. Using these methods require linking LibUnicode into your application. // Creates a new String by case-transforming this String. Using these methods require linking LibUnicode into your application.
ErrorOr<String> to_lowercase(Optional<StringView> const& locale = {}) const; ErrorOr<String> to_lowercase(Optional<StringView> const& locale = {}) const;
ErrorOr<String> to_uppercase(Optional<StringView> const& locale = {}) const; ErrorOr<String> to_uppercase(Optional<StringView> const& locale = {}) const;
ErrorOr<String> to_titlecase(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_casefold() const;
// Compare this String against another string with caseless matching. Using this method requires linking LibUnicode into your application. // Compare this String against another string with caseless matching. Using this method requires linking LibUnicode into your application.

View file

@ -54,6 +54,13 @@ enum class SplitBehavior : unsigned {
}; };
AK_ENUM_BITWISE_OPERATORS(SplitBehavior); 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 { struct MaskSpan {
size_t start; size_t start;
size_t length; size_t length;
@ -117,6 +124,7 @@ size_t count(StringView, char needle);
using AK::CaseSensitivity; using AK::CaseSensitivity;
using AK::ReplaceMode; using AK::ReplaceMode;
using AK::SplitBehavior; using AK::SplitBehavior;
using AK::TrailingCodePointTransformation;
using AK::TrimMode; using AK::TrimMode;
using AK::TrimWhitespace; using AK::TrimWhitespace;
#endif #endif

View file

@ -34,13 +34,6 @@ struct BlockName {
StringView display_name; 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<DeprecatedString> code_point_display_name(u32 code_point); Optional<DeprecatedString> code_point_display_name(u32 code_point);
Optional<StringView> code_point_block_display_name(u32 code_point); Optional<StringView> code_point_block_display_name(u32 code_point);
Optional<StringView> code_point_abbreviation(u32 code_point); Optional<StringView> code_point_abbreviation(u32 code_point);

View file

@ -19,7 +19,6 @@ enum class Property : u8;
enum class Script : u8; enum class Script : u8;
enum class SentenceBreakProperty : u8; enum class SentenceBreakProperty : u8;
enum class WordBreakProperty : u8; enum class WordBreakProperty : u8;
enum class TrailingCodePointTransformation : u8;
struct CodePointDecomposition; struct CodePointDecomposition;
struct CurrencyCode; struct CurrencyCode;

View file

@ -28,10 +28,10 @@ ErrorOr<String> String::to_uppercase(Optional<StringView> const& locale) const
return builder.to_string(); return builder.to_string();
} }
ErrorOr<String> String::to_titlecase(Optional<StringView> const& locale) const ErrorOr<String> String::to_titlecase(Optional<StringView> const& locale, TrailingCodePointTransformation trailing_code_point_transformation) const
{ {
StringBuilder builder; 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(); return builder.to_string();
} }