| 150 | /* Parse the input text into an unescaped cstring, and populate item. */ |
| 151 | static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; |
| 152 | static const char *parse_string(cJSON *item,const char *str) |
| 153 | { |
| 154 | const char *ptr=str+1; char *ptr2; char *out; int len=0; unsigned uc; |
| 155 | if (*str!='\"') {ep=str;return nullptr;} /* not a string! */ |
| 156 | |
| 157 | while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */ |
| 158 | |
| 159 | out=static_cast<char*> (cJSON_malloc(len+1)); /* This is how long we need for the string, roughly. */ |
| 160 | if (!out) return nullptr; |
| 161 | |
| 162 | ptr=str+1;ptr2=out; |
| 163 | while (*ptr!='\"' && *ptr) |
| 164 | { |
| 165 | if (*ptr!='\\') *ptr2++=*ptr++; |
| 166 | else |
| 167 | { |
| 168 | ptr++; |
| 169 | switch (*ptr) |
| 170 | { |
| 171 | case 'b': *ptr2++='\b'; break; |
| 172 | case 'f': *ptr2++='\f'; break; |
| 173 | case 'n': *ptr2++='\n'; break; |
| 174 | case 'r': *ptr2++='\r'; break; |
| 175 | case 't': *ptr2++='\t'; break; |
| 176 | case 'u': /* transcode utf16 to utf8. DOES NOT SUPPORT SURROGATE PAIRS CORRECTLY. */ |
| 177 | sscanf(ptr+1,"%4x",&uc); /* get the unicode char. */ |
| 178 | len=3;if (uc<0x80) len=1;else if (uc<0x800) len=2;ptr2+=len; |
| 179 | |
| 180 | switch (len) { |
| 181 | case 3: *--ptr2 = static_cast<char>(( (uc) | 0x80) & 0xBF ); |
| 182 | uc >>= 6; |
| 183 | PCL_FALLTHROUGH |
| 184 | case 2: *--ptr2 = static_cast<char>(( (uc) | 0x80) & 0xBF ); |
| 185 | uc >>= 6; |
| 186 | PCL_FALLTHROUGH |
| 187 | case 1: *--ptr2 = static_cast<char>( (uc) | firstByteMark[len] ); |
| 188 | } |
| 189 | ptr2+=len;ptr+=4; |
| 190 | break; |
| 191 | default: *ptr2++=*ptr; break; |
| 192 | } |
| 193 | ptr++; |
| 194 | } |
| 195 | } |
| 196 | *ptr2=0; |
| 197 | if (*ptr=='\"') ptr++; |
| 198 | item->valuestring=out; |
| 199 | item->type=cJSON_String; |
| 200 | return ptr; |
| 201 | } |
| 202 | |
| 203 | /* Render the cstring provided to an escaped version that can be printed. */ |
| 204 | static char *print_string_ptr(const char *str) |
no outgoing calls
no test coverage detected