utils/utf16.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "simdb/Assert.hpp" | ||
| 4 | #include "simdb/Exceptions.hpp" | ||
| 5 | |||
| 6 | #include <cstdint> | ||
| 7 | #include <string> | ||
| 8 | |||
| 9 | namespace simdb::utils { | ||
| 10 | |||
| 11 | 3050 | inline void uint64_to_utf16(uint64_t value, char16_t* out) | |
| 12 | { | ||
| 13 | 64050 | for (int i = 19; i >= 0; --i) | |
| 14 | { | ||
| 15 | 61000 | out[i] = static_cast<char16_t>(u'0' + (value % 10)); | |
| 16 | 61000 | value /= 10; | |
| 17 | } | ||
| 18 | 3050 | } | |
| 19 | |||
| 20 | 3050 | inline std::u16string uint64_to_utf16(uint64_t value) | |
| 21 | { | ||
| 22 | 3050 | std::u16string result(20, u'0'); | |
| 23 | 3050 | uint64_to_utf16(value, &result[0]); | |
| 24 | 3050 | return result; | |
| 25 | ✗ | } | |
| 26 | |||
| 27 | 3023 | inline uint64_t utf16_to_uint64(const char16_t* str, int length) | |
| 28 | { | ||
| 29 | 3023 | simdb_assert(length == 20, "Invalid UTF-16 uint64 length"); | |
| 30 | |||
| 31 | 3023 | uint64_t value = 0; | |
| 32 | 63483 | for (int i = 0; i < 20; ++i) | |
| 33 | { | ||
| 34 | 60460 | char16_t ch = str[i]; | |
| 35 | 60460 | simdb_assert(ch >= u'0' && ch <= u'9', "Invalid digit"); | |
| 36 | 60460 | value = value * 10 + (ch - u'0'); | |
| 37 | } | ||
| 38 | |||
| 39 | 3023 | return value; | |
| 40 | } | ||
| 41 | |||
| 42 | } // namespace simdb::utils | ||
| 43 |