summaryrefslogtreecommitdiff
path: root/src/bin/psql/mbprint.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-08-18 19:54:01 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-08-18 19:54:01 +0000
commit2d8314bd43663b7ef45628d283dc5c6c10a60a75 (patch)
tree40b34275a67b9f802fb30dbcf79b83e3bcd40829 /src/bin/psql/mbprint.c
parentb5565bca110c3b2d6fe55cc87d0b3fbb105a504f (diff)
downloadpostgresql-2d8314bd43663b7ef45628d283dc5c6c10a60a75.tar.gz
Rename utf2ucs() to utf8_to_unicode(), and export it so it can be used
elsewhere. Similarly rename the version in mbprint.c, not because this affects anything but just to keep the two copies in exact sync. There was some discussion of having only one copy in src/port/ instead, but this function is so small and unlikely to change that that seems like overkill. Slightly editorialized version of a patch by Joseph Adams. (The bug-fix aspect of his patch was applied separately, and back-patched.)
Diffstat (limited to 'src/bin/psql/mbprint.c')
-rw-r--r--src/bin/psql/mbprint.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/bin/psql/mbprint.c b/src/bin/psql/mbprint.c
index d46aaef544..141f860041 100644
--- a/src/bin/psql/mbprint.c
+++ b/src/bin/psql/mbprint.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.39 2010/08/16 00:06:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.40 2010/08/18 19:54:01 tgl Exp $
*
* XXX this file does not really belong in psql/. Perhaps move to libpq?
* It also seems that the mbvalidate function is redundant with existing
@@ -43,13 +43,15 @@ pg_get_utf8_id(void)
#define PG_UTF8 pg_get_utf8_id()
+/*
+ * Convert a UTF-8 character to a Unicode code point.
+ * This is a one-character version of pg_utf2wchar_with_len.
+ *
+ * No error checks here, c must point to a long-enough string.
+ */
static pg_wchar
-utf2ucs(const unsigned char *c)
+utf8_to_unicode(const unsigned char *c)
{
- /*
- * one char version of pg_utf2wchar_with_len. no control here, c must
- * point to a large enough string
- */
if ((*c & 0x80) == 0)
return (pg_wchar) c[0];
else if ((*c & 0xe0) == 0xc0)
@@ -346,7 +348,7 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
else if (w < 0) /* Non-ascii control char */
{
if (encoding == PG_UTF8)
- sprintf((char *) ptr, "\\u%04X", utf2ucs(pwcs));
+ sprintf((char *) ptr, "\\u%04X", utf8_to_unicode(pwcs));
else
{
/*