Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5841aa8

Browse files
committed
Explicitly bind gettext to the correct encoding on Windows.
Original patch from Hiroshi Inoue.
1 parent 95aaf25 commit 5841aa8

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

src/backend/utils/mb/mbutils.c

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* (currently mule internal code (mic) is used)
55
* Tatsuo Ishii
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.77 2009/01/19 15:34:23 mha Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.78 2009/01/22 10:09:48 mha Exp $
88
*/
99
#include "postgres.h"
1010

@@ -849,6 +849,46 @@ cliplen(const char *str, int len, int limit)
849849
return l;
850850
}
851851

852+
#if defined(ENABLE_NLS) && defined(WIN32)
853+
static const struct codeset_map {
854+
int encoding;
855+
const char *codeset;
856+
} codeset_map_array[] = {
857+
{PG_UTF8, "UTF-8"},
858+
{PG_LATIN1, "LATIN1"},
859+
{PG_LATIN2, "LATIN2"},
860+
{PG_LATIN3, "LATIN3"},
861+
{PG_LATIN4, "LATIN4"},
862+
{PG_ISO_8859_5, "ISO-8859-5"},
863+
{PG_ISO_8859_6, "ISO_8859-6"},
864+
{PG_ISO_8859_7, "ISO-8859-7"},
865+
{PG_ISO_8859_8, "ISO-8859-8"},
866+
{PG_LATIN5, "LATIN5"},
867+
{PG_LATIN6, "LATIN6"},
868+
{PG_LATIN7, "LATIN7"},
869+
{PG_LATIN8, "LATIN8"},
870+
{PG_LATIN9, "LATIN-9"},
871+
{PG_LATIN10, "LATIN10"},
872+
{PG_KOI8R, "KOI8-R"},
873+
{PG_WIN1250, "CP1250"},
874+
{PG_WIN1251, "CP1251"},
875+
{PG_WIN1252, "CP1252"},
876+
{PG_WIN1253, "CP1253"},
877+
{PG_WIN1254, "CP1254"},
878+
{PG_WIN1255, "CP1255"},
879+
{PG_WIN1256, "CP1256"},
880+
{PG_WIN1257, "CP1257"},
881+
{PG_WIN1258, "CP1258"},
882+
{PG_WIN866, "CP866"},
883+
{PG_WIN874, "CP874"},
884+
{PG_EUC_CN, "EUC-CN"},
885+
{PG_EUC_JP, "EUC-JP"},
886+
{PG_EUC_KR, "EUC-KR"},
887+
{PG_EUC_TW, "EUC-TW"},
888+
{PG_EUC_JIS_2004, "EUC-JP"}
889+
};
890+
#endif /* WIN32 */
891+
852892
void
853893
SetDatabaseEncoding(int encoding)
854894
{
@@ -859,22 +899,23 @@ SetDatabaseEncoding(int encoding)
859899
Assert(DatabaseEncoding->encoding == encoding);
860900

861901
/*
862-
* On Windows, we allow UTF-8 database encoding to be used with any
863-
* locale setting, because UTF-8 requires special handling anyway.
864-
* But this means that gettext() might be misled about what output
865-
* encoding it should use, so we have to tell it explicitly.
866-
*
867-
* In future we might want to call bind_textdomain_codeset
868-
* unconditionally, but that requires knowing how to spell the codeset
869-
* name properly for all encodings on all platforms, which might be
870-
* problematic.
871-
*
872-
* This is presently unnecessary, but harmless, on non-Windows platforms.
902+
* On Windows, we need to explicitly bind gettext to the correct
903+
* encoding, because gettext() tends to get confused.
873904
*/
874-
#ifdef ENABLE_NLS
875-
if (encoding == PG_UTF8)
876-
if (bind_textdomain_codeset(textdomain(NULL), "UTF-8") == NULL)
877-
elog(LOG, "bind_textdomain_codeset failed");
905+
#if defined(ENABLE_NLS) && defined(WIN32)
906+
{
907+
int i;
908+
909+
for (i = 0; i < sizeof(codeset_map_array) / sizeof(codeset_map_array[0]); i++)
910+
{
911+
if (codeset_map_array[i].encoding == encoding)
912+
{
913+
if (bind_textdomain_codeset(textdomain(NULL), codeset_map_array[i].codeset) == NULL)
914+
elog(LOG, "bind_textdomain_codeset failed");
915+
break;
916+
}
917+
}
918+
}
878919
#endif
879920
}
880921

0 commit comments

Comments
 (0)