36
src/common.hpp
Normal file
36
src/common.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <cstdint>
|
||||
|
||||
using u8 = std::uint8_t;
|
||||
using i8 = std::int8_t;
|
||||
using u16 = std::uint16_t;
|
||||
using i16 = std::int16_t;
|
||||
using u32 = std::uint32_t;
|
||||
using i32 = std::int32_t;
|
||||
using u64 = std::uint64_t;
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user