mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +03:00
AK+Kernel: Add StringBuilder::append overload for UTF-16 views
Currently, to append a UTF-16 view to a StringBuilder, callers must first convert the view to UTF-8 and then append the copy. Add a UTF-16 overload so callers do not need to hold an entire copy in memory.
This commit is contained in:
parent
5978caf96b
commit
c16aca7abf
Notes:
sideshowbarker
2024-07-18 07:08:30 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/c16aca7abf8 Pull-request: https://github.com/SerenityOS/serenity/pull/9320 Reviewed-by: https://github.com/davidot ✅
@ -12,6 +12,7 @@
|
|||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <AK/Utf16View.h>
|
||||||
#include <AK/Utf32View.h>
|
#include <AK/Utf32View.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
@ -112,6 +113,16 @@ void StringBuilder::append_code_point(u32 code_point)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StringBuilder::append(Utf16View const& utf16_view)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < utf16_view.length_in_code_units();) {
|
||||||
|
auto code_point = utf16_view.code_point_at(i);
|
||||||
|
append_code_point(code_point);
|
||||||
|
|
||||||
|
i += (code_point > 0xffff ? 2 : 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void StringBuilder::append(Utf32View const& utf32_view)
|
void StringBuilder::append(Utf32View const& utf32_view)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < utf32_view.length(); ++i) {
|
for (size_t i = 0; i < utf32_view.length(); ++i) {
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
~StringBuilder() = default;
|
~StringBuilder() = default;
|
||||||
|
|
||||||
void append(StringView const&);
|
void append(StringView const&);
|
||||||
|
void append(Utf16View const&);
|
||||||
void append(Utf32View const&);
|
void append(Utf32View const&);
|
||||||
void append(char);
|
void append(char);
|
||||||
void append_code_point(u32);
|
void append_code_point(u32);
|
||||||
|
@ -312,6 +312,8 @@ set(AK_SOURCES
|
|||||||
../AK/Time.cpp
|
../AK/Time.cpp
|
||||||
../AK/Format.cpp
|
../AK/Format.cpp
|
||||||
../AK/UUID.cpp
|
../AK/UUID.cpp
|
||||||
|
../AK/Utf8View.cpp
|
||||||
|
../AK/Utf16View.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(ELF_SOURCES
|
set(ELF_SOURCES
|
||||||
|
Loading…
Reference in New Issue
Block a user