MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / print_string_ptr

Function print_string_ptr

TheForceEngine/TFE_System/cJSON.c:907–1026  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 2

print_stringFunction · 0.85
print_objectFunction · 0.85

Calls 1

ensureFunction · 0.85

Tested by

no test coverage detected