LCOV - code coverage report
Current view: top level - src/backend/utils/mb/conversion_procs/utf8_and_euc2004 - utf8_and_euc2004.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17beta1 Lines: 19 19 100.0 %
Date: 2024-06-14 19:10:57 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  *    EUC_JIS_2004 <--> UTF8
       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_euc2004/utf8_and_euc2004.c
      10             :  *
      11             :  *-------------------------------------------------------------------------
      12             :  */
      13             : 
      14             : #include "postgres.h"
      15             : #include "fmgr.h"
      16             : #include "mb/pg_wchar.h"
      17             : #include "../../Unicode/euc_jis_2004_to_utf8.map"
      18             : #include "../../Unicode/utf8_to_euc_jis_2004.map"
      19             : 
      20          12 : PG_MODULE_MAGIC;
      21             : 
      22          12 : PG_FUNCTION_INFO_V1(euc_jis_2004_to_utf8);
      23          12 : PG_FUNCTION_INFO_V1(utf8_to_euc_jis_2004);
      24             : 
      25             : /* ----------
      26             :  * conv_proc(
      27             :  *      INTEGER,    -- source encoding id
      28             :  *      INTEGER,    -- destination encoding id
      29             :  *      CSTRING,    -- source string (null terminated C string)
      30             :  *      CSTRING,    -- destination string (null terminated C string)
      31             :  *      INTEGER,    -- source string length
      32             :  *      BOOL        -- if true, don't throw an error if conversion fails
      33             :  * ) returns INTEGER;
      34             :  *
      35             :  * Returns the number of bytes successfully converted.
      36             :  * ----------
      37             :  */
      38             : Datum
      39         240 : euc_jis_2004_to_utf8(PG_FUNCTION_ARGS)
      40             : {
      41         240 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      42         240 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      43         240 :     int         len = PG_GETARG_INT32(4);
      44         240 :     bool        noError = PG_GETARG_BOOL(5);
      45             :     int         converted;
      46             : 
      47         240 :     CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JIS_2004, PG_UTF8);
      48             : 
      49         240 :     converted = LocalToUtf(src, len, dest,
      50             :                            &euc_jis_2004_to_unicode_tree,
      51             :                            LUmapEUC_JIS_2004_combined, lengthof(LUmapEUC_JIS_2004_combined),
      52             :                            NULL,
      53             :                            PG_EUC_JIS_2004,
      54             :                            noError);
      55             : 
      56         150 :     PG_RETURN_INT32(converted);
      57             : }
      58             : 
      59             : Datum
      60         366 : utf8_to_euc_jis_2004(PG_FUNCTION_ARGS)
      61             : {
      62         366 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      63         366 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      64         366 :     int         len = PG_GETARG_INT32(4);
      65         366 :     bool        noError = PG_GETARG_BOOL(5);
      66             :     int         converted;
      67             : 
      68         366 :     CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_JIS_2004);
      69             : 
      70         366 :     converted = UtfToLocal(src, len, dest,
      71             :                            &euc_jis_2004_from_unicode_tree,
      72             :                            ULmapEUC_JIS_2004_combined, lengthof(ULmapEUC_JIS_2004_combined),
      73             :                            NULL,
      74             :                            PG_EUC_JIS_2004,
      75             :                            noError);
      76             : 
      77         240 :     PG_RETURN_INT32(converted);
      78             : }

Generated by: LCOV version 1.14