LCOV - code coverage report
Current view: top level - src/backend/utils/mb/conversion_procs/cyrillic_and_mic - cyrillic_and_mic.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 181 181
Test Date: 2026-02-17 17:20:33 Functions: 100.0 % 41 41
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  *    Cyrillic and MULE_INTERNAL
       4              :  *
       5              :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       6              :  * Portions Copyright (c) 1994, Regents of the University of California
       7              :  *
       8              :  * IDENTIFICATION
       9              :  *    src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c
      10              :  *
      11              :  *-------------------------------------------------------------------------
      12              :  */
      13              : 
      14              : #include "postgres.h"
      15              : #include "fmgr.h"
      16              : #include "mb/pg_wchar.h"
      17              : 
      18            6 : PG_MODULE_MAGIC_EXT(
      19              :                     .name = "cyrillic_and_mic",
      20              :                     .version = PG_VERSION
      21              : );
      22              : 
      23            3 : PG_FUNCTION_INFO_V1(koi8r_to_mic);
      24            6 : PG_FUNCTION_INFO_V1(mic_to_koi8r);
      25            6 : PG_FUNCTION_INFO_V1(iso_to_mic);
      26            6 : PG_FUNCTION_INFO_V1(mic_to_iso);
      27            3 : PG_FUNCTION_INFO_V1(win1251_to_mic);
      28            3 : PG_FUNCTION_INFO_V1(mic_to_win1251);
      29            3 : PG_FUNCTION_INFO_V1(win866_to_mic);
      30            3 : PG_FUNCTION_INFO_V1(mic_to_win866);
      31            3 : PG_FUNCTION_INFO_V1(koi8r_to_win1251);
      32            3 : PG_FUNCTION_INFO_V1(win1251_to_koi8r);
      33            3 : PG_FUNCTION_INFO_V1(koi8r_to_win866);
      34            3 : PG_FUNCTION_INFO_V1(win866_to_koi8r);
      35            3 : PG_FUNCTION_INFO_V1(win866_to_win1251);
      36            3 : PG_FUNCTION_INFO_V1(win1251_to_win866);
      37            6 : PG_FUNCTION_INFO_V1(iso_to_koi8r);
      38            3 : PG_FUNCTION_INFO_V1(koi8r_to_iso);
      39            3 : PG_FUNCTION_INFO_V1(iso_to_win1251);
      40            3 : PG_FUNCTION_INFO_V1(win1251_to_iso);
      41            3 : PG_FUNCTION_INFO_V1(iso_to_win866);
      42            3 : PG_FUNCTION_INFO_V1(win866_to_iso);
      43              : 
      44              : /* ----------
      45              :  * conv_proc(
      46              :  *      INTEGER,    -- source encoding id
      47              :  *      INTEGER,    -- destination encoding id
      48              :  *      CSTRING,    -- source string (null terminated C string)
      49              :  *      CSTRING,    -- destination string (null terminated C string)
      50              :  *      INTEGER,    -- source string length
      51              :  *      BOOL        -- if true, don't throw an error if conversion fails
      52              :  * ) returns INTEGER;
      53              :  *
      54              :  * Returns the number of bytes successfully converted.
      55              :  * ----------
      56              :  */
      57              : 
      58              : /*
      59              :  * Cyrillic support
      60              :  * currently supported Cyrillic encodings:
      61              :  *
      62              :  * KOI8-R (this is also the charset for the mule internal code for Cyrillic)
      63              :  * ISO-8859-5
      64              :  * Microsoft's CP1251 (windows-1251)
      65              :  * Alternativny Variant (MS-DOS CP866)
      66              :  */
      67              : 
      68              : /* ISO-8859-5 to KOI8-R */
      69              : static const unsigned char iso2koi[] = {
      70              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      71              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      72              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      73              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      74              :     0x00, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      75              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      76              :     0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA,
      77              :     0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0,
      78              :     0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE,
      79              :     0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1,
      80              :     0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA,
      81              :     0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0,
      82              :     0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE,
      83              :     0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1,
      84              :     0x00, 0xA3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      85              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
      86              : };
      87              : 
      88              : /* KOI8-R to ISO-8859-5 */
      89              : static const unsigned char koi2iso[] = {
      90              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      91              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      92              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      93              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      94              :     0x00, 0x00, 0x00, 0xF1, 0x00, 0x00, 0x00, 0x00,
      95              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      96              :     0x00, 0x00, 0x00, 0xA1, 0x00, 0x00, 0x00, 0x00,
      97              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      98              :     0xEE, 0xD0, 0xD1, 0xE6, 0xD4, 0xD5, 0xE4, 0xD3,
      99              :     0xE5, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE,
     100              :     0xDF, 0xEF, 0xE0, 0xE1, 0xE2, 0xE3, 0xD6, 0xD2,
     101              :     0xEC, 0xEB, 0xD7, 0xE8, 0xED, 0xE9, 0xE7, 0xEA,
     102              :     0xCE, 0xB0, 0xB1, 0xC6, 0xB4, 0xB5, 0xC4, 0xB3,
     103              :     0xC5, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE,
     104              :     0xBF, 0xCF, 0xC0, 0xC1, 0xC2, 0xC3, 0xB6, 0xB2,
     105              :     0xCC, 0xCB, 0xB7, 0xC8, 0xCD, 0xC9, 0xC7, 0xCA
     106              : };
     107              : 
     108              : /* WIN1251 to KOI8-R */
     109              : static const unsigned char win12512koi[] = {
     110              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     111              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     112              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     113              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     114              :     0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00,
     115              :     0xB3, 0x00, 0xB4, 0x00, 0x00, 0x00, 0x00, 0xB7,
     116              :     0x00, 0x00, 0xB6, 0xA6, 0xAD, 0x00, 0x00, 0x00,
     117              :     0xA3, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, 0xA7,
     118              :     0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA,
     119              :     0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0,
     120              :     0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE,
     121              :     0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1,
     122              :     0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA,
     123              :     0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0,
     124              :     0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE,
     125              :     0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1
     126              : };
     127              : 
     128              : /* KOI8-R to WIN1251 */
     129              : static const unsigned char koi2win1251[] = {
     130              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     131              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     132              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     133              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     134              :     0x00, 0x00, 0x00, 0xB8, 0xBA, 0x00, 0xB3, 0xBF,
     135              :     0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00,
     136              :     0x00, 0x00, 0x00, 0xA8, 0xAA, 0x00, 0xB2, 0xAF,
     137              :     0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00,
     138              :     0xFE, 0xE0, 0xE1, 0xF6, 0xE4, 0xE5, 0xF4, 0xE3,
     139              :     0xF5, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE,
     140              :     0xEF, 0xFF, 0xF0, 0xF1, 0xF2, 0xF3, 0xE6, 0xE2,
     141              :     0xFC, 0xFB, 0xE7, 0xF8, 0xFD, 0xF9, 0xF7, 0xFA,
     142              :     0xDE, 0xC0, 0xC1, 0xD6, 0xC4, 0xC5, 0xD4, 0xC3,
     143              :     0xD5, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE,
     144              :     0xCF, 0xDF, 0xD0, 0xD1, 0xD2, 0xD3, 0xC6, 0xC2,
     145              :     0xDC, 0xDB, 0xC7, 0xD8, 0xDD, 0xD9, 0xD7, 0xDA
     146              : };
     147              : 
     148              : /* WIN866 to KOI8-R */
     149              : static const unsigned char win8662koi[] = {
     150              :     0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA,
     151              :     0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0,
     152              :     0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE,
     153              :     0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1,
     154              :     0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA,
     155              :     0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0,
     156              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     157              :     0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00,
     158              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     159              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     160              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     161              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     162              :     0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE,
     163              :     0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1,
     164              :     0xB3, 0xA3, 0xB4, 0xA4, 0xB7, 0xA7, 0x00, 0x00,
     165              :     0xB6, 0xA6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     166              : };
     167              : 
     168              : /* KOI8-R to WIN866 */
     169              : static const unsigned char koi2win866[] = {
     170              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     171              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     172              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     173              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     174              :     0x00, 0x00, 0x00, 0xF1, 0xF3, 0x00, 0xF9, 0xF5,
     175              :     0x00, 0x00, 0x00, 0x00, 0x00, 0xAD, 0x00, 0x00,
     176              :     0x00, 0x00, 0x00, 0xF0, 0xF2, 0x00, 0xF8, 0xF4,
     177              :     0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00,
     178              :     0xEE, 0xA0, 0xA1, 0xE6, 0xA4, 0xA5, 0xE4, 0xA3,
     179              :     0xE5, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE,
     180              :     0xAF, 0xEF, 0xE0, 0xE1, 0xE2, 0xE3, 0xA6, 0xA2,
     181              :     0xEC, 0xEB, 0xA7, 0xE8, 0xED, 0xE9, 0xE7, 0xEA,
     182              :     0x9E, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83,
     183              :     0x95, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E,
     184              :     0x8F, 0x9F, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82,
     185              :     0x9C, 0x9B, 0x87, 0x98, 0x9D, 0x99, 0x97, 0x9A
     186              : };
     187              : 
     188              : /* WIN866 to WIN1251 */
     189              : static const unsigned char win8662win1251[] = {
     190              :     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
     191              :     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
     192              :     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
     193              :     0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
     194              :     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
     195              :     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
     196              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     197              :     0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00,
     198              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     199              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     200              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     201              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     202              :     0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
     203              :     0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
     204              :     0xA8, 0xB8, 0xAA, 0xBA, 0xAF, 0xBF, 0x00, 0x00,
     205              :     0xB2, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     206              : };
     207              : 
     208              : /* WIN1251 to WIN866 */
     209              : static const unsigned char win12512win866[] = {
     210              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     211              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     212              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     213              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     214              :     0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00,
     215              :     0xF0, 0x00, 0xF2, 0x00, 0x00, 0x00, 0x00, 0xF4,
     216              :     0x00, 0x00, 0xF8, 0xF9, 0xAD, 0x00, 0x00, 0x00,
     217              :     0xF1, 0x00, 0xF3, 0x00, 0x00, 0x00, 0x00, 0xF5,
     218              :     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
     219              :     0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
     220              :     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
     221              :     0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
     222              :     0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
     223              :     0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
     224              :     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
     225              :     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF
     226              : };
     227              : 
     228              : /* ISO-8859-5 to WIN1251 */
     229              : static const unsigned char iso2win1251[] = {
     230              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     231              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     232              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     233              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     234              :     0x00, 0xA8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     235              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     236              :     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
     237              :     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
     238              :     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
     239              :     0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
     240              :     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
     241              :     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
     242              :     0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
     243              :     0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
     244              :     0x00, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     245              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     246              : };
     247              : 
     248              : /* WIN1251 to ISO-8859-5 */
     249              : static const unsigned char win12512iso[] = {
     250              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     251              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     252              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     253              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     254              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     255              :     0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     256              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     257              :     0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     258              :     0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
     259              :     0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
     260              :     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
     261              :     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
     262              :     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
     263              :     0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
     264              :     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
     265              :     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF
     266              : };
     267              : 
     268              : /* ISO-8859-5 to WIN866 */
     269              : static const unsigned char iso2win866[] = {
     270              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     271              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     272              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     273              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     274              :     0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     275              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     276              :     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
     277              :     0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
     278              :     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
     279              :     0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
     280              :     0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
     281              :     0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
     282              :     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
     283              :     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
     284              :     0x00, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     285              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     286              : };
     287              : 
     288              : /* WIN866 to ISO-8859-5 */
     289              : static const unsigned char win8662iso[] = {
     290              :     0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
     291              :     0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
     292              :     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
     293              :     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
     294              :     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
     295              :     0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
     296              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     297              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     298              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     299              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     300              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     301              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     302              :     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
     303              :     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
     304              :     0xA1, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     305              :     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     306              : };
     307              : 
     308              : 
     309              : Datum
     310            3 : koi8r_to_mic(PG_FUNCTION_ARGS)
     311              : {
     312            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     313            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     314            3 :     int         len = PG_GETARG_INT32(4);
     315            3 :     bool        noError = PG_GETARG_BOOL(5);
     316              :     int         converted;
     317              : 
     318            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_MULE_INTERNAL);
     319              : 
     320            3 :     converted = latin2mic(src, dest, len, LC_KOI8_R, PG_KOI8R, noError);
     321              : 
     322            3 :     PG_RETURN_INT32(converted);
     323              : }
     324              : 
     325              : Datum
     326          165 : mic_to_koi8r(PG_FUNCTION_ARGS)
     327              : {
     328          165 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     329          165 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     330          165 :     int         len = PG_GETARG_INT32(4);
     331          165 :     bool        noError = PG_GETARG_BOOL(5);
     332              :     int         converted;
     333              : 
     334          165 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_KOI8R);
     335              : 
     336          165 :     converted = mic2latin(src, dest, len, LC_KOI8_R, PG_KOI8R, noError);
     337              : 
     338           93 :     PG_RETURN_INT32(converted);
     339              : }
     340              : 
     341              : Datum
     342           75 : iso_to_mic(PG_FUNCTION_ARGS)
     343              : {
     344           75 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     345           75 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     346           75 :     int         len = PG_GETARG_INT32(4);
     347           75 :     bool        noError = PG_GETARG_BOOL(5);
     348              :     int         converted;
     349              : 
     350           75 :     CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_MULE_INTERNAL);
     351              : 
     352           75 :     converted = latin2mic_with_table(src, dest, len, LC_KOI8_R, PG_ISO_8859_5, iso2koi, noError);
     353              : 
     354           48 :     PG_RETURN_INT32(converted);
     355              : }
     356              : 
     357              : Datum
     358          165 : mic_to_iso(PG_FUNCTION_ARGS)
     359              : {
     360          165 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     361          165 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     362          165 :     int         len = PG_GETARG_INT32(4);
     363          165 :     bool        noError = PG_GETARG_BOOL(5);
     364              :     int         converted;
     365              : 
     366          165 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_ISO_8859_5);
     367              : 
     368          165 :     converted = mic2latin_with_table(src, dest, len, LC_KOI8_R, PG_ISO_8859_5, koi2iso, noError);
     369              : 
     370           93 :     PG_RETURN_INT32(converted);
     371              : }
     372              : 
     373              : Datum
     374            3 : win1251_to_mic(PG_FUNCTION_ARGS)
     375              : {
     376            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     377            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     378            3 :     int         len = PG_GETARG_INT32(4);
     379            3 :     bool        noError = PG_GETARG_BOOL(5);
     380              :     int         converted;
     381              : 
     382            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_MULE_INTERNAL);
     383              : 
     384            3 :     converted = latin2mic_with_table(src, dest, len, LC_KOI8_R, PG_WIN1251, win12512koi, noError);
     385              : 
     386            3 :     PG_RETURN_INT32(converted);
     387              : }
     388              : 
     389              : Datum
     390            3 : mic_to_win1251(PG_FUNCTION_ARGS)
     391              : {
     392            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     393            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     394            3 :     int         len = PG_GETARG_INT32(4);
     395            3 :     bool        noError = PG_GETARG_BOOL(5);
     396              :     int         converted;
     397              : 
     398            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN1251);
     399              : 
     400            3 :     converted = mic2latin_with_table(src, dest, len, LC_KOI8_R, PG_WIN1251, koi2win1251, noError);
     401              : 
     402            3 :     PG_RETURN_INT32(converted);
     403              : }
     404              : 
     405              : Datum
     406            3 : win866_to_mic(PG_FUNCTION_ARGS)
     407              : {
     408            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     409            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     410            3 :     int         len = PG_GETARG_INT32(4);
     411            3 :     bool        noError = PG_GETARG_BOOL(5);
     412              :     int         converted;
     413              : 
     414            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_MULE_INTERNAL);
     415              : 
     416            3 :     converted = latin2mic_with_table(src, dest, len, LC_KOI8_R, PG_WIN866, win8662koi, noError);
     417              : 
     418            3 :     PG_RETURN_INT32(converted);
     419              : }
     420              : 
     421              : Datum
     422            3 : mic_to_win866(PG_FUNCTION_ARGS)
     423              : {
     424            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     425            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     426            3 :     int         len = PG_GETARG_INT32(4);
     427            3 :     bool        noError = PG_GETARG_BOOL(5);
     428              :     int         converted;
     429              : 
     430            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN866);
     431              : 
     432            3 :     converted = mic2latin_with_table(src, dest, len, LC_KOI8_R, PG_WIN866, koi2win866, noError);
     433              : 
     434            3 :     PG_RETURN_INT32(converted);
     435              : }
     436              : 
     437              : Datum
     438            3 : koi8r_to_win1251(PG_FUNCTION_ARGS)
     439              : {
     440            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     441            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     442            3 :     int         len = PG_GETARG_INT32(4);
     443            3 :     bool        noError = PG_GETARG_BOOL(5);
     444              :     int         converted;
     445              : 
     446            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_WIN1251);
     447              : 
     448            3 :     converted = local2local(src, dest, len, PG_KOI8R, PG_WIN1251, koi2win1251, noError);
     449              : 
     450            3 :     PG_RETURN_INT32(converted);
     451              : }
     452              : 
     453              : Datum
     454            3 : win1251_to_koi8r(PG_FUNCTION_ARGS)
     455              : {
     456            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     457            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     458            3 :     int         len = PG_GETARG_INT32(4);
     459            3 :     bool        noError = PG_GETARG_BOOL(5);
     460              :     int         converted;
     461              : 
     462            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_KOI8R);
     463              : 
     464            3 :     converted = local2local(src, dest, len, PG_WIN1251, PG_KOI8R, win12512koi, noError);
     465              : 
     466            3 :     PG_RETURN_INT32(converted);
     467              : }
     468              : 
     469              : Datum
     470            3 : koi8r_to_win866(PG_FUNCTION_ARGS)
     471              : {
     472            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     473            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     474            3 :     int         len = PG_GETARG_INT32(4);
     475            3 :     bool        noError = PG_GETARG_BOOL(5);
     476              :     int         converted;
     477              : 
     478            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_WIN866);
     479              : 
     480            3 :     converted = local2local(src, dest, len, PG_KOI8R, PG_WIN866, koi2win866, noError);
     481              : 
     482            3 :     PG_RETURN_INT32(converted);
     483              : }
     484              : 
     485              : Datum
     486            3 : win866_to_koi8r(PG_FUNCTION_ARGS)
     487              : {
     488            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     489            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     490            3 :     int         len = PG_GETARG_INT32(4);
     491            3 :     bool        noError = PG_GETARG_BOOL(5);
     492              :     int         converted;
     493              : 
     494            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_KOI8R);
     495              : 
     496            3 :     converted = local2local(src, dest, len, PG_WIN866, PG_KOI8R, win8662koi, noError);
     497              : 
     498            3 :     PG_RETURN_INT32(converted);
     499              : }
     500              : 
     501              : Datum
     502            3 : win866_to_win1251(PG_FUNCTION_ARGS)
     503              : {
     504            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     505            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     506            3 :     int         len = PG_GETARG_INT32(4);
     507            3 :     bool        noError = PG_GETARG_BOOL(5);
     508              :     int         converted;
     509              : 
     510            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_WIN1251);
     511              : 
     512            3 :     converted = local2local(src, dest, len, PG_WIN866, PG_WIN1251, win8662win1251, noError);
     513              : 
     514            3 :     PG_RETURN_INT32(converted);
     515              : }
     516              : 
     517              : Datum
     518            3 : win1251_to_win866(PG_FUNCTION_ARGS)
     519              : {
     520            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     521            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     522            3 :     int         len = PG_GETARG_INT32(4);
     523            3 :     bool        noError = PG_GETARG_BOOL(5);
     524              :     int         converted;
     525              : 
     526            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_WIN866);
     527              : 
     528            3 :     converted = local2local(src, dest, len, PG_WIN1251, PG_WIN866, win12512win866, noError);
     529              : 
     530            3 :     PG_RETURN_INT32(converted);
     531              : }
     532              : 
     533              : Datum
     534           75 : iso_to_koi8r(PG_FUNCTION_ARGS)
     535              : {
     536           75 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     537           75 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     538           75 :     int         len = PG_GETARG_INT32(4);
     539           75 :     bool        noError = PG_GETARG_BOOL(5);
     540              :     int         converted;
     541              : 
     542           75 :     CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_KOI8R);
     543              : 
     544           75 :     converted = local2local(src, dest, len, PG_ISO_8859_5, PG_KOI8R, iso2koi, noError);
     545              : 
     546           48 :     PG_RETURN_INT32(converted);
     547              : }
     548              : 
     549              : Datum
     550            3 : koi8r_to_iso(PG_FUNCTION_ARGS)
     551              : {
     552            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     553            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     554            3 :     int         len = PG_GETARG_INT32(4);
     555            3 :     bool        noError = PG_GETARG_BOOL(5);
     556              :     int         converted;
     557              : 
     558            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_ISO_8859_5);
     559              : 
     560            3 :     converted = local2local(src, dest, len, PG_KOI8R, PG_ISO_8859_5, koi2iso, noError);
     561              : 
     562            3 :     PG_RETURN_INT32(converted);
     563              : }
     564              : 
     565              : Datum
     566            3 : iso_to_win1251(PG_FUNCTION_ARGS)
     567              : {
     568            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     569            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     570            3 :     int         len = PG_GETARG_INT32(4);
     571            3 :     bool        noError = PG_GETARG_BOOL(5);
     572              :     int         converted;
     573              : 
     574            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN1251);
     575              : 
     576            3 :     converted = local2local(src, dest, len, PG_ISO_8859_5, PG_WIN1251, iso2win1251, noError);
     577              : 
     578            3 :     PG_RETURN_INT32(converted);
     579              : }
     580              : 
     581              : Datum
     582            3 : win1251_to_iso(PG_FUNCTION_ARGS)
     583              : {
     584            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     585            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     586            3 :     int         len = PG_GETARG_INT32(4);
     587            3 :     bool        noError = PG_GETARG_BOOL(5);
     588              :     int         converted;
     589              : 
     590            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ISO_8859_5);
     591              : 
     592            3 :     converted = local2local(src, dest, len, PG_WIN1251, PG_ISO_8859_5, win12512iso, noError);
     593              : 
     594            3 :     PG_RETURN_INT32(converted);
     595              : }
     596              : 
     597              : Datum
     598            3 : iso_to_win866(PG_FUNCTION_ARGS)
     599              : {
     600            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     601            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     602            3 :     int         len = PG_GETARG_INT32(4);
     603            3 :     bool        noError = PG_GETARG_BOOL(5);
     604              :     int         converted;
     605              : 
     606            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN866);
     607              : 
     608            3 :     converted = local2local(src, dest, len, PG_ISO_8859_5, PG_WIN866, iso2win866, noError);
     609              : 
     610            3 :     PG_RETURN_INT32(converted);
     611              : }
     612              : 
     613              : Datum
     614            3 : win866_to_iso(PG_FUNCTION_ARGS)
     615              : {
     616            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     617            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     618            3 :     int         len = PG_GETARG_INT32(4);
     619            3 :     bool        noError = PG_GETARG_BOOL(5);
     620              :     int         converted;
     621              : 
     622            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_ISO_8859_5);
     623              : 
     624            3 :     converted = local2local(src, dest, len, PG_WIN866, PG_ISO_8859_5, win8662iso, noError);
     625              : 
     626            3 :     PG_RETURN_INT32(converted);
     627              : }
        

Generated by: LCOV version 2.0-1