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

Function cbm_json_escape

src/foundation/str_util.c:313–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311}
312
313int cbm_json_escape(char *buf, int bufsize, const char *src) {
314 if (!buf || bufsize <= 0) {
315 return 0;
316 }
317 if (!src) {
318 buf[0] = '\0';
319 return 0;
320 }
321 int pos = 0;
322 for (int i = 0; src[i] && pos < bufsize - JSON_NUL_RESERVE; i++) {
323 unsigned char c = (unsigned char)src[i];
324 if (c == '"' || c == '\\') {
325 if (pos + JSON_ESC_LEN > bufsize - JSON_NUL_RESERVE) {
326 break;
327 }
328 buf[pos++] = '\\';
329 buf[pos++] = (char)c;
330 } else if (c == '\n') {
331 if (pos + JSON_ESC_LEN > bufsize - JSON_NUL_RESERVE) {
332 break;
333 }
334 buf[pos++] = '\\';
335 buf[pos++] = 'n';
336 } else if (c == '\r') {
337 if (pos + JSON_ESC_LEN > bufsize - JSON_NUL_RESERVE) {
338 break;
339 }
340 buf[pos++] = '\\';
341 buf[pos++] = 'r';
342 } else if (c == '\t') {
343 if (pos + JSON_ESC_LEN > bufsize - JSON_NUL_RESERVE) {
344 break;
345 }
346 buf[pos++] = '\\';
347 buf[pos++] = 't';
348 } else if (c < JSON_CTRL_LIMIT) {
349 /* Other control chars: escape as \u00XX */
350 if (pos + 6 > bufsize - JSON_NUL_RESERVE) {
351 break;
352 }
353 pos += snprintf(buf + pos, 7, "\\u%04x", c);
354 } else {
355 buf[pos++] = (char)c;
356 }
357 }
358 buf[pos] = '\0';
359 return pos;
360}

Callers 15

json_append_stringFunction · 0.85
handle_repo_infoFunction · 0.85
handle_browseFunction · 0.85
handle_index_startFunction · 0.85
handle_index_statusFunction · 0.85
calls_append_argsFunction · 0.85
emit_http_async_edgeFunction · 0.85
emit_classified_edgeFunction · 0.85
insert_def_into_gbufFunction · 0.85
create_imports_edgesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected