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

Function text_validate_bytes

src/cli/config_text_edit.c:215–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Calls 1

text_decode_utf8Function · 0.85

Tested by

no test coverage detected