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

Function text_validate_bytes

src/cli/config_text_edit.c:214–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214static int text_validate_bytes(const char *data, size_t len, int allow_initial_bom) {
215 if (!data && len != 0U) {
216 return TEXT_ERROR;
217 }
218 size_t pos = 0U;
219 while (pos < len) {
220 uint32_t codepoint = 0U;
221 size_t byte_count = 0U;
222 if (text_decode_utf8((const unsigned char *)data + pos, len - pos, &codepoint,
223 &byte_count) != TEXT_OK) {
224 return TEXT_ERROR;
225 }
226 if (codepoint == 0xfeffU) {
227 if (!(allow_initial_bom && pos == 0U && byte_count == 3U)) {
228 return TEXT_ERROR;
229 }
230 } else if (codepoint < 0x20U) {
231 if (codepoint != '\t' && codepoint != '\n' && codepoint != '\r') {
232 return TEXT_ERROR;
233 }
234 if (codepoint == '\r' && (pos + 1U >= len || data[pos + 1U] != '\n')) {
235 return TEXT_ERROR;
236 }
237 } else if (codepoint == 0x7fU || (codepoint >= 0x80U && codepoint <= 0x9fU)) {
238 return TEXT_ERROR;
239 }
240 pos += byte_count;
241 }
242 return TEXT_OK;
243}
244
245static int text_valid_path(const char *path) {
246 size_t len = 0U;

Calls 1

text_decode_utf8Function · 0.85

Tested by

no test coverage detected