| 210 | }; |
| 211 | |
| 212 | const char *FixupString(StringInfo &data) |
| 213 | { |
| 214 | if (!data.ptr) |
| 215 | { |
| 216 | return NULL; |
| 217 | } |
| 218 | |
| 219 | if (data.quoted) |
| 220 | { |
| 221 | data.ptr++; |
| 222 | } |
| 223 | #if defined _DEBUG |
| 224 | else { |
| 225 | /* A string will never have beginning whitespace because we ignore it in the stream. |
| 226 | * Furthermore, if there is trailing whitespace, the end ptr will point to it, so it is valid |
| 227 | * to overwrite! Lastly, the last character must be whitespace or a comment/invalid character. |
| 228 | */ |
| 229 | } |
| 230 | #endif |
| 231 | |
| 232 | /* Do some extra work on strings that have special quoted characters. */ |
| 233 | if (data.special) |
| 234 | { |
| 235 | char *outptr = data.ptr; |
| 236 | size_t len = data.end - data.ptr; |
| 237 | if (len >= 2) |
| 238 | { |
| 239 | for (size_t i=0; i<len; i++) |
| 240 | { |
| 241 | if (data.ptr[i] == '\\' && i < len - 1) |
| 242 | { |
| 243 | /* Resolve the next character. */ |
| 244 | i++; |
| 245 | if (data.ptr[i] == 'n') |
| 246 | { |
| 247 | data.ptr[i] = '\n'; |
| 248 | } else if (data.ptr[i] == 't') { |
| 249 | data.ptr[i] = '\t'; |
| 250 | } else if (data.ptr[i] == 'r') { |
| 251 | data.ptr[i] = '\r'; |
| 252 | } else if (data.ptr[i] != '\\' |
| 253 | && data.ptr[i] != '"') { |
| 254 | /* This character is invalid, so go back one */ |
| 255 | i--; |
| 256 | } |
| 257 | } |
| 258 | *outptr++ = data.ptr[i]; |
| 259 | } |
| 260 | *outptr = '\0'; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | if (data.end) |
| 265 | { |
| 266 | *(data.end) = '\0'; |
| 267 | } |
| 268 | |
| 269 | return data.ptr; |