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

Function utf8_trim_partial_tail

internal/cbm/extract_defs.c:6886–6903  ·  view source on GitHub ↗

Drop a trailing PARTIAL UTF-8 sequence left behind by a byte-length cut, so * a capped prose value never ends mid-codepoint (#1017's rule, applied to the * prose bodies below rather than to comments). */

Source from the content-addressed store, hash-verified

6884 * a capped prose value never ends mid-codepoint (#1017's rule, applied to the
6885 * prose bodies below rather than to comments). */
6886static void utf8_trim_partial_tail(char *text) {
6887 size_t n = strlen(text);
6888 if (n == 0) {
6889 return;
6890 }
6891 size_t i = n;
6892 while (i > 0 && ((unsigned char)text[i - UTF8_LEN_1] & UTF8_CONT_MASK) == UTF8_CONT_MARK) {
6893 i--;
6894 }
6895 if (i == 0) {
6896 text[0] = '\0'; /* continuation bytes only — not decodable */
6897 return;
6898 }
6899 size_t need = utf8_sequence_len((unsigned char)text[i - UTF8_LEN_1]);
6900 if (i - UTF8_LEN_1 + need > n) {
6901 text[i - UTF8_LEN_1] = '\0';
6902 }
6903}
6904
6905/* Collapse `len` bytes of raw prose into a single-spaced value capped at
6906 * MAX_COMMENT_LEN (500 bytes, which leaves room inside the 2 KB properties

Callers 1

collapse_proseFunction · 0.85

Calls 1

utf8_sequence_lenFunction · 0.70

Tested by

no test coverage detected