MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / print_string_ptr

Function print_string_ptr

external/cJSON/cJSON.c:954–1073  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 2

print_stringFunction · 0.85
print_objectFunction · 0.85

Calls 1

ensureFunction · 0.85

Tested by

no test coverage detected