Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions | Variables

euc_kr_and_mic.c File Reference

#include "postgres.h"
#include "fmgr.h"
#include "mb/pg_wchar.h"
Include dependency graph for euc_kr_and_mic.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (euc_kr_to_mic)
 PG_FUNCTION_INFO_V1 (mic_to_euc_kr)
Datum euc_kr_to_mic (PG_FUNCTION_ARGS)
Datum mic_to_euc_kr (PG_FUNCTION_ARGS)
static void euc_kr2mic (const unsigned char *euc, unsigned char *p, int len)
static void mic2euc_kr (const unsigned char *mic, unsigned char *p, int len)

Variables

 PG_MODULE_MAGIC

Function Documentation

static void euc_kr2mic ( const unsigned char *  euc,
unsigned char *  p,
int  len 
) [static]

Definition at line 72 of file euc_kr_and_mic.c.

References IS_HIGHBIT_SET, pg_encoding_verifymb(), PG_EUC_KR, and report_invalid_encoding().

Referenced by euc_kr_to_mic().

{
    int         c1;
    int         l;

    while (len > 0)
    {
        c1 = *euc;
        if (IS_HIGHBIT_SET(c1))
        {
            l = pg_encoding_verifymb(PG_EUC_KR, (const char *) euc, len);
            if (l != 2)
                report_invalid_encoding(PG_EUC_KR,
                                        (const char *) euc, len);
            *p++ = LC_KS5601;
            *p++ = c1;
            *p++ = euc[1];
            euc += 2;
            len -= 2;
        }
        else
        {                       /* should be ASCII */
            if (c1 == 0)
                report_invalid_encoding(PG_EUC_KR,
                                        (const char *) euc, len);
            *p++ = c1;
            euc++;
            len--;
        }
    }
    *p = '\0';
}

Datum euc_kr_to_mic ( PG_FUNCTION_ARGS   ) 

Definition at line 41 of file euc_kr_and_mic.c.

References CHECK_ENCODING_CONVERSION_ARGS, euc_kr2mic(), PG_EUC_KR, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_MULE_INTERNAL, and PG_RETURN_VOID.

{
    unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
    unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
    int         len = PG_GETARG_INT32(4);

    CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_KR, PG_MULE_INTERNAL);

    euc_kr2mic(src, dest, len);

    PG_RETURN_VOID();
}

static void mic2euc_kr ( const unsigned char *  mic,
unsigned char *  p,
int  len 
) [static]

Definition at line 109 of file euc_kr_and_mic.c.

References IS_HIGHBIT_SET, LC_KS5601, pg_encoding_verifymb(), PG_EUC_KR, PG_MULE_INTERNAL, report_invalid_encoding(), and report_untranslatable_char().

Referenced by mic_to_euc_kr().

{
    int         c1;
    int         l;

    while (len > 0)
    {
        c1 = *mic;
        if (!IS_HIGHBIT_SET(c1))
        {
            /* ASCII */
            if (c1 == 0)
                report_invalid_encoding(PG_MULE_INTERNAL,
                                        (const char *) mic, len);
            *p++ = c1;
            mic++;
            len--;
            continue;
        }
        l = pg_encoding_verifymb(PG_MULE_INTERNAL, (const char *) mic, len);
        if (l < 0)
            report_invalid_encoding(PG_MULE_INTERNAL,
                                    (const char *) mic, len);
        if (c1 == LC_KS5601)
        {
            *p++ = mic[1];
            *p++ = mic[2];
        }
        else
            report_untranslatable_char(PG_MULE_INTERNAL, PG_EUC_KR,
                                       (const char *) mic, len);
        mic += l;
        len -= l;
    }
    *p = '\0';
}

Datum mic_to_euc_kr ( PG_FUNCTION_ARGS   ) 

Definition at line 55 of file euc_kr_and_mic.c.

References CHECK_ENCODING_CONVERSION_ARGS, mic2euc_kr(), PG_EUC_KR, PG_GETARG_CSTRING, PG_GETARG_INT32, PG_MULE_INTERNAL, and PG_RETURN_VOID.

{
    unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
    unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
    int         len = PG_GETARG_INT32(4);

    CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_KR);

    mic2euc_kr(src, dest, len);

    PG_RETURN_VOID();
}

PG_FUNCTION_INFO_V1 ( euc_kr_to_mic   ) 
PG_FUNCTION_INFO_V1 ( mic_to_euc_kr   ) 

Variable Documentation

Definition at line 18 of file euc_kr_and_mic.c.