LCOV - code coverage report
Current view: top level - src/backend/utils/mb/conversion_procs/utf8_and_uhc - utf8_and_uhc.c (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 19 19 100.0 %
Date: 2025-04-01 16:15:31 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14