| 256 | } |
| 257 | |
| 258 | size_t utf32_length_from_utf8(const char* buf, size_t len) { |
| 259 | const int8_t* p = reinterpret_cast<const int8_t*>(buf); |
| 260 | return std::count_if(p, std::next(p, len), [](int8_t c) { |
| 261 | // -65 is 0b10111111, anything larger in two-complement's |
| 262 | // should start a new code point. |
| 263 | return c > -65; |
| 264 | }); |
| 265 | } |
| 266 | |
| 267 | size_t utf32_to_utf8(const char32_t* buf, size_t len, char* utf8_output) { |
| 268 | const uint32_t* data = reinterpret_cast<const uint32_t*>(buf); |