]> granicus.if.org Git - postgresql/blob - src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c
pgindent run for 8.2.
[postgresql] / src / backend / utils / mb / conversion_procs / utf8_and_cyrillic / utf8_and_cyrillic.c
1 /*-------------------------------------------------------------------------
2  *
3  *        UTF8 and Cyrillic
4  *
5  * Portions Copyright (c) 1996-2006, 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_cyrillic/utf8_and_cyrillic.c,v 1.17 2006/10/04 00:30:02 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 #include "postgres.h"
15 #include "fmgr.h"
16 #include "mb/pg_wchar.h"
17 #include "../../Unicode/utf8_to_koi8r.map"
18 #include "../../Unicode/koi8r_to_utf8.map"
19
20 PG_MODULE_MAGIC;
21
22 PG_FUNCTION_INFO_V1(utf8_to_koi8r);
23 PG_FUNCTION_INFO_V1(koi8r_to_utf8);
24
25 extern Datum utf8_to_koi8r(PG_FUNCTION_ARGS);
26 extern Datum koi8r_to_utf8(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
39 Datum
40 utf8_to_koi8r(PG_FUNCTION_ARGS)
41 {
42         unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
43         unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
44         int                     len = PG_GETARG_INT32(4);
45
46         Assert(PG_GETARG_INT32(0) == PG_UTF8);
47         Assert(PG_GETARG_INT32(1) == PG_KOI8R);
48         Assert(len >= 0);
49
50         UtfToLocal(src, dest, ULmapKOI8R,
51                            sizeof(ULmapKOI8R) / sizeof(pg_utf_to_local), PG_KOI8R, len);
52
53         PG_RETURN_VOID();
54 }
55
56 Datum
57 koi8r_to_utf8(PG_FUNCTION_ARGS)
58 {
59         unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
60         unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
61         int                     len = PG_GETARG_INT32(4);
62
63         Assert(PG_GETARG_INT32(0) == PG_KOI8R);
64         Assert(PG_GETARG_INT32(1) == PG_UTF8);
65         Assert(len >= 0);
66
67         LocalToUtf(src, dest, LUmapKOI8R,
68                            sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), PG_KOI8R, len);
69
70         PG_RETURN_VOID();
71 }