Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * UTF8 and Cyrillic
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_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 4 : PG_MODULE_MAGIC;
23 :
24 6 : PG_FUNCTION_INFO_V1(utf8_to_koi8r);
25 6 : PG_FUNCTION_INFO_V1(koi8r_to_utf8);
26 :
27 6 : PG_FUNCTION_INFO_V1(utf8_to_koi8u);
28 6 : PG_FUNCTION_INFO_V1(koi8u_to_utf8);
29 :
30 : /* ----------
31 : * conv_proc(
32 : * INTEGER, -- source encoding id
33 : * INTEGER, -- destination encoding id
34 : * CSTRING, -- source string (null terminated C string)
35 : * CSTRING, -- destination string (null terminated C string)
36 : * INTEGER -- source string length
37 : * ) returns VOID;
38 : * ----------
39 : */
40 :
41 : Datum
42 4 : utf8_to_koi8r(PG_FUNCTION_ARGS)
43 : {
44 4 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
45 4 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
46 4 : int len = PG_GETARG_INT32(4);
47 :
48 4 : CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8R);
49 :
50 4 : UtfToLocal(src, len, dest,
51 : &koi8r_from_unicode_tree,
52 : NULL, 0,
53 : NULL,
54 : PG_KOI8R);
55 :
56 4 : PG_RETURN_VOID();
57 : }
58 :
59 : Datum
60 4 : koi8r_to_utf8(PG_FUNCTION_ARGS)
61 : {
62 4 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
63 4 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
64 4 : int len = PG_GETARG_INT32(4);
65 :
66 4 : CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_UTF8);
67 :
68 4 : LocalToUtf(src, len, dest,
69 : &koi8r_to_unicode_tree,
70 : NULL, 0,
71 : NULL,
72 : PG_KOI8R);
73 :
74 4 : PG_RETURN_VOID();
75 : }
76 :
77 : Datum
78 4 : utf8_to_koi8u(PG_FUNCTION_ARGS)
79 : {
80 4 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
81 4 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
82 4 : int len = PG_GETARG_INT32(4);
83 :
84 4 : CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8U);
85 :
86 4 : UtfToLocal(src, len, dest,
87 : &koi8u_from_unicode_tree,
88 : NULL, 0,
89 : NULL,
90 : PG_KOI8U);
91 :
92 4 : PG_RETURN_VOID();
93 : }
94 :
95 : Datum
96 4 : koi8u_to_utf8(PG_FUNCTION_ARGS)
97 : {
98 4 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
99 4 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
100 4 : int len = PG_GETARG_INT32(4);
101 :
102 4 : CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8U, PG_UTF8);
103 :
104 4 : LocalToUtf(src, len, dest,
105 : &koi8u_to_unicode_tree,
106 : NULL, 0,
107 : NULL,
108 : PG_KOI8U);
109 :
110 4 : PG_RETURN_VOID();
111 : }
|