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

Function dm_utf8_ok

tests/test_doc_mentions.c:10080–10107  ·  view source on GitHub ↗

True when s[0, n) is well-formed UTF-8 (no surrogate, nothing past * U+10FFFF, no overlong form, nothing cut short). */

Source from the content-addressed store, hash-verified

10078/* True when s[0, n) is well-formed UTF-8 (no surrogate, nothing past
10079 * U+10FFFF, no overlong form, nothing cut short). */
10080static bool dm_utf8_ok(const char *s, size_t n) {
10081 const unsigned char *u = (const unsigned char *)s;
10082 for (size_t i = 0; i < n;) {
10083 unsigned char c = u[i];
10084 size_t len = c < 0x80 ? 1
10085 : (c >= 0xC2 && c <= 0xDF) ? 2
10086 : (c >= 0xE0 && c <= 0xEF) ? 3
10087 : (c >= 0xF0 && c <= 0xF4) ? 4
10088 : 0;
10089 if (len == 0 || i + len > n) {
10090 return false;
10091 }
10092 if (len > 1) {
10093 unsigned char c1 = u[i + 1];
10094 if ((c == 0xE0 && c1 < 0xA0) || (c == 0xED && c1 > 0x9F) || (c == 0xF0 && c1 < 0x90) ||
10095 (c == 0xF4 && c1 > 0x8F)) {
10096 return false;
10097 }
10098 for (size_t k = 1; k < len; k++) {
10099 if ((u[i + k] & 0xC0) != 0x80) {
10100 return false;
10101 }
10102 }
10103 }
10104 i += len;
10105 }
10106 return true;
10107}
10108
10109static bool dm_scope_utf8_ok(const char *scope) {
10110 return dm_utf8_ok(scope, strlen(scope));

Callers 2

dm_scope_utf8_okFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected