Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-05 04:50:09 +03:00
parent 8653b02c44
commit 1414a66e56
6 changed files with 226 additions and 173 deletions

View File

@@ -11,26 +11,27 @@ using i64 = std::int64_t;
using usize = std::uintptr_t;
using isize = std::intptr_t;
inline auto rune_to_string(uint32_t cp) -> char const * {
static char utf8[5] = {0};
for (auto &c : utf8)
c = 0;
inline auto rune_to_string(uint32_t cp) -> char const *
{
static char utf8[5] = { 0 };
for (auto &c : utf8)
c = 0;
if (cp < 0x80) {
utf8[0] = cp;
} else if (cp < 0x800) {
utf8[0] = 0xC0 | (cp >> 6);
utf8[1] = 0x80 | (cp & 0x3F);
} else if (cp < 0x10000) {
utf8[0] = 0xE0 | (cp >> 12);
utf8[1] = 0x80 | ((cp >> 6) & 0x3F);
utf8[2] = 0x80 | (cp & 0x3F);
} else {
utf8[0] = 0xF0 | (cp >> 18);
utf8[1] = 0x80 | ((cp >> 12) & 0x3F);
utf8[2] = 0x80 | ((cp >> 6) & 0x3F);
utf8[3] = 0x80 | (cp & 0x3F);
}
if (cp < 0x80) {
utf8[0] = cp;
} else if (cp < 0x800) {
utf8[0] = 0xC0 | (cp >> 6);
utf8[1] = 0x80 | (cp & 0x3F);
} else if (cp < 0x10000) {
utf8[0] = 0xE0 | (cp >> 12);
utf8[1] = 0x80 | ((cp >> 6) & 0x3F);
utf8[2] = 0x80 | (cp & 0x3F);
} else {
utf8[0] = 0xF0 | (cp >> 18);
utf8[1] = 0x80 | ((cp >> 12) & 0x3F);
utf8[2] = 0x80 | ((cp >> 6) & 0x3F);
utf8[3] = 0x80 | (cp & 0x3F);
}
return utf8;
return utf8;
}