Commit bd422fbc authored by Tom Lane's avatar Tom Lane

Simplify scanstr(), fix broken octal-escape code.

parent f7c6a88c
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/scansup.c,v 1.10 1998/02/26 04:33:49 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/scansup.c,v 1.11 1999/02/07 23:59:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -29,12 +29,8 @@ ...@@ -29,12 +29,8 @@
* if the string passed in has escaped codes, map the escape codes to actual * if the string passed in has escaped codes, map the escape codes to actual
* chars * chars
* *
* also, remove leading and ending quotes '"' if any
*
* the string passed in must be non-null
*
* the string returned is a pointer to static storage and should NOT * the string returned is a pointer to static storage and should NOT
* be freed by the CALLER. * be freed by the caller.
* ---------------- * ----------------
*/ */
...@@ -55,76 +51,59 @@ scanstr(char *s) ...@@ -55,76 +51,59 @@ scanstr(char *s)
{ {
if (s[i] == '\'') if (s[i] == '\'')
{ {
i = i + 1; /* Note: if scanner is working right, unescaped quotes can only
if (s[i] == '\'') * appear in pairs, so there should be another character.
newStr[j] = '\''; */
i++;
newStr[j] = s[i];
} }
else else if (s[i] == '\\')
{ {
if (s[i] == '\\') i++;
switch (s[i])
{ {
i = i + 1; case 'b':
switch (s[i]) newStr[j] = '\b';
{ break;
case '\\': case 'f':
newStr[j] = '\\'; newStr[j] = '\f';
break; break;
case 'b': case 'n':
newStr[j] = '\b'; newStr[j] = '\n';
break; break;
case 'f': case 'r':
newStr[j] = '\f'; newStr[j] = '\r';
break; break;
case 'n': case 't':
newStr[j] = '\n'; newStr[j] = '\t';
break; break;
case 'r': case '0':
newStr[j] = '\r'; case '1':
break; case '2':
case 't': case '3':
newStr[j] = '\t'; case '4':
break; case '5':
case '"': case '6':
newStr[j] = '"'; case '7':
break; {
case '\'': int k;
newStr[j] = '\''; long octVal = 0;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
{
char octal[4];
int k;
long octVal;
for (k = 0; for (k = 0;
s[i + k] >= '0' && s[i + k] <= '7' && k < 3; s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
k++) k++)
octal[k] = s[i + k]; octVal = (octVal << 3) + (s[i + k] - '0');
i += k - 1; i += k - 1;
octal[3] = '\0'; newStr[j] = ((char) octVal);
}
octVal = strtol(octal, 0, 8); break;
/* elog (NOTICE, "octal = %s octVal = %d, %od", octal, octVal, octVal);*/ default:
if (octVal <= 0377) newStr[j] = s[i];
{ break;
newStr[j] = ((char) octVal); } /* switch */
break; } /* s[i] == '\\' */
} else
} newStr[j] = s[i];
default:
newStr[j] = s[i];
} /* switch */
} /* s[i] == '\\' */
else
newStr[j] = s[i];
}
j++; j++;
} }
newStr[j] = '\0'; newStr[j] = '\0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment