MCPcopy Create free account
hub / github.com/Netis/cloud-probe / print_string_ptr

Function print_string_ptr

cpworker/src/cJSON/cJSON.c:911–1030  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 2

print_stringFunction · 0.85
print_objectFunction · 0.85

Calls 1

ensureFunction · 0.85

Tested by

no test coverage detected