MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / text_decode_utf8

Function text_decode_utf8

src/cli/config_text_edit.c:167–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167static int text_decode_utf8(const unsigned char *text, size_t remaining, uint32_t *codepoint,
168 size_t *byte_count) {
169 if (!text || !codepoint || !byte_count || remaining == 0U) {
170 return TEXT_ERROR;
171 }
172 unsigned char first = text[0];
173 if (first <= 0x7fU) {
174 *codepoint = first;
175 *byte_count = 1U;
176 return TEXT_OK;
177 }
178
179 size_t count;
180 uint32_t value;
181 uint32_t minimum;
182 if (first >= 0xc2U && first <= 0xdfU) {
183 count = 2U;
184 value = first & 0x1fU;
185 minimum = 0x80U;
186 } else if (first >= 0xe0U && first <= 0xefU) {
187 count = 3U;
188 value = first & 0x0fU;
189 minimum = 0x800U;
190 } else if (first >= 0xf0U && first <= 0xf4U) {
191 count = 4U;
192 value = first & 0x07U;
193 minimum = 0x10000U;
194 } else {
195 return TEXT_ERROR;
196 }
197 if (count > remaining) {
198 return TEXT_ERROR;
199 }
200 for (size_t i = 1U; i < count; i++) {
201 unsigned char next = text[i];
202 if ((next & 0xc0U) != 0x80U) {
203 return TEXT_ERROR;
204 }
205 value = (value << 6U) | (uint32_t)(next & 0x3fU);
206 }
207 if (value < minimum || value > 0x10ffffU || (value >= 0xd800U && value <= 0xdfffU)) {
208 return TEXT_ERROR;
209 }
210 *codepoint = value;
211 *byte_count = count;
212 return TEXT_OK;
213}
214
215static int text_validate_bytes(const char *data, size_t len, int allow_initial_bom) {
216 if (!data && len != 0U) {

Callers 1

text_validate_bytesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected