Add support for \x hex escapes in backend strings. Octal was already
authorBruce Momjian
Thu, 2 Jun 2005 01:23:08 +0000 (01:23 +0000)
committerBruce Momjian
Thu, 2 Jun 2005 01:23:08 +0000 (01:23 +0000)
supported.  This follows the C standard escapes.

doc/src/sgml/syntax.sgml
src/backend/parser/scan.l

index 6e49e9cee1eb4426a3870b0b8bccc1af7831f2fc..45b6a80564b51724d9de5658c2c2c142a7e5dd20 100644 (file)
@@ -1,5 +1,5 @@
 
 
 
@@ -254,17 +254,18 @@ UPDATE "my_table" SET "a" = 5;
 
     
      Another PostgreSQL extension is that
-     C-style backslash escapes are available:
-     \b is a backspace, \f is a
-     form feed, \n is a newline,
-     \r is a carriage return, \t
-     is a tab, and \xxx,
-     where xxx is an octal number, is a
-     byte with the corresponding code.  (It is your responsibility
-     that the byte sequences you create are valid characters in the
-     server character set encoding.)  Any other character following a
-     backslash is taken literally.  Thus, to include a backslash in a
-     string constant, write two backslashes.
+     C-style backslash escapes are available: \b is a
+     backspace, \f is a form feed,
+     \n is a newline, \r is a
+     carriage return, \t is a tab. Also supported is
+     \digits, where
+     ddd represents an octal byte value, and
+     \xhexdigits, where
+     hexdigits represents a hexadecimal byte value.
+     (It is your responsibility that the byte sequences you create are
+     valid characters in the server character set encoding.) Any other
+     character following a backslash is taken literally. Thus, to
+     include a backslash in a string constant, write two backslashes.
     
 
     
index ef5c1a639f1029b8e9709a4eedd8e83d048a41d7..161a32861f624fbcc0b2f2a34163ee948a1955e6 100644 (file)
@@ -24,7 +24,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.122 2005/05/26 01:24:29 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.123 2005/06/02 01:23:08 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -193,8 +193,9 @@ xnstart         [nN]{quote}
 xqstart            {quote}
 xqdouble       {quote}{quote}
 xqinside       [^\\']+
-xqescape       [\\][^0-7]
+xqescape       [\\][^0-7x]
 xqoctesc       [\\][0-7]{1,3}
+xqhexesc       [\\]x[0-9A-Fa-f]{1,2}
 
 /* $foo$ style quotes ("dollar quoting")
  * The quoted string starts with $foo$ where "foo" is an optional string
@@ -435,6 +436,10 @@ other          .
                    unsigned char c = strtoul(yytext+1, NULL, 8);
                    addlitchar(c);
                }
+{xqhexesc}  {
+                   unsigned char c = strtoul(yytext+2, NULL, 16);
+                   addlitchar(c);
+               }
 {quotecontinue} {
                    /* ignore */
                }