forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibUnicode+LibWeb: Rework
bidirectional_class()
API a bit
Before this commit, GenerateUnicodeData generated a `BidirectionalClass` enum directly from UnicodeData.txt. Now, GenerateUnicodeData instead generates `BidirectionalClassInternal` and CharacterTypes.h has an explicit enum `BidiClass` with nicer names -- no underscores, but also names more similar to ICUs names. (Since CharacterTypes.h is included in some of LibUnicode's generators, it can't refer to generated `BidirectionalClassInternal`, so we instead have a big manual mapping switch in UnicodeData.cpp.) `bidirectional_class()` used to return an `Optional<BidirectionalClass>` for when unicode data was disabled. Now we return `BidiClass` and just return `BidiClass::LeftToRight` instead of making every client do this. It also updates LibWeb's Element.cpp to this new system. Also remove now-unused `bidirectional_class_from_string()`. This kind of cherry-picks the 4th commit of LadybirdBrowser/ladybird#239 (aa3a30870b58c47cb37bce1418d7e6bee7af71d9): The CharacterTypes.h, Element.cpp and TestUnicodeCharacterTypes.cpp changes are by trflynn. Co-authored-by: Tim Flynn <[email protected]>
- Loading branch information
Showing
6 changed files
with
113 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2021, Tim Flynn <[email protected]> | ||
* Copyright (c) 2021-2024, Tim Flynn <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
@@ -416,25 +416,13 @@ TEST_CASE(code_point_display_name) | |
|
||
TEST_CASE(code_point_bidirectional_character_type) | ||
{ | ||
auto code_point_bidi_class = [](u32 code_point) { | ||
auto bidi_class = Unicode::bidirectional_class(code_point); | ||
VERIFY(bidi_class.has_value()); | ||
return bidi_class.release_value(); | ||
}; | ||
|
||
auto bidi_class_from_string = [](StringView name) { | ||
auto result = Unicode::bidirectional_class_from_string(name); | ||
VERIFY(result.has_value()); | ||
return result.release_value(); | ||
}; | ||
|
||
// Left-to-right | ||
EXPECT_EQ(code_point_bidi_class('A'), bidi_class_from_string("L"sv)); | ||
EXPECT_EQ(code_point_bidi_class('z'), bidi_class_from_string("L"sv)); | ||
EXPECT_EQ(Unicode::bidirectional_class('A'), Unicode::BidiClass::LeftToRight); | ||
EXPECT_EQ(Unicode::bidirectional_class('z'), Unicode::BidiClass::LeftToRight); | ||
// European number | ||
EXPECT_EQ(code_point_bidi_class('7'), bidi_class_from_string("EN"sv)); | ||
EXPECT_EQ(Unicode::bidirectional_class('7'), Unicode::BidiClass::EuropeanNumber); | ||
// Whitespace | ||
EXPECT_EQ(code_point_bidi_class(' '), bidi_class_from_string("WS"sv)); | ||
EXPECT_EQ(Unicode::bidirectional_class(' '), Unicode::BidiClass::WhiteSpaceNeutral); | ||
// Arabic right-to-left (U+FEB4 ARABIC LETTER SEEN MEDIAL FORM) | ||
EXPECT_EQ(code_point_bidi_class(0xFEB4), bidi_class_from_string("AL"sv)); | ||
EXPECT_EQ(Unicode::bidirectional_class(0xFEB4), Unicode::BidiClass::RightToLeftArabic); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters