LCOV - code coverage report
Current view: top level - src/backend/utils/mb/conversion_procs/utf8_and_ascii - utf8_and_ascii.c (source / functions) Hit Total Coverage
Test: PostgreSQL Lines: 17 17 100.0 %
Date: 2017-09-29 15:12:54 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  *    ASCII <--> UTF8
       4             :  *
       5             :  * Portions Copyright (c) 1996-2017, 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_ascii/utf8_and_ascii.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           6 : PG_FUNCTION_INFO_V1(ascii_to_utf8);
      21           4 : PG_FUNCTION_INFO_V1(utf8_to_ascii);
      22             : 
      23             : /* ----------
      24             :  * conv_proc(
      25             :  *      INTEGER,    -- source encoding id
      26             :  *      INTEGER,    -- destination encoding id
      27             :  *      CSTRING,    -- source string (null terminated C string)
      28             :  *      CSTRING,    -- destination string (null terminated C string)
      29             :  *      INTEGER     -- source string length
      30             :  * ) returns VOID;
      31             :  * ----------
      32             :  */
      33             : 
      34             : Datum
      35           4 : ascii_to_utf8(PG_FUNCTION_ARGS)
      36             : {
      37           4 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      38           4 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      39           4 :     int         len = PG_GETARG_INT32(4);
      40             : 
      41           4 :     CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_UTF8);
      42             : 
      43             :     /* this looks wrong, but basically we're just rejecting high-bit-set */
      44           4 :     pg_ascii2mic(src, dest, len);
      45             : 
      46           4 :     PG_RETURN_VOID();
      47             : }
      48             : 
      49             : Datum
      50           2 : utf8_to_ascii(PG_FUNCTION_ARGS)
      51             : {
      52           2 :     unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
      53           2 :     unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
      54           2 :     int         len = PG_GETARG_INT32(4);
      55             : 
      56           2 :     CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SQL_ASCII);
      57             : 
      58             :     /* this looks wrong, but basically we're just rejecting high-bit-set */
      59           2 :     pg_mic2ascii(src, dest, len);
      60             : 
      61           2 :     PG_RETURN_VOID();
      62             : }

Generated by: LCOV version 1.11