MCPcopy Create free account
hub / github.com/OpenDriveLab/OpenLane / print_string_ptr

Function print_string_ptr

eval/LANE_evaluation/lane2d/src/cJSON.c:345–411  ·  view source on GitHub ↗

Render the cstring provided to an escaped version that can be printed. */

Source from the content-addressed store, hash-verified

343
344/* Render the cstring provided to an escaped version that can be printed. */
345static char *print_string_ptr(const char *str)
346{
347 const char *ptr;
348 char *ptr2, *out;
349 int len = 0;
350 unsigned char token;
351
352 if (!str)
353 return cJSON_strdup("");
354 ptr = str;
355 while ((token = *ptr) && ++len)
356 {
357 if (strchr("\"\\\b\f\n\r\t", token))
358 len++;
359 else if (token < 32)
360 len += 5;
361 ptr++;
362 }
363
364 out = (char*) cJSON_malloc(len + 3);
365 if (!out)
366 return 0;
367
368 ptr2 = out;
369 ptr = str;
370 *ptr2++ = '\"';
371 while (*ptr)
372 {
373 if ((unsigned char) *ptr > 31 && *ptr != '\"' && *ptr != '\\')
374 *ptr2++ = *ptr++;
375 else
376 {
377 *ptr2++ = '\\';
378 switch (token = *ptr++)
379 {
380 case '\\':
381 *ptr2++ = '\\';
382 break;
383 case '\"':
384 *ptr2++ = '\"';
385 break;
386 case '\b':
387 *ptr2++ = 'b';
388 break;
389 case '\f':
390 *ptr2++ = 'f';
391 break;
392 case '\n':
393 *ptr2++ = 'n';
394 break;
395 case '\r':
396 *ptr2++ = 'r';
397 break;
398 case '\t':
399 *ptr2++ = 't';
400 break;
401 default:
402 sprintf(ptr2, "u%04x", token);

Callers 2

print_stringFunction · 0.85
print_objectFunction · 0.85

Calls 1

cJSON_strdupFunction · 0.85

Tested by

no test coverage detected