Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65537ac

Browse files
committed
Add support for \x hex escapes in backend strings. Octal was already
supported. This follows the C standard escapes.
1 parent202e6e7 commit65537ac

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

‎doc/src/sgml/syntax.sgml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.99 2004/12/23 05:37:40 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.100 2005/06/02 01:23:08 momjian Exp $
33
-->
44

55
<chapter id="sql-syntax">
@@ -254,17 +254,18 @@ UPDATE "my_table" SET "a" = 5;
254254

255255
<para>
256256
Another <productname>PostgreSQL</productname> extension is that
257-
C-style backslash escapes are available:
258-
<literal>\b</literal> is a backspace, <literal>\f</literal> is a
259-
form feed, <literal>\n</literal> is a newline,
260-
<literal>\r</literal> is a carriage return, <literal>\t</literal>
261-
is a tab, and <literal>\<replaceable>xxx</replaceable></literal>,
262-
where <replaceable>xxx</replaceable> is an octal number, is a
263-
byte with the corresponding code. (It is your responsibility
264-
that the byte sequences you create are valid characters in the
265-
server character set encoding.) Any other character following a
266-
backslash is taken literally. Thus, to include a backslash in a
267-
string constant, write two backslashes.
257+
C-style backslash escapes are available: <literal>\b</literal> is a
258+
backspace, <literal>\f</literal> is a form feed,
259+
<literal>\n</literal> is a newline, <literal>\r</literal> is a
260+
carriage return, <literal>\t</literal> is a tab. Also supported is
261+
<literal>\<replaceable>digits</replaceable></literal>, where
262+
<replaceable>ddd</replaceable> represents an octal byte value, and
263+
<literal>\x<replaceable>hexdigits</replaceable></literal>, where
264+
<replaceable>hexdigits</replaceable> represents a hexadecimal byte value.
265+
(It is your responsibility that the byte sequences you create are
266+
valid characters in the server character set encoding.) Any other
267+
character following a backslash is taken literally. Thus, to
268+
include a backslash in a string constant, write two backslashes.
268269
</para>
269270

270271
<para>

‎src/backend/parser/scan.l

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
2626
* IDENTIFICATION
27-
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.122 2005/05/26 01:24:29 tgl Exp $
27+
* $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.123 2005/06/02 01:23:08 momjian Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -193,8 +193,9 @@ xnstart[nN]{quote}
193193
xqstart{quote}
194194
xqdouble{quote}{quote}
195195
xqinside[^\\']+
196-
xqescape[\\][^0-7]
196+
xqescape[\\][^0-7x]
197197
xqoctesc[\\][0-7]{1,3}
198+
xqhexesc[\\]x[0-9A-Fa-f]{1,2}
198199

199200
/* $foo$ style quotes ("dollar quoting")
200201
* The quoted string starts with $foo$ where "foo" is an optional string
@@ -435,6 +436,10 @@ other.
435436
unsignedchar c =strtoul(yytext+1,NULL,8);
436437
addlitchar(c);
437438
}
439+
<xq>{xqhexesc} {
440+
unsignedchar c =strtoul(yytext+2,NULL,16);
441+
addlitchar(c);
442+
}
438443
<xq>{quotecontinue} {
439444
/* ignore */
440445
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp