LCOV - code coverage report
Current view: top level - src/backend/utils/mb/conversion_procs/latin2_and_win1250 - latin2_and_win1250.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 55 55
Test Date: 2026-03-03 10:15:07 Functions: 100.0 % 13 13
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  *    LATIN2 and WIN1250
       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/latin2_and_win1250/latin2_and_win1250.c
      10              :  *
      11              :  *-------------------------------------------------------------------------
      12              :  */
      13              : 
      14              : #include "postgres.h"
      15              : #include "fmgr.h"
      16              : #include "mb/pg_wchar.h"
      17              : 
      18            3 : PG_MODULE_MAGIC_EXT(
      19              :                     .name = "latin2_and_win1250",
      20              :                     .version = PG_VERSION
      21              : );
      22              : 
      23            3 : PG_FUNCTION_INFO_V1(latin2_to_mic);
      24            3 : PG_FUNCTION_INFO_V1(mic_to_latin2);
      25            3 : PG_FUNCTION_INFO_V1(win1250_to_mic);
      26            3 : PG_FUNCTION_INFO_V1(mic_to_win1250);
      27            3 : PG_FUNCTION_INFO_V1(latin2_to_win1250);
      28            3 : PG_FUNCTION_INFO_V1(win1250_to_latin2);
      29              : 
      30              : /* ----------
      31              :  * conv_proc(
      32              :  *      INTEGER,    -- source encoding id
      33              :  *      INTEGER,    -- destination encoding id
      34              :  *      CSTRING,    -- source string (null terminated C string)
      35              :  *      CSTRING,    -- destination string (null terminated C string)
      36              :  *      INTEGER,    -- source string length
      37              :  *      BOOL        -- if true, don't throw an error if conversion fails
      38              :  * ) returns INTEGER;
      39              :  *
      40              :  * Returns the number of bytes successfully converted.
      41              :  * ----------
      42              :  */
      43              : 
      44              : /* WIN1250 to ISO-8859-2 */
      45              : static const unsigned char win1250_2_iso88592[] = {
      46              :     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
      47              :     0x88, 0x89, 0xA9, 0x8B, 0xA6, 0xAB, 0xAE, 0xAC,
      48              :     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
      49              :     0x98, 0x99, 0xB9, 0x9B, 0xB6, 0xBB, 0xBE, 0xBC,
      50              :     0xA0, 0xB7, 0xA2, 0xA3, 0xA4, 0xA1, 0x00, 0xA7,
      51              :     0xA8, 0x00, 0xAA, 0x00, 0x00, 0xAD, 0x00, 0xAF,
      52              :     0xB0, 0x00, 0xB2, 0xB3, 0xB4, 0x00, 0x00, 0x00,
      53              :     0xB8, 0xB1, 0xBA, 0x00, 0xA5, 0xBD, 0xB5, 0xBF,
      54              :     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
      55              :     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
      56              :     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
      57              :     0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
      58              :     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
      59              :     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
      60              :     0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
      61              :     0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
      62              : };
      63              : 
      64              : /* ISO-8859-2 to WIN1250 */
      65              : static const unsigned char iso88592_2_win1250[] = {
      66              :     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
      67              :     0x88, 0x89, 0x00, 0x8B, 0x00, 0x00, 0x00, 0x00,
      68              :     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
      69              :     0x98, 0x99, 0x00, 0x9B, 0x00, 0x00, 0x00, 0x00,
      70              :     0xA0, 0xA5, 0xA2, 0xA3, 0xA4, 0xBC, 0x8C, 0xA7,
      71              :     0xA8, 0x8A, 0xAA, 0x8D, 0x8F, 0xAD, 0x8E, 0xAF,
      72              :     0xB0, 0xB9, 0xB2, 0xB3, 0xB4, 0xBE, 0x9C, 0xA1,
      73              :     0xB8, 0x9A, 0xBA, 0x9D, 0x9F, 0xBD, 0x9E, 0xBF,
      74              :     0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
      75              :     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
      76              :     0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
      77              :     0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
      78              :     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
      79              :     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
      80              :     0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
      81              :     0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
      82              : };
      83              : 
      84              : 
      85              : Datum
      86            3 : latin2_to_mic(PG_FUNCTION_ARGS)
      87              : {
      88            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      89            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      90            3 :     int         len = PG_GETARG_INT32(4);
      91            3 :     bool        noError = PG_GETARG_BOOL(5);
      92              :     int         converted;
      93              : 
      94            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_MULE_INTERNAL);
      95              : 
      96            3 :     converted = latin2mic(src, dest, len, LC_ISO8859_2, PG_LATIN2, noError);
      97              : 
      98            3 :     PG_RETURN_INT32(converted);
      99              : }
     100              : 
     101              : Datum
     102            3 : mic_to_latin2(PG_FUNCTION_ARGS)
     103              : {
     104            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     105            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     106            3 :     int         len = PG_GETARG_INT32(4);
     107            3 :     bool        noError = PG_GETARG_BOOL(5);
     108              :     int         converted;
     109              : 
     110            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN2);
     111              : 
     112            3 :     converted = mic2latin(src, dest, len, LC_ISO8859_2, PG_LATIN2, noError);
     113              : 
     114            3 :     PG_RETURN_INT32(converted);
     115              : }
     116              : 
     117              : Datum
     118            3 : win1250_to_mic(PG_FUNCTION_ARGS)
     119              : {
     120            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     121            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     122            3 :     int         len = PG_GETARG_INT32(4);
     123            3 :     bool        noError = PG_GETARG_BOOL(5);
     124              :     int         converted;
     125              : 
     126            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_MULE_INTERNAL);
     127              : 
     128            3 :     converted = latin2mic_with_table(src, dest, len, LC_ISO8859_2, PG_WIN1250,
     129              :                                      win1250_2_iso88592, noError);
     130              : 
     131            3 :     PG_RETURN_INT32(converted);
     132              : }
     133              : 
     134              : Datum
     135            3 : mic_to_win1250(PG_FUNCTION_ARGS)
     136              : {
     137            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     138            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     139            3 :     int         len = PG_GETARG_INT32(4);
     140            3 :     bool        noError = PG_GETARG_BOOL(5);
     141              :     int         converted;
     142              : 
     143            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN1250);
     144              : 
     145            3 :     converted = mic2latin_with_table(src, dest, len, LC_ISO8859_2, PG_WIN1250,
     146              :                                      iso88592_2_win1250, noError);
     147              : 
     148            3 :     PG_RETURN_INT32(converted);
     149              : }
     150              : 
     151              : Datum
     152            3 : latin2_to_win1250(PG_FUNCTION_ARGS)
     153              : {
     154            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     155            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     156            3 :     int         len = PG_GETARG_INT32(4);
     157            3 :     bool        noError = PG_GETARG_BOOL(5);
     158              :     int         converted;
     159              : 
     160            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_WIN1250);
     161              : 
     162            3 :     converted = local2local(src, dest, len, PG_LATIN2, PG_WIN1250,
     163              :                             iso88592_2_win1250, noError);
     164              : 
     165            3 :     PG_RETURN_INT32(converted);
     166              : }
     167              : 
     168              : Datum
     169            3 : win1250_to_latin2(PG_FUNCTION_ARGS)
     170              : {
     171            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     172            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     173            3 :     int         len = PG_GETARG_INT32(4);
     174            3 :     bool        noError = PG_GETARG_BOOL(5);
     175              :     int         converted;
     176              : 
     177            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_LATIN2);
     178              : 
     179            3 :     converted = local2local(src, dest, len, PG_WIN1250, PG_LATIN2,
     180              :                             win1250_2_iso88592, noError);
     181              : 
     182            3 :     PG_RETURN_INT32(converted);
     183              : }
        

Generated by: LCOV version 2.0-1