mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Replace strchr with switch case
This should improve performance and improve readability.
This commit is contained in:
parent
778a0c146f
commit
c9739c59fd
16
cJSON.c
16
cJSON.c
@ -818,16 +818,26 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe
|
||||
/* set "flag" to 1 if something needs to be escaped */
|
||||
for (input_pointer = input; *input_pointer; input_pointer++)
|
||||
{
|
||||
if (strchr("\"\\\b\f\n\r\t", *input_pointer))
|
||||
switch (*input_pointer)
|
||||
{
|
||||
case '\"':
|
||||
case '\\':
|
||||
case '\b':
|
||||
case '\f':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
/* one character escape sequence */
|
||||
escape_characters++;
|
||||
}
|
||||
else if (*input_pointer < 32)
|
||||
break;
|
||||
default:
|
||||
if (*input_pointer < 32)
|
||||
{
|
||||
/* UTF-16 escape sequence uXXXX */
|
||||
escape_characters += 5;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
output_length = (size_t)(input_pointer - input) + escape_characters;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user