1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

AK: Allow constructing a UTF-16 view from a UTF-16 string literal

UTF-16 string literals are a language-level feature. It is convenient to
be able to construct a Utf16View from these strings.
This commit is contained in:
Timothy Flynn 2024-01-03 13:16:37 -05:00 committed by Andreas Kling
parent e16345555b
commit c46ba7e68d
2 changed files with 38 additions and 0 deletions

View file

@ -71,6 +71,14 @@ public:
{
}
template<size_t Size>
Utf16View(char16_t const (&code_units)[Size])
: m_code_units(
reinterpret_cast<u16 const*>(&code_units[0]),
code_units[Size - 1] == u'\0' ? Size - 1 : Size)
{
}
bool operator==(Utf16View const& other) const { return m_code_units == other.m_code_units; }
enum class AllowInvalidCodeUnits {