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

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  *    UTF8 and Cyrillic
       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/utf8_and_cyrillic/utf8_and_cyrillic.c
      10              :  *
      11              :  *-------------------------------------------------------------------------
      12              :  */
      13              : 
      14              : #include "postgres.h"
      15              : #include "fmgr.h"
      16              : #include "mb/pg_wchar.h"
      17              : #include "../../Unicode/utf8_to_koi8r.map"
      18              : #include "../../Unicode/koi8r_to_utf8.map"
      19              : #include "../../Unicode/utf8_to_koi8u.map"
      20              : #include "../../Unicode/koi8u_to_utf8.map"
      21              : 
      22            6 : PG_MODULE_MAGIC_EXT(
      23              :                     .name = "utf8_and_cyrillic",
      24              :                     .version = PG_VERSION
      25              : );
      26              : 
      27            6 : PG_FUNCTION_INFO_V1(utf8_to_koi8r);
      28            3 : PG_FUNCTION_INFO_V1(koi8r_to_utf8);
      29              : 
      30            3 : PG_FUNCTION_INFO_V1(utf8_to_koi8u);
      31            3 : PG_FUNCTION_INFO_V1(koi8u_to_utf8);
      32              : 
      33              : /* ----------
      34              :  * conv_proc(
      35              :  *      INTEGER,    -- source encoding id
      36              :  *      INTEGER,    -- destination encoding id
      37              :  *      CSTRING,    -- source string (null terminated C string)
      38              :  *      CSTRING,    -- destination string (null terminated C string)
      39              :  *      INTEGER,    -- source string length
      40              :  *      BOOL        -- if true, don't throw an error if conversion fails
      41              :  * ) returns INTEGER;
      42              :  *
      43              :  * Returns the number of bytes successfully converted.
      44              :  * ----------
      45              :  */
      46              : 
      47              : Datum
      48          219 : utf8_to_koi8r(PG_FUNCTION_ARGS)
      49              : {
      50          219 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      51          219 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      52          219 :     int         len = PG_GETARG_INT32(4);
      53          219 :     bool        noError = PG_GETARG_BOOL(5);
      54              :     int         converted;
      55              : 
      56          219 :     CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8R);
      57              : 
      58          219 :     converted = UtfToLocal(src, len, dest,
      59              :                            &koi8r_from_unicode_tree,
      60              :                            NULL, 0,
      61              :                            NULL,
      62              :                            PG_KOI8R,
      63              :                            noError);
      64              : 
      65          120 :     PG_RETURN_INT32(converted);
      66              : }
      67              : 
      68              : Datum
      69            3 : koi8r_to_utf8(PG_FUNCTION_ARGS)
      70              : {
      71            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      72            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      73            3 :     int         len = PG_GETARG_INT32(4);
      74            3 :     bool        noError = PG_GETARG_BOOL(5);
      75              :     int         converted;
      76              : 
      77            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_UTF8);
      78              : 
      79            3 :     converted = LocalToUtf(src, len, dest,
      80              :                            &koi8r_to_unicode_tree,
      81              :                            NULL, 0,
      82              :                            NULL,
      83              :                            PG_KOI8R,
      84              :                            noError);
      85              : 
      86            3 :     PG_RETURN_INT32(converted);
      87              : }
      88              : 
      89              : Datum
      90            3 : utf8_to_koi8u(PG_FUNCTION_ARGS)
      91              : {
      92            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      93            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      94            3 :     int         len = PG_GETARG_INT32(4);
      95            3 :     bool        noError = PG_GETARG_BOOL(5);
      96              :     int         converted;
      97              : 
      98            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8U);
      99              : 
     100            3 :     converted = UtfToLocal(src, len, dest,
     101              :                            &koi8u_from_unicode_tree,
     102              :                            NULL, 0,
     103              :                            NULL,
     104              :                            PG_KOI8U,
     105              :                            noError);
     106              : 
     107            3 :     PG_RETURN_INT32(converted);
     108              : }
     109              : 
     110              : Datum
     111            3 : koi8u_to_utf8(PG_FUNCTION_ARGS)
     112              : {
     113            3 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     114            3 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     115            3 :     int         len = PG_GETARG_INT32(4);
     116            3 :     bool        noError = PG_GETARG_BOOL(5);
     117              :     int         converted;
     118              : 
     119            3 :     CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8U, PG_UTF8);
     120              : 
     121            3 :     converted = LocalToUtf(src, len, dest,
     122              :                            &koi8u_to_unicode_tree,
     123              :                            NULL, 0,
     124              :                            NULL,
     125              :                            PG_KOI8U,
     126              :                            noError);
     127              : 
     128            3 :     PG_RETURN_INT32(converted);
     129              : }
        

Generated by: LCOV version 2.0-1