* strip_quotes * * Remove quotes from the string at *source. Leading and trailing occurrences * of 'quote' are removed; embedded double occurrences of 'quote' are reduced * to single occurrences; if 'escape' is not 0 then 'escape' removes special * significance of next character. * * Note that the source string is overwritten in-place. */
| 237 | * Note that the source string is overwritten in-place. |
| 238 | */ |
| 239 | void |
| 240 | strip_quotes(char *source, char quote, char escape, int encoding) |
| 241 | { |
| 242 | char *src; |
| 243 | char *dst; |
| 244 | |
| 245 | Assert(source != NULL); |
| 246 | Assert(quote != '\0'); |
| 247 | |
| 248 | src = dst = source; |
| 249 | |
| 250 | if (*src && *src == quote) |
| 251 | src++; /* skip leading quote */ |
| 252 | |
| 253 | while (*src) |
| 254 | { |
| 255 | char c = *src; |
| 256 | int i; |
| 257 | |
| 258 | if (c == quote && src[1] == '\0') |
| 259 | break; /* skip trailing quote */ |
| 260 | else if (c == quote && src[1] == quote) |
| 261 | src++; /* process doubled quote */ |
| 262 | else if (c == escape && src[1] != '\0') |
| 263 | src++; /* process escaped character */ |
| 264 | |
| 265 | i = PQmblenBounded(src, encoding); |
| 266 | while (i--) |
| 267 | *dst++ = *src++; |
| 268 | } |
| 269 | |
| 270 | *dst = '\0'; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | /* |
no test coverage detected