MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / decode_codepoint

Function decode_codepoint

src/models/omnivoice/prompt_builder.cpp:80–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80bool 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
109std::string lowercase_ascii(std::string_view text) {
110 std::string out(text);

Callers 2

combine_textFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected