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

Function utf8_sequence_len

src/mcp/mcp.c:12930–12964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12928}
12929
12930static size_t utf8_sequence_len(const unsigned char *p, const unsigned char *end) {
12931 size_t remaining = (size_t)(end - p);
12932 unsigned char c = *p;
12933 if (c < 0x80) {
12934 return 1;
12935 }
12936 if (c >= 0xC2 && c <= 0xDF && remaining >= 2 && utf8_is_cont(p[1])) {
12937 return 2;
12938 }
12939 if (c == 0xE0 && remaining >= 3 && p[1] >= 0xA0 && p[1] <= 0xBF && utf8_is_cont(p[2])) {
12940 return 3;
12941 }
12942 if (c >= 0xE1 && c <= 0xEC && remaining >= 3 && utf8_is_cont(p[1]) && utf8_is_cont(p[2])) {
12943 return 3;
12944 }
12945 if (c == 0xED && remaining >= 3 && p[1] >= 0x80 && p[1] <= 0x9F && utf8_is_cont(p[2])) {
12946 return 3;
12947 }
12948 if (c >= 0xEE && c <= 0xEF && remaining >= 3 && utf8_is_cont(p[1]) && utf8_is_cont(p[2])) {
12949 return 3;
12950 }
12951 if (c == 0xF0 && remaining >= 4 && p[1] >= 0x90 && p[1] <= 0xBF && utf8_is_cont(p[2]) &&
12952 utf8_is_cont(p[3])) {
12953 return 4;
12954 }
12955 if (c >= 0xF1 && c <= 0xF3 && remaining >= 4 && utf8_is_cont(p[1]) && utf8_is_cont(p[2]) &&
12956 utf8_is_cont(p[3])) {
12957 return 4;
12958 }
12959 if (c == 0xF4 && remaining >= 4 && p[1] >= 0x80 && p[1] <= 0x8F && utf8_is_cont(p[2]) &&
12960 utf8_is_cont(p[3])) {
12961 return 4;
12962 }
12963 return 0;
12964}
12965
12966static char *sanitize_utf8_lossy(const char *s) {
12967 enum { UTF8_REPLACEMENT_LEN = 3 };

Callers 3

sanitize_utf8_lossyFunction · 0.70
search_utf8_page_startFunction · 0.70
search_utf8_page_endFunction · 0.70

Calls 1

utf8_is_contFunction · 0.85

Tested by

no test coverage detected