From 9603a32594d2f5e6d9a1f098bc554a68f44ccb3c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 17 Apr 2016 11:37:58 -0400 Subject: Avoid code duplication in \crosstabview. In commit 6f0d6a507 I added a duplicate copy of psqlscanslash's identifier downcasing code, but actually it's not hard to split that out as a callable subroutine and avoid the duplication. --- src/bin/psql/crosstabview.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'src/bin/psql/crosstabview.c') diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c index 71abaf3a6fe..7685c6e7467 100644 --- a/src/bin/psql/crosstabview.c +++ b/src/bin/psql/crosstabview.c @@ -12,6 +12,7 @@ #include "common.h" #include "crosstabview.h" #include "pqexpbuffer.h" +#include "psqlscanslash.h" #include "settings.h" @@ -648,39 +649,14 @@ indexOfColumn(char *arg, const PGresult *res) } else { - bool inquotes = false; - char *cp = arg; int i; /* * Dequote and downcase the column name. By checking for all-digits * before doing this, we can ensure that a quoted name is treated as a - * name even if it's all digits. This transformation should match - * what psqlscanslash.l does in OT_SQLID mode. (XXX ideally we would - * let the lexer do this, but then we couldn't tell if the name was - * quoted.) + * name even if it's all digits. */ - while (*cp) - { - if (*cp == '"') - { - if (inquotes && cp[1] == '"') - { - /* Keep the first quote, remove the second */ - cp++; - } - inquotes = !inquotes; - /* Collapse out quote at *cp */ - memmove(cp, cp + 1, strlen(cp)); - /* do not advance cp */ - } - else - { - if (!inquotes) - *cp = pg_tolower((unsigned char) *cp); - cp += PQmblen(cp, pset.encoding); - } - } + dequote_downcase_identifier(arg, true, pset.encoding); /* Now look for match(es) among res' column names */ idx = -1; -- cgit v1.2.3