]> granicus.if.org Git - postgresql/blob - src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c
Remove cvs keywords from all files.
[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-2010, 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_cyrillic/utf8_and_cyrillic.c
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 #include "../../Unicode/utf8_to_koi8u.map"
20 #include "../../Unicode/koi8u_to_utf8.map"
21
22 PG_MODULE_MAGIC;
23
24 PG_FUNCTION_INFO_V1(utf8_to_koi8r);
25 PG_FUNCTION_INFO_V1(koi8r_to_utf8);
26
27 PG_FUNCTION_INFO_V1(utf8_to_koi8u);
28 PG_FUNCTION_INFO_V1(koi8u_to_utf8);
29
30 extern Datum utf8_to_koi8r(PG_FUNCTION_ARGS);
31 extern Datum koi8r_to_utf8(PG_FUNCTION_ARGS);
32
33 extern Datum utf8_to_koi8u(PG_FUNCTION_ARGS);
34 extern Datum koi8u_to_utf8(PG_FUNCTION_ARGS);
35
36 /* ----------
37  * conv_proc(
38  *              INTEGER,        -- source encoding id
39  *              INTEGER,        -- destination encoding id
40  *              CSTRING,        -- source string (null terminated C string)
41  *              CSTRING,        -- destination string (null terminated C string)
42  *              INTEGER         -- source string length
43  * ) returns VOID;
44  * ----------
45  */
46
47 Datum
48 utf8_to_koi8r(PG_FUNCTION_ARGS)
49 {
50         unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
51         unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
52         int                     len = PG_GETARG_INT32(4);
53
54         CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8R);
55
56         UtfToLocal(src, dest, ULmapKOI8R, NULL,
57                          sizeof(ULmapKOI8R) / sizeof(pg_utf_to_local), 0, PG_KOI8R, len);
58
59         PG_RETURN_VOID();
60 }
61
62 Datum
63 koi8r_to_utf8(PG_FUNCTION_ARGS)
64 {
65         unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
66         unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
67         int                     len = PG_GETARG_INT32(4);
68
69         CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_UTF8);
70
71         LocalToUtf(src, dest, LUmapKOI8R, NULL,
72                          sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), 0, PG_KOI8R, len);
73
74         PG_RETURN_VOID();
75 }
76
77 Datum
78 utf8_to_koi8u(PG_FUNCTION_ARGS)
79 {
80         unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
81         unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
82         int                     len = PG_GETARG_INT32(4);
83
84         CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8U);
85
86         UtfToLocal(src, dest, ULmapKOI8U, NULL,
87                          sizeof(ULmapKOI8U) / sizeof(pg_utf_to_local), 0, PG_KOI8U, len);
88
89         PG_RETURN_VOID();
90 }
91
92 Datum
93 koi8u_to_utf8(PG_FUNCTION_ARGS)
94 {
95         unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
96         unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
97         int                     len = PG_GETARG_INT32(4);
98
99         CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8U, PG_UTF8);
100
101         LocalToUtf(src, dest, LUmapKOI8U, NULL,
102                          sizeof(LUmapKOI8U) / sizeof(pg_local_to_utf), 0, PG_KOI8U, len);
103
104         PG_RETURN_VOID();
105 }