MCPcopy Create free account
hub / github.com/esnet/iperf / print_string_ptr

Function print_string_ptr

src/cjson.c:913–1032  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

911
912/* Render the cstring provided to an escaped version that can be printed. */
913static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer)
914{
915 const unsigned char *input_pointer = NULL;
916 unsigned char *output = NULL;
917 unsigned char *output_pointer = NULL;
918 size_t output_length = 0;
919 /* numbers of additional characters needed for escaping */
920 size_t escape_characters = 0;
921
922 if (output_buffer == NULL)
923 {
924 return false;
925 }
926
927 /* empty string */
928 if (input == NULL)
929 {
930 output = ensure(output_buffer, sizeof("\"\""));
931 if (output == NULL)
932 {
933 return false;
934 }
935 strcpy((char*)output, "\"\"");
936
937 return true;
938 }
939
940 /* set "flag" to 1 if something needs to be escaped */
941 for (input_pointer = input; *input_pointer; input_pointer++)
942 {
943 switch (*input_pointer)
944 {
945 case '\"':
946 case '\\':
947 case '\b':
948 case '\f':
949 case '\n':
950 case '\r':
951 case '\t':
952 /* one character escape sequence */
953 escape_characters++;
954 break;
955 default:
956 if (*input_pointer < 32)
957 {
958 /* UTF-16 escape sequence uXXXX */
959 escape_characters += 5;
960 }
961 break;
962 }
963 }
964 output_length = (size_t)(input_pointer - input) + escape_characters;
965
966 output = ensure(output_buffer, output_length + sizeof("\"\""));
967 if (output == NULL)
968 {
969 return false;
970 }

Callers 2

print_stringFunction · 0.85
print_objectFunction · 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…