mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +00:00
LibWeb: Implement text-transform: capitalize
This commit is contained in:
parent
9f7cfb1394
commit
bbfe0d3a82
Notes:
sideshowbarker
2024-07-17 03:19:14 +09:00
Author: https://github.com/Cr4xy
Commit: bbfe0d3a82
Pull-request: https://github.com/SerenityOS/serenity/pull/21266
Reviewed-by: https://github.com/trflynn89 ✅
7 changed files with 27 additions and 9 deletions
|
@ -266,7 +266,7 @@ ErrorOr<void> build_uppercase_string([[maybe_unused]] Utf8View code_points, [[ma
|
|||
}
|
||||
|
||||
// https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G34078
|
||||
ErrorOr<void> build_titlecase_string([[maybe_unused]] Utf8View code_points, [[maybe_unused]] StringBuilder& builder, [[maybe_unused]] Optional<StringView> const& locale)
|
||||
ErrorOr<void> build_titlecase_string([[maybe_unused]] Utf8View code_points, [[maybe_unused]] StringBuilder& builder, [[maybe_unused]] Optional<StringView> const& locale, TrailingCodePointTransformation trailing_code_point_transformation)
|
||||
{
|
||||
#if ENABLE_UNICODE_DATA
|
||||
// toTitlecase(X): Find the word boundaries in X according to Unicode Standard Annex #29,
|
||||
|
@ -317,8 +317,15 @@ ErrorOr<void> build_titlecase_string([[maybe_unused]] Utf8View code_points, [[ma
|
|||
boundary = code_point_offset + code_point_length;
|
||||
}
|
||||
|
||||
auto substring_to_lowercase = code_points.substring_view(boundary, *next_boundary - boundary);
|
||||
TRY(build_lowercase_string(substring_to_lowercase, builder, locale));
|
||||
auto remaining_code_points = code_points.substring_view(boundary, *next_boundary - boundary);
|
||||
switch (trailing_code_point_transformation) {
|
||||
case TrailingCodePointTransformation::Lowercase:
|
||||
TRY(build_lowercase_string(remaining_code_points, builder, locale));
|
||||
break;
|
||||
case TrailingCodePointTransformation::PreserveExisting:
|
||||
TRY(builder.try_append(remaining_code_points.as_string()));
|
||||
break;
|
||||
}
|
||||
|
||||
boundary = *next_boundary;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue