* SplitGUCList --- parse a string containing identifiers or file names * * This is used to split the value of a GUC_LIST_QUOTE GUC variable, without * presuming whether the elements will be taken as identifiers or file names. * See comparable code in src/backend/utils/adt/varlena.c. * * Inputs: * rawstring: the input string; must be overwritable! On return, it's * been modified to con
| 871 | * Returns true if okay, false if there is a syntax error in the string. |
| 872 | */ |
| 873 | bool |
| 874 | SplitGUCList(char *rawstring, char separator, |
| 875 | char ***namelist) |
| 876 | { |
| 877 | char *nextp = rawstring; |
| 878 | bool done = false; |
| 879 | char **nextptr; |
| 880 | |
| 881 | /* |
| 882 | * Since we disallow empty identifiers, this is a conservative |
| 883 | * overestimate of the number of pointers we could need. Allow one for |
| 884 | * list terminator. |
| 885 | */ |
| 886 | *namelist = nextptr = (char **) |
| 887 | pg_malloc((strlen(rawstring) / 2 + 2) * sizeof(char *)); |
| 888 | *nextptr = NULL; |
| 889 | |
| 890 | while (isspace((unsigned char) *nextp)) |
| 891 | nextp++; /* skip leading whitespace */ |
| 892 | |
| 893 | if (*nextp == '\0') |
| 894 | return true; /* allow empty string */ |
| 895 | |
| 896 | /* At the top of the loop, we are at start of a new identifier. */ |
| 897 | do |
| 898 | { |
| 899 | char *curname; |
| 900 | char *endp; |
| 901 | |
| 902 | if (*nextp == '"') |
| 903 | { |
| 904 | /* Quoted name --- collapse quote-quote pairs */ |
| 905 | curname = nextp + 1; |
| 906 | for (;;) |
| 907 | { |
| 908 | endp = strchr(nextp + 1, '"'); |
| 909 | if (endp == NULL) |
| 910 | return false; /* mismatched quotes */ |
| 911 | if (endp[1] != '"') |
| 912 | break; /* found end of quoted name */ |
| 913 | /* Collapse adjacent quotes into one quote, and look again */ |
| 914 | memmove(endp, endp + 1, strlen(endp)); |
| 915 | nextp = endp; |
| 916 | } |
| 917 | /* endp now points at the terminating quote */ |
| 918 | nextp = endp + 1; |
| 919 | } |
| 920 | else |
| 921 | { |
| 922 | /* Unquoted name --- extends to separator or whitespace */ |
| 923 | curname = nextp; |
| 924 | while (*nextp && *nextp != separator && |
| 925 | !isspace((unsigned char) *nextp)) |
| 926 | nextp++; |
| 927 | endp = nextp; |
| 928 | if (curname == nextp) |
| 929 | return false; /* empty unquoted name not allowed */ |
| 930 | } |
no test coverage detected