| 11 | namespace devilution { |
| 12 | |
| 13 | char32_t DecodeFirstUtf8CodePoint(string_view input, std::size_t *len) |
| 14 | { |
| 15 | uint32_t codepoint = 0; |
| 16 | uint8_t state = UTF8_ACCEPT; |
| 17 | for (std::size_t i = 0; i < input.size(); ++i) { |
| 18 | state = utf8_decode_step(state, static_cast<uint8_t>(input[i]), &codepoint); |
| 19 | if (state == UTF8_ACCEPT) { |
| 20 | *len = i + 1; |
| 21 | return codepoint; |
| 22 | } |
| 23 | if (state == UTF8_REJECT) { |
| 24 | *len = i + 1; |
| 25 | return Utf8DecodeError; |
| 26 | } |
| 27 | } |
| 28 | *len = input.size(); |
| 29 | return Utf8DecodeError; |
| 30 | } |
| 31 | |
| 32 | string_view TruncateUtf8(string_view str, std::size_t len) |
| 33 | { |
no test coverage detected