OSDN Git Service

pgindent run for 8.3.
[pg-rex/syncrep.git] / src / backend / utils / mb / conversion_procs / utf8_and_euc_kr / utf8_and_euc_kr.c
1 /*-------------------------------------------------------------------------
2  *
3  *        EUC_KR <--> UTF8
4  *
5  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
6  * Portions Copyright (c) 1994, Regents of the University of California
7  *
8  * IDENTIFICATION
9  *        $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c,v 1.18 2007/11/15 21:14:40 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 #include "postgres.h"
15 #include "fmgr.h"
16 #include "mb/pg_wchar.h"
17 #include "../../Unicode/euc_kr_to_utf8.map"
18 #include "../../Unicode/utf8_to_euc_kr.map"
19
20 PG_MODULE_MAGIC;
21
22 PG_FUNCTION_INFO_V1(euc_kr_to_utf8);
23 PG_FUNCTION_INFO_V1(utf8_to_euc_kr);
24
25 extern Datum euc_kr_to_utf8(PG_FUNCTION_ARGS);
26 extern Datum utf8_to_euc_kr(PG_FUNCTION_ARGS);
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  * ) returns VOID;
36  * ----------
37  */
38 Datum
39 euc_kr_to_utf8(PG_FUNCTION_ARGS)
40 {
41         unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
42         unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
43         int                     len = PG_GETARG_INT32(4);
44
45         Assert(PG_GETARG_INT32(0) == PG_EUC_KR);
46         Assert(PG_GETARG_INT32(1) == PG_UTF8);
47         Assert(len >= 0);
48
49         LocalToUtf(src, dest, LUmapEUC_KR, NULL,
50                    sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), 0, PG_EUC_KR, len);
51
52         PG_RETURN_VOID();
53 }
54
55 Datum
56 utf8_to_euc_kr(PG_FUNCTION_ARGS)
57 {
58         unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
59         unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
60         int                     len = PG_GETARG_INT32(4);
61
62         Assert(PG_GETARG_INT32(0) == PG_UTF8);
63         Assert(PG_GETARG_INT32(1) == PG_EUC_KR);
64         Assert(len >= 0);
65
66         UtfToLocal(src, dest, ULmapEUC_KR, NULL,
67                    sizeof(ULmapEUC_KR) / sizeof(pg_utf_to_local), 0, PG_EUC_KR, len);
68
69         PG_RETURN_VOID();
70 }