MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / print_string_ptr

Function print_string_ptr

libapp2sys/src/main/cpp/cjson/cJSON.c:829–949  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

827
828/* Render the cstring provided to an escaped version that can be printed. */
829static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer)
830{
831 const unsigned char *input_pointer = NULL;
832 unsigned char *output = NULL;
833 unsigned char *output_pointer = NULL;
834 size_t output_length = 0;
835 /* numbers of additional characters needed for escaping */
836 size_t escape_characters = 0;
837
838 if (output_buffer == NULL)
839 {
840 return false;
841 }
842
843 /* empty string */
844 if (input == NULL)
845 {
846 output = ensure(output_buffer, sizeof("\"\""));
847 if (output == NULL)
848 {
849 return false;
850 }
851
852 strncpy((char*)output, "\"\"", sizeof("\"\""));
853
854 return true;
855 }
856
857 /* set "flag" to 1 if something needs to be escaped */
858 for (input_pointer = input; *input_pointer; input_pointer++)
859 {
860 switch (*input_pointer)
861 {
862 case '\"':
863 case '\\':
864 case '\b':
865 case '\f':
866 case '\n':
867 case '\r':
868 case '\t':
869 /* one character escape sequence */
870 escape_characters++;
871 break;
872 default:
873 if (*input_pointer < 32)
874 {
875 /* UTF-16 escape sequence uXXXX */
876 escape_characters += 5;
877 }
878 break;
879 }
880 }
881 output_length = (size_t)(input_pointer - input) + escape_characters;
882
883 output = ensure(output_buffer, output_length + sizeof("\"\""));
884 if (output == NULL)
885 {
886 return false;

Callers 2

print_stringFunction · 0.85
print_objectFunction · 0.85

Calls 1

ensureFunction · 0.85

Tested by

no test coverage detected