66 * Portions Copyright (c) 1994, Regents of the University of California
77 *
88 * IDENTIFICATION
9- * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.16 2005/11/22 18:17:26 momjian Exp $
9+ * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.17 2005/12/23 02:11:02 ishii Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -68,15 +68,6 @@ typedef struct
6868}pg_conv_map ;
6969
7070static pg_conv_map maps []= {
71- {PG_SQL_ASCII },/* SQL/ASCII */
72- {PG_EUC_JP },/* EUC for Japanese */
73- {PG_EUC_CN },/* EUC for Chinese */
74- {PG_EUC_KR },/* EUC for Korean */
75- {PG_EUC_TW },/* EUC for Taiwan */
76- {PG_JOHAB },/* EUC for Korean JOHAB */
77- {PG_UTF8 },/* Unicode UTF8 */
78- {PG_MULE_INTERNAL },/* Mule internal code */
79- {PG_LATIN1 },/* ISO-8859-1 Latin 1 */
8071{PG_LATIN2 ,LUmapISO8859_2 ,ULmapISO8859_2 ,
8172sizeof (LUmapISO8859_2 ) /sizeof (pg_local_to_utf ),
8273sizeof (ULmapISO8859_2 ) /sizeof (pg_utf_to_local )},/* ISO-8859-2 Latin 2 */
@@ -104,12 +95,6 @@ static pg_conv_map maps[] = {
10495{PG_LATIN10 ,LUmapISO8859_16 ,ULmapISO8859_16 ,
10596sizeof (LUmapISO8859_16 ) /sizeof (pg_local_to_utf ),
10697sizeof (ULmapISO8859_16 ) /sizeof (pg_utf_to_local )},/* ISO-8859-16 Latin 10 */
107- {PG_WIN1256 },/* windows-1256 */
108- {PG_WIN1258 },/* Windows-1258 */
109- {PG_WIN874 },/* windows-874 */
110- {PG_KOI8R },/* KOI8-R */
111- {PG_WIN1251 },/* windows-1251 */
112- {PG_WIN866 },/* (MS-DOS CP866) */
11398{PG_ISO_8859_5 ,LUmapISO8859_5 ,ULmapISO8859_5 ,
11499sizeof (LUmapISO8859_5 ) /sizeof (pg_local_to_utf ),
115100sizeof (ULmapISO8859_5 ) /sizeof (pg_utf_to_local )},/* ISO-8859-5 */
@@ -131,11 +116,23 @@ iso8859_to_utf8(PG_FUNCTION_ARGS)
131116unsignedchar * src = (unsignedchar * )PG_GETARG_CSTRING (2 );
132117unsignedchar * dest = (unsignedchar * )PG_GETARG_CSTRING (3 );
133118int len = PG_GETARG_INT32 (4 );
119+ int i ;
134120
135121Assert (PG_GETARG_INT32 (1 )== PG_UTF8 );
136122Assert (len >=0 );
137123
138- LocalToUtf (src ,dest ,maps [encoding ].map1 ,maps [encoding ].size1 ,encoding ,len );
124+ for (i = 0 ;i < sizeof (maps )/sizeof (pg_conv_map );i ++ )
125+ {
126+ if (encoding == maps [i ].encoding )
127+ {
128+ LocalToUtf (src ,dest ,maps [i ].map1 ,maps [i ].size1 ,encoding ,len );
129+ PG_RETURN_VOID ();
130+ }
131+ }
132+
133+ ereport (ERROR ,
134+ (errcode (ERRCODE_INTERNAL_ERROR ),
135+ errmsg ("unexpected encoding id %d for ISO-8859 charsets" ,encoding )));
139136
140137PG_RETURN_VOID ();
141138}
@@ -147,11 +144,23 @@ utf8_to_iso8859(PG_FUNCTION_ARGS)
147144unsignedchar * src = (unsignedchar * )PG_GETARG_CSTRING (2 );
148145unsignedchar * dest = (unsignedchar * )PG_GETARG_CSTRING (3 );
149146int len = PG_GETARG_INT32 (4 );
147+ int i ;
150148
151149Assert (PG_GETARG_INT32 (0 )== PG_UTF8 );
152150Assert (len >=0 );
153151
154- UtfToLocal (src ,dest ,maps [encoding ].map2 ,maps [encoding ].size2 ,len );
152+ for (i = 0 ;i < sizeof (maps )/sizeof (pg_conv_map );i ++ )
153+ {
154+ if (encoding == maps [i ].encoding )
155+ {
156+ UtfToLocal (src ,dest ,maps [i ].map2 ,maps [i ].size2 ,len );
157+ PG_RETURN_VOID ();
158+ }
159+ }
160+
161+ ereport (ERROR ,
162+ (errcode (ERRCODE_INTERNAL_ERROR ),
163+ errmsg ("unexpected encoding id %d for ISO-8859 charsets" ,encoding )));
155164
156165PG_RETURN_VOID ();
157166}