mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 15:16:14 +00: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:
committed by
Andreas Kling
parent
5978caf96b
commit
c16aca7abf
@@ -12,6 +12,7 @@
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Utf16View.h>
|
||||
#include <AK/Utf32View.h>
|
||||
|
||||
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)
|
||||
{
|
||||
for (size_t i = 0; i < utf32_view.length(); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user