MCPcopy Create free account
hub / github.com/DaveGamble/cJSON / print_string_ptr

Function print_string_ptr

cJSON.c:949–1068  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

947
948/* Render the cstring provided to an escaped version that can be printed. */
949static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer)
950{
951 const unsigned char *input_pointer = NULL;
952 unsigned char *output = NULL;
953 unsigned char *output_pointer = NULL;
954 size_t output_length = 0;
955 /* numbers of additional characters needed for escaping */
956 size_t escape_characters = 0;
957
958 if (output_buffer == NULL)
959 {
960 return false;
961 }
962
963 /* empty string */
964 if (input == NULL)
965 {
966 output = ensure(output_buffer, sizeof("\"\""));
967 if (output == NULL)
968 {
969 return false;
970 }
971 strcpy((char*)output, "\"\"");
972
973 return true;
974 }
975
976 /* set "flag" to 1 if something needs to be escaped */
977 for (input_pointer = input; *input_pointer; input_pointer++)
978 {
979 switch (*input_pointer)
980 {
981 case '\"':
982 case '\\':
983 case '\b':
984 case '\f':
985 case '\n':
986 case '\r':
987 case '\t':
988 /* one character escape sequence */
989 escape_characters++;
990 break;
991 default:
992 if (*input_pointer < 32)
993 {
994 /* UTF-16 escape sequence uXXXX */
995 escape_characters += 5;
996 }
997 break;
998 }
999 }
1000 output_length = (size_t)(input_pointer - input) + escape_characters;
1001
1002 output = ensure(output_buffer, output_length + sizeof("\"\""));
1003 if (output == NULL)
1004 {
1005 return false;
1006 }

Callers 3

print_stringFunction · 0.85
print_objectFunction · 0.85
assert_print_stringFunction · 0.85

Calls 1

ensureFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…