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

Function append_quoted

src/mcp/compact_out.c:163–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163static void append_quoted(cbm_sb_t *sb, const char *s) {
164 cbm_sb_append_n(sb, "\"", 1);
165 for (const char *p = s ? s : ""; *p; p++) {
166 switch (*p) {
167 case '"':
168 cbm_sb_append_n(sb, "\\\"", 2);
169 break;
170 case '\\':
171 cbm_sb_append_n(sb, "\\\\", 2);
172 break;
173 case '\n':
174 cbm_sb_append_n(sb, "\\n", 2);
175 break;
176 case '\r':
177 cbm_sb_append_n(sb, "\\r", 2);
178 break;
179 default: {
180 unsigned char c = (unsigned char)*p;
181 if (c >= 0x20 && c != 0x7f && c < 0x80) {
182 cbm_sb_append_n(sb, p, 1);
183 } else if (c < 0x20 || c == 0x7f) {
184 /* JSON-style escape: the value stays one printable line. */
185 char esc[8];
186 snprintf(esc, sizeof(esc), "\\u%04x", (unsigned)c);
187 cbm_sb_append(sb, esc);
188 } else {
189 size_t len = utf8_sequence_length((const unsigned char *)p);
190 if (len) {
191 cbm_sb_append_n(sb, p, len);
192 p += len - 1;
193 } else {
194 /* Invalid byte → U+FFFD: output is valid UTF-8 by
195 * construction, and the corruption stays visible. */
196 cbm_sb_append_n(sb, "\xEF\xBF\xBD", 3);
197 }
198 }
199 break;
200 }
201 }
202 }
203 cbm_sb_append_n(sb, "\"", 1);
204}
205
206static void append_value(cbm_sb_t *sb, const char *s) {
207 if (!s || !*s) {

Callers 1

append_valueFunction · 0.85

Calls 3

cbm_sb_append_nFunction · 0.85
cbm_sb_appendFunction · 0.85
utf8_sequence_lengthFunction · 0.85

Tested by

no test coverage detected