* strip_quotes * * (copied from bin/psql/stringutils.c - TODO: place to share FE and BE code?). * * 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 str
| 22 | * Note that the source string is overwritten in-place. |
| 23 | */ |
| 24 | extern void |
| 25 | strip_quotes(char *source, char quote, char escape, int encoding) |
| 26 | { |
| 27 | char *src; |
| 28 | char *dst; |
| 29 | |
| 30 | Assert(source); |
| 31 | Assert(quote); |
| 32 | |
| 33 | src = dst = source; |
| 34 | |
| 35 | if (*src && *src == quote) |
| 36 | src++; /* skip leading quote */ |
| 37 | |
| 38 | while (*src) |
| 39 | { |
| 40 | char c = *src; |
| 41 | int i; |
| 42 | |
| 43 | if (c == quote && src[1] == '\0') |
| 44 | break; /* skip trailing quote */ |
| 45 | else if (c == quote && src[1] == quote) |
| 46 | src++; /* process doubled quote */ |
| 47 | else if (c == escape && src[1] != '\0') |
| 48 | src++; /* process escaped character */ |
| 49 | |
| 50 | i = pg_encoding_mblen(encoding, src); |
| 51 | while (i--) |
| 52 | *dst++ = *src++; |
| 53 | } |
| 54 | |
| 55 | *dst = '\0'; |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | * strtokx2 |
no test coverage detected