diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2021-10-11 07:08:08 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-10-15 21:50:19 -0700 |
commit | fccb06b2cdbe4fa67e8f584d2f9416a11ed5bc3c (patch) | |
tree | 920d3405b9f0fb4993c663f3582800ed57dd3148 | |
parent | c8367df74639a399a2195a2a07ff7ac74b88d426 (diff) | |
download | serenity-fccb06b2cdbe4fa67e8f584d2f9416a11ed5bc3c.zip |
AK: Use UnicodeUtils::code_point_to_utf8 in StringBuilder
-rw-r--r-- | AK/StringBuilder.cpp | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 8a697f8ebc..df4331f9ca 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -12,6 +12,7 @@ #include <AK/String.h> #include <AK/StringBuilder.h> #include <AK/StringView.h> +#include <AK/UnicodeUtils.h> #include <AK/Utf16View.h> #include <AK/Utf32View.h> @@ -97,21 +98,8 @@ void StringBuilder::clear() void StringBuilder::append_code_point(u32 code_point) { - if (code_point <= 0x7f) { - append((char)code_point); - } else if (code_point <= 0x07ff) { - append((char)(((code_point >> 6) & 0x1f) | 0xc0)); - append((char)(((code_point >> 0) & 0x3f) | 0x80)); - } else if (code_point <= 0xffff) { - append((char)(((code_point >> 12) & 0x0f) | 0xe0)); - append((char)(((code_point >> 6) & 0x3f) | 0x80)); - append((char)(((code_point >> 0) & 0x3f) | 0x80)); - } else if (code_point <= 0x10ffff) { - append((char)(((code_point >> 18) & 0x07) | 0xf0)); - append((char)(((code_point >> 12) & 0x3f) | 0x80)); - append((char)(((code_point >> 6) & 0x3f) | 0x80)); - append((char)(((code_point >> 0) & 0x3f) | 0x80)); - } else { + auto nwritten = AK::UnicodeUtils::code_point_to_utf8(code_point, [this](char c) { append(c); }); + if (nwritten < 0) { append(0xef); append(0xbf); append(0xbd); |