| 78 | } |
| 79 | |
| 80 | bool decode_codepoint(std::string_view text, size_t offset, uint32_t & codepoint, size_t & len) { |
| 81 | if (offset >= text.size()) { |
| 82 | return false; |
| 83 | } |
| 84 | const unsigned char ch = static_cast<unsigned char>(text[offset]); |
| 85 | len = 1; |
| 86 | if ((ch & 0x80U) == 0) { |
| 87 | codepoint = ch; |
| 88 | } else if ((ch & 0xE0U) == 0xC0U && offset + 1 < text.size()) { |
| 89 | len = 2; |
| 90 | codepoint = ((static_cast<uint32_t>(ch) & 0x1FU) << 6) | |
| 91 | (static_cast<uint32_t>(static_cast<unsigned char>(text[offset + 1])) & 0x3FU); |
| 92 | } else if ((ch & 0xF0U) == 0xE0U && offset + 2 < text.size()) { |
| 93 | len = 3; |
| 94 | codepoint = ((static_cast<uint32_t>(ch) & 0x0FU) << 12) | |
| 95 | ((static_cast<uint32_t>(static_cast<unsigned char>(text[offset + 1])) & 0x3FU) << 6) | |
| 96 | (static_cast<uint32_t>(static_cast<unsigned char>(text[offset + 2])) & 0x3FU); |
| 97 | } else if ((ch & 0xF8U) == 0xF0U && offset + 3 < text.size()) { |
| 98 | len = 4; |
| 99 | codepoint = ((static_cast<uint32_t>(ch) & 0x07U) << 18) | |
| 100 | ((static_cast<uint32_t>(static_cast<unsigned char>(text[offset + 1])) & 0x3FU) << 12) | |
| 101 | ((static_cast<uint32_t>(static_cast<unsigned char>(text[offset + 2])) & 0x3FU) << 6) | |
| 102 | (static_cast<uint32_t>(static_cast<unsigned char>(text[offset + 3])) & 0x3FU); |
| 103 | } else { |
| 104 | throw std::runtime_error("OmniVoice prompt builder encountered invalid UTF-8"); |
| 105 | } |
| 106 | return true; |
| 107 | } |
| 108 | |
| 109 | std::string lowercase_ascii(std::string_view text) { |
| 110 | std::string out(text); |
no test coverage detected