| 322 | } |
| 323 | |
| 324 | static inline uint8_t* UTF8Encode(uint8_t* str, uint32_t codepoint) { |
| 325 | if (codepoint < 0x80) { |
| 326 | *str++ = codepoint; |
| 327 | } else if (codepoint < 0x800) { |
| 328 | *str++ = 0xC0 + (codepoint >> 6); |
| 329 | *str++ = 0x80 + (codepoint & 0x3F); |
| 330 | } else if (codepoint < 0x10000) { |
| 331 | *str++ = 0xE0 + (codepoint >> 12); |
| 332 | *str++ = 0x80 + ((codepoint >> 6) & 0x3F); |
| 333 | *str++ = 0x80 + (codepoint & 0x3F); |
| 334 | } else { |
| 335 | // Assume proper codepoints are always passed |
| 336 | assert(codepoint < kMaxUnicodeCodepoint); |
| 337 | *str++ = 0xF0 + (codepoint >> 18); |
| 338 | *str++ = 0x80 + ((codepoint >> 12) & 0x3F); |
| 339 | *str++ = 0x80 + ((codepoint >> 6) & 0x3F); |
| 340 | *str++ = 0x80 + (codepoint & 0x3F); |
| 341 | } |
| 342 | return str; |
| 343 | } |
| 344 | |
| 345 | static inline bool UTF8Decode(const uint8_t** data, uint32_t* codepoint) { |
| 346 | const uint8_t* str = *data; |
no outgoing calls
no test coverage detected