mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
AK: Remove null state from Utf16View
The default constructor now initializes to an empty ASCII string rather than a null pointer. Also add a VERIFY in the utf16 constructor to assert the pointer is non null, and remove the now unneeded is_null() method.
This commit is contained in:
committed by
Sam Atkins
parent
a066ee720e
commit
7ab9454f51
Notes:
github-actions[bot]
2026-03-31 12:50:11 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/7ab9454f51a Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8694 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/gmta ✅
@@ -151,13 +151,17 @@ class Utf16View {
|
||||
public:
|
||||
using Iterator = Utf16CodePointIterator;
|
||||
|
||||
Utf16View() = default;
|
||||
constexpr Utf16View()
|
||||
: m_string { .ascii = "" }
|
||||
{
|
||||
}
|
||||
~Utf16View() = default;
|
||||
|
||||
constexpr Utf16View(char16_t const* string, size_t length_in_code_units)
|
||||
: m_string { .utf16 = string }
|
||||
, m_length_in_code_units(length_in_code_units)
|
||||
{
|
||||
VERIFY(string != nullptr);
|
||||
m_length_in_code_units |= 1uz << Detail::UTF16_FLAG;
|
||||
}
|
||||
|
||||
@@ -326,13 +330,6 @@ public:
|
||||
return string_hash(m_string.utf16, length_in_code_units());
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool is_null() const
|
||||
{
|
||||
if (has_ascii_storage())
|
||||
return m_string.ascii == nullptr;
|
||||
return m_string.utf16 == nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool is_empty() const { return length_in_code_units() == 0; }
|
||||
|
||||
[[nodiscard]] bool is_ascii() const;
|
||||
|
||||
@@ -99,6 +99,15 @@ TEST_CASE(null_view)
|
||||
FAIL("Iterating a null UTF-16 string should not produce any values");
|
||||
}
|
||||
|
||||
TEST_CASE(default_empty_view_is_empty_ascii_string)
|
||||
{
|
||||
Utf16View view;
|
||||
EXPECT(view.has_ascii_storage());
|
||||
EXPECT_EQ(view.ascii_span().data(), "");
|
||||
EXPECT_EQ(view.length_in_code_units(), 0zu);
|
||||
EXPECT_EQ(view, ""sv);
|
||||
}
|
||||
|
||||
TEST_CASE(utf16_literal)
|
||||
{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user