MCPcopy Create free account
hub / github.com/Entware/Entware / escape_string_value

Function escape_string_value

scripts/config/confdata.c:649–689  ·  view source on GitHub ↗

The returned pointer must be freed on the caller side */

Source from the content-addressed store, hash-verified

647
648/* The returned pointer must be freed on the caller side */
649static char *escape_string_value(const char *in)
650{
651 const char *p;
652 char *out;
653 size_t len;
654
655 len = strlen(in) + strlen("\"\"") + 1;
656
657 p = in;
658 while (1) {
659 p += strcspn(p, "\"\\");
660
661 if (p[0] == '\0')
662 break;
663
664 len++;
665 p++;
666 }
667
668 out = xmalloc(len);
669 out[0] = '\0';
670
671 strcat(out, "\"");
672
673 p = in;
674 while (1) {
675 len = strcspn(p, "\"\\");
676 strncat(out, p, len);
677 p += len;
678
679 if (p[0] == '\0')
680 break;
681
682 strcat(out, "\\");
683 strncat(out, p++, 1);
684 }
685
686 strcat(out, "\"");
687
688 return out;
689}
690
691enum output_n { OUTPUT_N, OUTPUT_N_AS_UNSET, OUTPUT_N_NONE };
692

Callers 3

__print_symbolFunction · 0.85
print_symbol_for_cFunction · 0.85

Calls 1

xmallocFunction · 0.85

Tested by

no test coverage detected