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

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  *    LATINn 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/latin_and_mic/latin_and_mic.c
      10              :  *
      11              :  *-------------------------------------------------------------------------
      12              :  */
      13              : 
      14              : #include "postgres.h"
      15              : #include "fmgr.h"
      16              : #include "mb/pg_wchar.h"
      17              : 
      18            4 : PG_MODULE_MAGIC_EXT(
      19              :                     .name = "latin_and_mic",
      20              :                     .version = PG_VERSION
      21              : );
      22              : 
      23            4 : PG_FUNCTION_INFO_V1(latin1_to_mic);
      24            4 : PG_FUNCTION_INFO_V1(mic_to_latin1);
      25            4 : PG_FUNCTION_INFO_V1(latin3_to_mic);
      26            4 : PG_FUNCTION_INFO_V1(mic_to_latin3);
      27            4 : PG_FUNCTION_INFO_V1(latin4_to_mic);
      28            4 : PG_FUNCTION_INFO_V1(mic_to_latin4);
      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              : 
      45              : Datum
      46            4 : latin1_to_mic(PG_FUNCTION_ARGS)
      47              : {
      48            4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      49            4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      50            4 :     int         len = PG_GETARG_INT32(4);
      51            4 :     bool        noError = PG_GETARG_BOOL(5);
      52              :     int         converted;
      53              : 
      54            4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_MULE_INTERNAL);
      55              : 
      56            4 :     converted = latin2mic(src, dest, len, LC_ISO8859_1, PG_LATIN1, noError);
      57              : 
      58            4 :     PG_RETURN_INT32(converted);
      59              : }
      60              : 
      61              : Datum
      62            4 : mic_to_latin1(PG_FUNCTION_ARGS)
      63              : {
      64            4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      65            4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      66            4 :     int         len = PG_GETARG_INT32(4);
      67            4 :     bool        noError = PG_GETARG_BOOL(5);
      68              :     int         converted;
      69              : 
      70            4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN1);
      71              : 
      72            4 :     converted = mic2latin(src, dest, len, LC_ISO8859_1, PG_LATIN1, noError);
      73              : 
      74            4 :     PG_RETURN_INT32(converted);
      75              : }
      76              : 
      77              : Datum
      78            4 : latin3_to_mic(PG_FUNCTION_ARGS)
      79              : {
      80            4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      81            4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      82            4 :     int         len = PG_GETARG_INT32(4);
      83            4 :     bool        noError = PG_GETARG_BOOL(5);
      84              :     int         converted;
      85              : 
      86            4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN3, PG_MULE_INTERNAL);
      87              : 
      88            4 :     converted = latin2mic(src, dest, len, LC_ISO8859_3, PG_LATIN3, noError);
      89              : 
      90            4 :     PG_RETURN_INT32(converted);
      91              : }
      92              : 
      93              : Datum
      94            4 : mic_to_latin3(PG_FUNCTION_ARGS)
      95              : {
      96            4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      97            4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      98            4 :     int         len = PG_GETARG_INT32(4);
      99            4 :     bool        noError = PG_GETARG_BOOL(5);
     100              :     int         converted;
     101              : 
     102            4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN3);
     103              : 
     104            4 :     converted = mic2latin(src, dest, len, LC_ISO8859_3, PG_LATIN3, noError);
     105              : 
     106            4 :     PG_RETURN_INT32(converted);
     107              : }
     108              : 
     109              : Datum
     110            4 : latin4_to_mic(PG_FUNCTION_ARGS)
     111              : {
     112            4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     113            4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     114            4 :     int         len = PG_GETARG_INT32(4);
     115            4 :     bool        noError = PG_GETARG_BOOL(5);
     116              :     int         converted;
     117              : 
     118            4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN4, PG_MULE_INTERNAL);
     119              : 
     120            4 :     converted = latin2mic(src, dest, len, LC_ISO8859_4, PG_LATIN4, noError);
     121              : 
     122            4 :     PG_RETURN_INT32(converted);
     123              : }
     124              : 
     125              : Datum
     126            4 : mic_to_latin4(PG_FUNCTION_ARGS)
     127              : {
     128            4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     129            4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     130            4 :     int         len = PG_GETARG_INT32(4);
     131            4 :     bool        noError = PG_GETARG_BOOL(5);
     132              :     int         converted;
     133              : 
     134            4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN4);
     135              : 
     136            4 :     converted = mic2latin(src, dest, len, LC_ISO8859_4, PG_LATIN4, noError);
     137              : 
     138            4 :     PG_RETURN_INT32(converted);
     139              : }
        

Generated by: LCOV version 2.0-1