Backslash followed by one to three octal digits specifies
the character with that numeric code
+ |
+ \x>digits>
+ Backslash x> followed by one or two hex digits specifies
+ the character with that numeric code
+
- Presently, COPY TO will never emit an octal-digits
- backslash sequence, but it does use the other sequences listed above
- for those control characters.
+ Presently, COPY TO will never emit an octal or
+ hex-digits backslash sequence, but it does use the other sequences
+ listed above for those control characters.
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.244 2005/05/07 02:22:46 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.245 2005/06/02 01:21:22 momjian Exp $
*
*-------------------------------------------------------------------------
*/
return result;
}
+/*
+ * Return decimal value for a hexadecimal digit
+ */
+static
+int GetDecimalFromHex(char hex)
+{
+ if (isdigit(hex))
+ return hex - '0';
+ else
+ return tolower(hex) - 'a' + 10;
+}
+
/*----------
* Read the value of a single attribute, performing de-escaping as needed.
*
case '5':
case '6':
case '7':
+ /* handle \013 */
{
int val;
c = val & 0377;
}
break;
+ case 'x':
+ /* Handle \x3F */
+ if (line_buf.cursor < line_buf.len)
+ {
+ char hexchar = line_buf.data[line_buf.cursor];
+
+ if (isxdigit(hexchar))
+ {
+ int val = GetDecimalFromHex(hexchar);
+
+ line_buf.cursor++;
+ if (line_buf.cursor < line_buf.len)
+ {
+ hexchar = line_buf.data[line_buf.cursor];
+ if (isxdigit(hexchar))
+ {
+ line_buf.cursor++;
+ val = (val << 4) + GetDecimalFromHex(hexchar);
+ }
+ }
+ c = val & 0xff;
+ }
+ }
+ break;
case 'b':
c = '\b';
break;