LCOV - code coverage report
Current view: top level - src/backend/utils/mb/conversion_procs/utf8_and_cyrillic - utf8_and_cyrillic.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 37 37 100.0 %
Date: 2024-04-25 05:11:31 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  *    UTF8 and Cyrillic
       4             :  *
       5             :  * Portions Copyright (c) 1996-2024, 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          12 : PG_MODULE_MAGIC;
      23             : 
      24          12 : PG_FUNCTION_INFO_V1(utf8_to_koi8r);
      25           6 : PG_FUNCTION_INFO_V1(koi8r_to_utf8);
      26             : 
      27           6 : PG_FUNCTION_INFO_V1(utf8_to_koi8u);
      28           6 : PG_FUNCTION_INFO_V1(koi8u_to_utf8);
      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             : Datum
      45         438 : utf8_to_koi8r(PG_FUNCTION_ARGS)
      46             : {
      47         438 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      48         438 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      49         438 :     int         len = PG_GETARG_INT32(4);
      50         438 :     bool        noError = PG_GETARG_BOOL(5);
      51             :     int         converted;
      52             : 
      53         438 :     CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8R);
      54             : 
      55         438 :     converted = UtfToLocal(src, len, dest,
      56             :                            &koi8r_from_unicode_tree,
      57             :                            NULL, 0,
      58             :                            NULL,
      59             :                            PG_KOI8R,
      60             :                            noError);
      61             : 
      62         240 :     PG_RETURN_INT32(converted);
      63             : }
      64             : 
      65             : Datum
      66           6 : koi8r_to_utf8(PG_FUNCTION_ARGS)
      67             : {
      68           6 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      69           6 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      70           6 :     int         len = PG_GETARG_INT32(4);
      71           6 :     bool        noError = PG_GETARG_BOOL(5);
      72             :     int         converted;
      73             : 
      74           6 :     CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_UTF8);
      75             : 
      76           6 :     converted = LocalToUtf(src, len, dest,
      77             :                            &koi8r_to_unicode_tree,
      78             :                            NULL, 0,
      79             :                            NULL,
      80             :                            PG_KOI8R,
      81             :                            noError);
      82             : 
      83           6 :     PG_RETURN_INT32(converted);
      84             : }
      85             : 
      86             : Datum
      87           6 : utf8_to_koi8u(PG_FUNCTION_ARGS)
      88             : {
      89           6 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      90           6 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      91           6 :     int         len = PG_GETARG_INT32(4);
      92           6 :     bool        noError = PG_GETARG_BOOL(5);
      93             :     int         converted;
      94             : 
      95           6 :     CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8U);
      96             : 
      97           6 :     converted = UtfToLocal(src, len, dest,
      98             :                            &koi8u_from_unicode_tree,
      99             :                            NULL, 0,
     100             :                            NULL,
     101             :                            PG_KOI8U,
     102             :                            noError);
     103             : 
     104           6 :     PG_RETURN_INT32(converted);
     105             : }
     106             : 
     107             : Datum
     108           6 : koi8u_to_utf8(PG_FUNCTION_ARGS)
     109             : {
     110           6 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     111           6 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     112           6 :     int         len = PG_GETARG_INT32(4);
     113           6 :     bool        noError = PG_GETARG_BOOL(5);
     114             :     int         converted;
     115             : 
     116           6 :     CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8U, PG_UTF8);
     117             : 
     118           6 :     converted = LocalToUtf(src, len, dest,
     119             :                            &koi8u_to_unicode_tree,
     120             :                            NULL, 0,
     121             :                            NULL,
     122             :                            PG_KOI8U,
     123             :                            noError);
     124             : 
     125           6 :     PG_RETURN_INT32(converted);
     126             : }

Generated by: LCOV version 1.14