]> granicus.if.org Git - postgresql/commitdiff
Add Charset WIN1252 support.
authorBruce Momjian <bruce@momjian.us>
Thu, 2 Dec 2004 22:14:38 +0000 (22:14 +0000)
committerBruce Momjian <bruce@momjian.us>
Thu, 2 Dec 2004 22:14:38 +0000 (22:14 +0000)
Roland Volkmann

src/backend/utils/mb/Unicode/utf8_to_win1252.map [new file with mode: 0644]
src/backend/utils/mb/Unicode/win1252_to_utf8.map [new file with mode: 0644]
src/backend/utils/mb/conversion_procs/utf8_and_win1252/Makefile [new file with mode: 0644]
src/backend/utils/mb/conversion_procs/utf8_and_win1252/utf8_and_win1252.c [new file with mode: 0644]
src/backend/utils/mb/encnames.c
src/include/mb/pg_wchar.h

diff --git a/src/backend/utils/mb/Unicode/utf8_to_win1252.map b/src/backend/utils/mb/Unicode/utf8_to_win1252.map
new file mode 100644 (file)
index 0000000..6dc3c6c
--- /dev/null
@@ -0,0 +1,126 @@
+static pg_utf_to_local ULmapWIN1252[ 124 ] = {
+  {0x0000, 0x0081},
+  {0xc2a0, 0x00a0},
+  {0xc2a1, 0x00a1},
+  {0xc2a2, 0x00a2},
+  {0xc2a3, 0x00a3},
+  {0xc2a4, 0x00a4},
+  {0xc2a5, 0x00a5},
+  {0xc2a6, 0x00a6},
+  {0xc2a7, 0x00a7},
+  {0xc2a8, 0x00a8},
+  {0xc2a9, 0x00a9},
+  {0xc2aa, 0x00aa},
+  {0xc2ab, 0x00ab},
+  {0xc2ac, 0x00ac},
+  {0xc2ad, 0x00ad},
+  {0xc2ae, 0x00ae},
+  {0xc2af, 0x00af},
+  {0xc2b0, 0x00b0},
+  {0xc2b1, 0x00b1},
+  {0xc2b2, 0x00b2},
+  {0xc2b3, 0x00b3},
+  {0xc2b4, 0x00b4},
+  {0xc2b5, 0x00b5},
+  {0xc2b6, 0x00b6},
+  {0xc2b7, 0x00b7},
+  {0xc2b8, 0x00b8},
+  {0xc2b9, 0x00b9},
+  {0xc2ba, 0x00ba},
+  {0xc2bb, 0x00bb},
+  {0xc2bc, 0x00bc},
+  {0xc2bd, 0x00bd},
+  {0xc2be, 0x00be},
+  {0xc2bf, 0x00bf},
+  {0xc380, 0x00c0},
+  {0xc381, 0x00c1},
+  {0xc382, 0x00c2},
+  {0xc383, 0x00c3},
+  {0xc384, 0x00c4},
+  {0xc385, 0x00c5},
+  {0xc386, 0x00c6},
+  {0xc387, 0x00c7},
+  {0xc388, 0x00c8},
+  {0xc389, 0x00c9},
+  {0xc38a, 0x00ca},
+  {0xc38b, 0x00cb},
+  {0xc38c, 0x00cc},
+  {0xc38d, 0x00cd},
+  {0xc38e, 0x00ce},
+  {0xc38f, 0x00cf},
+  {0xc390, 0x00d0},
+  {0xc391, 0x00d1},
+  {0xc392, 0x00d2},
+  {0xc393, 0x00d3},
+  {0xc394, 0x00d4},
+  {0xc395, 0x00d5},
+  {0xc396, 0x00d6},
+  {0xc397, 0x00d7},
+  {0xc398, 0x00d8},
+  {0xc399, 0x00d9},
+  {0xc39a, 0x00da},
+  {0xc39b, 0x00db},
+  {0xc39c, 0x00dc},
+  {0xc39d, 0x00dd},
+  {0xc39e, 0x00de},
+  {0xc39f, 0x00df},
+  {0xc3a0, 0x00e0},
+  {0xc3a1, 0x00e1},
+  {0xc3a2, 0x00e2},
+  {0xc3a3, 0x00e3},
+  {0xc3a4, 0x00e4},
+  {0xc3a5, 0x00e5},
+  {0xc3a6, 0x00e6},
+  {0xc3a7, 0x00e7},
+  {0xc3a8, 0x00e8},
+  {0xc3a9, 0x00e9},
+  {0xc3aa, 0x00ea},
+  {0xc3ab, 0x00eb},
+  {0xc3ac, 0x00ec},
+  {0xc3ad, 0x00ed},
+  {0xc3ae, 0x00ee},
+  {0xc3af, 0x00ef},
+  {0xc3b0, 0x00f0},
+  {0xc3b1, 0x00f1},
+  {0xc3b2, 0x00f2},
+  {0xc3b3, 0x00f3},
+  {0xc3b4, 0x00f4},
+  {0xc3b5, 0x00f5},
+  {0xc3b6, 0x00f6},
+  {0xc3b7, 0x00f7},
+  {0xc3b8, 0x00f8},
+  {0xc3b9, 0x00f9},
+  {0xc3ba, 0x00fa},
+  {0xc3bb, 0x00fb},
+  {0xc3bc, 0x00fc},
+  {0xc3bd, 0x00fd},
+  {0xc3be, 0x00fe},
+  {0xc3bf, 0x00ff},
+  {0xc592, 0x008c},
+  {0xc593, 0x009c},
+  {0xc5a0, 0x008a},
+  {0xc5a1, 0x009a},
+  {0xc5b8, 0x009f},
+  {0xc5bd, 0x008e},
+  {0xc5be, 0x009e},
+  {0xc692, 0x0083},
+  {0xcb86, 0x0088},
+  {0xcb9c, 0x0098},
+  {0xe28093, 0x0096},
+  {0xe28094, 0x0097},
+  {0xe28098, 0x0091},
+  {0xe28099, 0x0092},
+  {0xe2809a, 0x0082},
+  {0xe2809c, 0x0093},
+  {0xe2809d, 0x0094},
+  {0xe2809e, 0x0084},
+  {0xe280a0, 0x0086},
+  {0xe280a1, 0x0087},
+  {0xe280a2, 0x0095},
+  {0xe280a6, 0x0085},
+  {0xe280b0, 0x0089},
+  {0xe280b9, 0x008b},
+  {0xe280ba, 0x009b},
+  {0xe282ac, 0x0080},
+  {0xe284a2, 0x0099}
+};
diff --git a/src/backend/utils/mb/Unicode/win1252_to_utf8.map b/src/backend/utils/mb/Unicode/win1252_to_utf8.map
new file mode 100644 (file)
index 0000000..636baf8
--- /dev/null
@@ -0,0 +1,130 @@
+static pg_local_to_utf LUmapWIN1252[ 128 ] = {
+  {0x0080, 0xe282ac},
+  {0x0081, 0x0000},
+  {0x0082, 0xe2809a},
+  {0x0083, 0xc692},
+  {0x0084, 0xe2809e},
+  {0x0085, 0xe280a6},
+  {0x0086, 0xe280a0},
+  {0x0087, 0xe280a1},
+  {0x0088, 0xcb86},
+  {0x0089, 0xe280b0},
+  {0x008a, 0xc5a0},
+  {0x008b, 0xe280b9},
+  {0x008c, 0xc592},
+  {0x008d, 0x0000},
+  {0x008e, 0xc5bd},
+  {0x008f, 0x0000},
+  {0x0090, 0x0000},
+  {0x0091, 0xe28098},
+  {0x0092, 0xe28099},
+  {0x0093, 0xe2809c},
+  {0x0094, 0xe2809d},
+  {0x0095, 0xe280a2},
+  {0x0096, 0xe28093},
+  {0x0097, 0xe28094},
+  {0x0098, 0xcb9c},
+  {0x0099, 0xe284a2},
+  {0x009a, 0xc5a1},
+  {0x009b, 0xe280ba},
+  {0x009c, 0xc593},
+  {0x009d, 0x0000},
+  {0x009e, 0xc5be},
+  {0x009f, 0xc5b8},
+  {0x00a0, 0xc2a0},
+  {0x00a1, 0xc2a1},
+  {0x00a2, 0xc2a2},
+  {0x00a3, 0xc2a3},
+  {0x00a4, 0xc2a4},
+  {0x00a5, 0xc2a5},
+  {0x00a6, 0xc2a6},
+  {0x00a7, 0xc2a7},
+  {0x00a8, 0xc2a8},
+  {0x00a9, 0xc2a9},
+  {0x00aa, 0xc2aa},
+  {0x00ab, 0xc2ab},
+  {0x00ac, 0xc2ac},
+  {0x00ad, 0xc2ad},
+  {0x00ae, 0xc2ae},
+  {0x00af, 0xc2af},
+  {0x00b0, 0xc2b0},
+  {0x00b1, 0xc2b1},
+  {0x00b2, 0xc2b2},
+  {0x00b3, 0xc2b3},
+  {0x00b4, 0xc2b4},
+  {0x00b5, 0xc2b5},
+  {0x00b6, 0xc2b6},
+  {0x00b7, 0xc2b7},
+  {0x00b8, 0xc2b8},
+  {0x00b9, 0xc2b9},
+  {0x00ba, 0xc2ba},
+  {0x00bb, 0xc2bb},
+  {0x00bc, 0xc2bc},
+  {0x00bd, 0xc2bd},
+  {0x00be, 0xc2be},
+  {0x00bf, 0xc2bf},
+  {0x00c0, 0xc380},
+  {0x00c1, 0xc381},
+  {0x00c2, 0xc382},
+  {0x00c3, 0xc383},
+  {0x00c4, 0xc384},
+  {0x00c5, 0xc385},
+  {0x00c6, 0xc386},
+  {0x00c7, 0xc387},
+  {0x00c8, 0xc388},
+  {0x00c9, 0xc389},
+  {0x00ca, 0xc38a},
+  {0x00cb, 0xc38b},
+  {0x00cc, 0xc38c},
+  {0x00cd, 0xc38d},
+  {0x00ce, 0xc38e},
+  {0x00cf, 0xc38f},
+  {0x00d0, 0xc390},
+  {0x00d1, 0xc391},
+  {0x00d2, 0xc392},
+  {0x00d3, 0xc393},
+  {0x00d4, 0xc394},
+  {0x00d5, 0xc395},
+  {0x00d6, 0xc396},
+  {0x00d7, 0xc397},
+  {0x00d8, 0xc398},
+  {0x00d9, 0xc399},
+  {0x00da, 0xc39a},
+  {0x00db, 0xc39b},
+  {0x00dc, 0xc39c},
+  {0x00dd, 0xc39d},
+  {0x00de, 0xc39e},
+  {0x00df, 0xc39f},
+  {0x00e0, 0xc3a0},
+  {0x00e1, 0xc3a1},
+  {0x00e2, 0xc3a2},
+  {0x00e3, 0xc3a3},
+  {0x00e4, 0xc3a4},
+  {0x00e5, 0xc3a5},
+  {0x00e6, 0xc3a6},
+  {0x00e7, 0xc3a7},
+  {0x00e8, 0xc3a8},
+  {0x00e9, 0xc3a9},
+  {0x00ea, 0xc3aa},
+  {0x00eb, 0xc3ab},
+  {0x00ec, 0xc3ac},
+  {0x00ed, 0xc3ad},
+  {0x00ee, 0xc3ae},
+  {0x00ef, 0xc3af},
+  {0x00f0, 0xc3b0},
+  {0x00f1, 0xc3b1},
+  {0x00f2, 0xc3b2},
+  {0x00f3, 0xc3b3},
+  {0x00f4, 0xc3b4},
+  {0x00f5, 0xc3b5},
+  {0x00f6, 0xc3b6},
+  {0x00f7, 0xc3b7},
+  {0x00f8, 0xc3b8},
+  {0x00f9, 0xc3b9},
+  {0x00fa, 0xc3ba},
+  {0x00fb, 0xc3bb},
+  {0x00fc, 0xc3bc},
+  {0x00fd, 0xc3bd},
+  {0x00fe, 0xc3be},
+  {0x00ff, 0xc3bf}
+};
diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_win1252/Makefile b/src/backend/utils/mb/conversion_procs/utf8_and_win1252/Makefile
new file mode 100644 (file)
index 0000000..ef130a4
--- /dev/null
@@ -0,0 +1,12 @@
+#-------------------------------------------------------------------------
+#
+# $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1252/Makefile,v 1.1 2004/12/02 22:14:37 momjian Exp $
+#
+#-------------------------------------------------------------------------
+subdir = src/backend/utils/mb/conversion_procs/utf8_and_win1252
+top_builddir = ../../../../../..
+include $(top_builddir)/src/Makefile.global
+
+NAME           := utf8_and_win1252
+
+include $(srcdir)/../proc.mk
diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_win1252/utf8_and_win1252.c b/src/backend/utils/mb/conversion_procs/utf8_and_win1252/utf8_and_win1252.c
new file mode 100644 (file)
index 0000000..f417ad1
--- /dev/null
@@ -0,0 +1,69 @@
+/*-------------------------------------------------------------------------
+ *
+ *       WIN1252 and UTF-8
+ *
+ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * IDENTIFICATION
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1252/utf8_and_win1252.c,v 1.1 2004/12/02 22:14:37 momjian Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "postgres.h"
+#include "fmgr.h"
+#include "mb/pg_wchar.h"
+#include "../../Unicode/utf8_to_win1252.map"
+#include "../../Unicode/win1252_to_utf8.map"
+
+PG_FUNCTION_INFO_V1(utf_to_win1252);
+PG_FUNCTION_INFO_V1(win1252_to_utf);
+
+extern Datum utf_to_win1252(PG_FUNCTION_ARGS);
+extern Datum win1252_to_utf(PG_FUNCTION_ARGS);
+
+/* ----------
+ * conv_proc(
+ *             INTEGER,        -- source encoding id
+ *             INTEGER,        -- destination encoding id
+ *             CSTRING,        -- source string (null terminated C string)
+ *             CSTRING,        -- destination string (null terminated C string)
+ *             INTEGER         -- source string length
+ * ) returns VOID;
+ * ----------
+ */
+
+Datum
+utf_to_win1252(PG_FUNCTION_ARGS)
+{
+       unsigned char *src = PG_GETARG_CSTRING(2);
+       unsigned char *dest = PG_GETARG_CSTRING(3);
+       int                     len = PG_GETARG_INT32(4);
+
+       Assert(PG_GETARG_INT32(0) == PG_UTF8);
+       Assert(PG_GETARG_INT32(1) == PG_WIN1252);
+       Assert(len >= 0);
+
+       UtfToLocal(src, dest, ULmapWIN1252,
+                          sizeof(ULmapWIN1252) / sizeof(pg_utf_to_local), len);
+
+       PG_RETURN_VOID();
+}
+
+Datum
+win1252_to_utf(PG_FUNCTION_ARGS)
+{
+       unsigned char *src = PG_GETARG_CSTRING(2);
+       unsigned char *dest = PG_GETARG_CSTRING(3);
+       int                     len = PG_GETARG_INT32(4);
+
+       Assert(PG_GETARG_INT32(0) == PG_WIN1252);
+       Assert(PG_GETARG_INT32(1) == PG_UTF8);
+       Assert(len >= 0);
+
+       LocalToUtf(src, dest, LUmapWIN1252,
+               sizeof(LUmapWIN1252) / sizeof(pg_local_to_utf), PG_WIN1252, len);
+
+       PG_RETURN_VOID();
+}
index a3260fd61c4ff2de16afac0a354118338f63322d..e288f3c23094e59db72d9f05041c31e83167ba99 100644 (file)
@@ -2,7 +2,7 @@
  * Encoding names and routines for work with it. All
  * in this file is shared bedween FE and BE.
  *
- * $PostgreSQL: pgsql/src/backend/utils/mb/encnames.c,v 1.20 2004/09/27 23:24:33 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/encnames.c,v 1.21 2004/12/02 22:14:36 momjian Exp $
  */
 #ifdef FRONTEND
 #include "postgres_fe.h"
@@ -193,6 +193,9 @@ pg_encname  pg_encname_tbl[] =
        {
                "win1251", PG_WIN1251
        },                                                      /* alias for Windows-1251 */
+       {
+               "win1252", PG_WIN1252
+       },                                                      /* alias for Windows-1252 */
        {
                "win1256", PG_WIN1256
        },                                                      /* alias for Windows-1256 */
@@ -220,6 +223,9 @@ pg_encname  pg_encname_tbl[] =
        {
                "windows1251", PG_WIN1251
        },                                                      /* Windows-1251; Microsoft */
+       {
+               "windows1252", PG_WIN1252
+       },                                                      /* Windows-1252; Microsoft */
        {
                "windows1256", PG_WIN1256
        },                                                      /* Windows-1256; Microsoft */
@@ -343,6 +349,9 @@ pg_enc2name pg_enc2name_tbl[] =
        {
                "WIN1250", PG_WIN1250
        },
+       {
+               "WIN1252", PG_WIN1252
+       },
        {
                "SJIS", PG_SJIS
        },
index 2b4ba2d9fb0b2f9f0e7f095d023b919965b1e2fc..9fb8aa2e4e32eefba10184a25c1f68979347f231 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.52 2004/09/17 21:59:57 petere Exp $ */
+/* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.53 2004/12/02 22:14:38 momjian Exp $ */
 
 #ifndef PG_WCHAR_H
 #define PG_WCHAR_H
@@ -178,6 +178,7 @@ typedef enum pg_enc
        PG_ISO_8859_7,                          /* ISO-8859-7 */
        PG_ISO_8859_8,                          /* ISO-8859-8 */
        PG_WIN1250,                                     /* windows-1250 */
+       PG_WIN1252,                                     /* windows-1252 */
 
        /* followings are for client encoding only */
        PG_SJIS,                                        /* Shift JIS (Winindows-932) */