66 * Portions Copyright (c) 1994, Regents of the University of California
77 *
88 * IDENTIFICATION
9- * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.16 2008/01/01 19:45:53 momjian Exp $
9+ * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.17 2008/03/20 10:30:04 heikki Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -301,6 +301,12 @@ win866_to_win1251(PG_FUNCTION_ARGS)
301301Assert (PG_GETARG_INT32 (1 )== PG_WIN1251 );
302302Assert (len >=0 );
303303
304+ /*
305+ * Note: There are a few characters like the "Numero" sign that exist in
306+ * all the other cyrillic encodings (win1251, ISO_8859-5 and cp866), but
307+ * not in KOI8R. As we use MULE_INTERNAL/KOI8R as an intermediary, we
308+ * will fail to convert those characters.
309+ */
304310buf = palloc (len * ENCODING_GROWTH_RATE );
305311win8662mic (src ,buf ,len );
306312mic2win1251 (buf ,dest ,strlen ((char * )buf ));
@@ -321,6 +327,7 @@ win1251_to_win866(PG_FUNCTION_ARGS)
321327Assert (PG_GETARG_INT32 (1 )== PG_WIN866 );
322328Assert (len >=0 );
323329
330+ /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
324331buf = palloc (len * ENCODING_GROWTH_RATE );
325332win12512mic (src ,buf ,len );
326333mic2win866 (buf ,dest ,strlen ((char * )buf ));
@@ -381,6 +388,7 @@ iso_to_win1251(PG_FUNCTION_ARGS)
381388Assert (PG_GETARG_INT32 (1 )== PG_WIN1251 );
382389Assert (len >=0 );
383390
391+ /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
384392buf = palloc (len * ENCODING_GROWTH_RATE );
385393iso2mic (src ,buf ,len );
386394mic2win1251 (buf ,dest ,strlen ((char * )buf ));
@@ -401,6 +409,7 @@ win1251_to_iso(PG_FUNCTION_ARGS)
401409Assert (PG_GETARG_INT32 (1 )== PG_ISO_8859_5 );
402410Assert (len >=0 );
403411
412+ /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
404413buf = palloc (len * ENCODING_GROWTH_RATE );
405414win12512mic (src ,buf ,len );
406415mic2iso (buf ,dest ,strlen ((char * )buf ));
@@ -421,6 +430,7 @@ iso_to_win866(PG_FUNCTION_ARGS)
421430Assert (PG_GETARG_INT32 (1 )== PG_WIN866 );
422431Assert (len >=0 );
423432
433+ /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
424434buf = palloc (len * ENCODING_GROWTH_RATE );
425435iso2mic (src ,buf ,len );
426436mic2win866 (buf ,dest ,strlen ((char * )buf ));
@@ -441,6 +451,7 @@ win866_to_iso(PG_FUNCTION_ARGS)
441451Assert (PG_GETARG_INT32 (1 )== PG_ISO_8859_5 );
442452Assert (len >=0 );
443453
454+ /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
444455buf = palloc (len * ENCODING_GROWTH_RATE );
445456win8662mic (src ,buf ,len );
446457mic2iso (buf ,dest ,strlen ((char * )buf ));
@@ -483,7 +494,7 @@ iso2mic(const unsigned char *l, unsigned char *p, int len)
4834940x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
4844950x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
4854960x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
486- 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
497+ 0x00 ,0xb3 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
4874980x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
4884990xe1 ,0xe2 ,0xf7 ,0xe7 ,0xe4 ,0xe5 ,0xf6 ,0xfa ,
4895000xe9 ,0xea ,0xeb ,0xec ,0xed ,0xee ,0xef ,0xf0 ,
@@ -493,7 +504,7 @@ iso2mic(const unsigned char *l, unsigned char *p, int len)
4935040xc9 ,0xca ,0xcb ,0xcc ,0xcd ,0xce ,0xcf ,0xd0 ,
4945050xd2 ,0xd3 ,0xd4 ,0xd5 ,0xc6 ,0xc8 ,0xc3 ,0xde ,
4955060xdb ,0xdd ,0xdf ,0xd9 ,0xd8 ,0xdc ,0xc0 ,0xd1 ,
496- 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
507+ 0x00 ,0xa3 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
4975080x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
498509};
499510
@@ -509,9 +520,9 @@ mic2iso(const unsigned char *mic, unsigned char *p, int len)
5095200x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
5105210x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
5115220x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
523+ 0x00 ,0x00 ,0x00 ,0xf1 ,0x00 ,0x00 ,0x00 ,0x00 ,
5125240x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
513- 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
514- 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
525+ 0x00 ,0x00 ,0x00 ,0xa1 ,0x00 ,0x00 ,0x00 ,0x00 ,
5155260x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
5165270xee ,0xd0 ,0xd1 ,0xe6 ,0xd4 ,0xd5 ,0xe4 ,0xd3 ,
5175280xe5 ,0xd8 ,0xd9 ,0xda ,0xdb ,0xdc ,0xdd ,0xde ,