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

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  *    LATINn and MULE_INTERNAL
       4             :  *
       5             :  * Portions Copyright (c) 1996-2021, 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;
      19             : 
      20           4 : PG_FUNCTION_INFO_V1(latin1_to_mic);
      21           4 : PG_FUNCTION_INFO_V1(mic_to_latin1);
      22           4 : PG_FUNCTION_INFO_V1(latin3_to_mic);
      23           4 : PG_FUNCTION_INFO_V1(mic_to_latin3);
      24           4 : PG_FUNCTION_INFO_V1(latin4_to_mic);
      25           4 : PG_FUNCTION_INFO_V1(mic_to_latin4);
      26             : 
      27             : /* ----------
      28             :  * conv_proc(
      29             :  *      INTEGER,    -- source encoding id
      30             :  *      INTEGER,    -- destination encoding id
      31             :  *      CSTRING,    -- source string (null terminated C string)
      32             :  *      CSTRING,    -- destination string (null terminated C string)
      33             :  *      INTEGER,    -- source string length
      34             :  *      BOOL        -- if true, don't throw an error if conversion fails
      35             :  * ) returns INTEGER;
      36             :  *
      37             :  * Returns the number of bytes successfully converted.
      38             :  * ----------
      39             :  */
      40             : 
      41             : 
      42             : Datum
      43           4 : latin1_to_mic(PG_FUNCTION_ARGS)
      44             : {
      45           4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      46           4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      47           4 :     int         len = PG_GETARG_INT32(4);
      48           4 :     bool        noError = PG_GETARG_BOOL(5);
      49             :     int         converted;
      50             : 
      51           4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_MULE_INTERNAL);
      52             : 
      53           4 :     converted = latin2mic(src, dest, len, LC_ISO8859_1, PG_LATIN1, noError);
      54             : 
      55           4 :     PG_RETURN_INT32(converted);
      56             : }
      57             : 
      58             : Datum
      59           4 : mic_to_latin1(PG_FUNCTION_ARGS)
      60             : {
      61           4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      62           4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      63           4 :     int         len = PG_GETARG_INT32(4);
      64           4 :     bool        noError = PG_GETARG_BOOL(5);
      65             :     int         converted;
      66             : 
      67           4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN1);
      68             : 
      69           4 :     converted = mic2latin(src, dest, len, LC_ISO8859_1, PG_LATIN1, noError);
      70             : 
      71           4 :     PG_RETURN_INT32(converted);
      72             : }
      73             : 
      74             : Datum
      75           4 : latin3_to_mic(PG_FUNCTION_ARGS)
      76             : {
      77           4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      78           4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      79           4 :     int         len = PG_GETARG_INT32(4);
      80           4 :     bool        noError = PG_GETARG_BOOL(5);
      81             :     int         converted;
      82             : 
      83           4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN3, PG_MULE_INTERNAL);
      84             : 
      85           4 :     converted = latin2mic(src, dest, len, LC_ISO8859_3, PG_LATIN3, noError);
      86             : 
      87           4 :     PG_RETURN_INT32(converted);
      88             : }
      89             : 
      90             : Datum
      91           4 : mic_to_latin3(PG_FUNCTION_ARGS)
      92             : {
      93           4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      94           4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      95           4 :     int         len = PG_GETARG_INT32(4);
      96           4 :     bool        noError = PG_GETARG_BOOL(5);
      97             :     int         converted;
      98             : 
      99           4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN3);
     100             : 
     101           4 :     converted = mic2latin(src, dest, len, LC_ISO8859_3, PG_LATIN3, noError);
     102             : 
     103           4 :     PG_RETURN_INT32(converted);
     104             : }
     105             : 
     106             : Datum
     107           4 : latin4_to_mic(PG_FUNCTION_ARGS)
     108             : {
     109           4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     110           4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     111           4 :     int         len = PG_GETARG_INT32(4);
     112           4 :     bool        noError = PG_GETARG_BOOL(5);
     113             :     int         converted;
     114             : 
     115           4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN4, PG_MULE_INTERNAL);
     116             : 
     117           4 :     converted = latin2mic(src, dest, len, LC_ISO8859_4, PG_LATIN4, noError);
     118             : 
     119           4 :     PG_RETURN_INT32(converted);
     120             : }
     121             : 
     122             : Datum
     123           4 : mic_to_latin4(PG_FUNCTION_ARGS)
     124             : {
     125           4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
     126           4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
     127           4 :     int         len = PG_GETARG_INT32(4);
     128           4 :     bool        noError = PG_GETARG_BOOL(5);
     129             :     int         converted;
     130             : 
     131           4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN4);
     132             : 
     133           4 :     converted = mic2latin(src, dest, len, LC_ISO8859_4, PG_LATIN4, noError);
     134             : 
     135           4 :     PG_RETURN_INT32(converted);
     136             : }

Generated by: LCOV version 1.13