PostgreSQL Source Code git master
cyrillic_and_mic.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * Cyrillic and MULE_INTERNAL
4 *
5 * Portions Copyright (c) 1996-2025, 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/cyrillic_and_mic/cyrillic_and_mic.c
10 *
11 *-------------------------------------------------------------------------
12 */
13
14#include "postgres.h"
15#include "fmgr.h"
16#include "mb/pg_wchar.h"
17
19 .name = "cyrillic_and_mic",
20 .version = PG_VERSION
21);
22
43
44/* ----------
45 * conv_proc(
46 * INTEGER, -- source encoding id
47 * INTEGER, -- destination encoding id
48 * CSTRING, -- source string (null terminated C string)
49 * CSTRING, -- destination string (null terminated C string)
50 * INTEGER, -- source string length
51 * BOOL -- if true, don't throw an error if conversion fails
52 * ) returns INTEGER;
53 *
54 * Returns the number of bytes successfully converted.
55 * ----------
56 */
57
58/*
59 * Cyrillic support
60 * currently supported Cyrillic encodings:
61 *
62 * KOI8-R (this is also the charset for the mule internal code for Cyrillic)
63 * ISO-8859-5
64 * Microsoft's CP1251 (windows-1251)
65 * Alternativny Variant (MS-DOS CP866)
66 */
67
68/* ISO-8859-5 to KOI8-R */
69static const unsigned char iso2koi[] = {
70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74 0x00, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76 0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA,
77 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0,
78 0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE,
79 0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1,
80 0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA,
81 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0,
82 0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE,
83 0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1,
84 0x00, 0xA3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
86};
87
88/* KOI8-R to ISO-8859-5 */
89static const unsigned char koi2iso[] = {
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00, 0xF1, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x00, 0x00, 0x00, 0xA1, 0x00, 0x00, 0x00, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98 0xEE, 0xD0, 0xD1, 0xE6, 0xD4, 0xD5, 0xE4, 0xD3,
99 0xE5, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE,
100 0xDF, 0xEF, 0xE0, 0xE1, 0xE2, 0xE3, 0xD6, 0xD2,
101 0xEC, 0xEB, 0xD7, 0xE8, 0xED, 0xE9, 0xE7, 0xEA,
102 0xCE, 0xB0, 0xB1, 0xC6, 0xB4, 0xB5, 0xC4, 0xB3,
103 0xC5, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE,
104 0xBF, 0xCF, 0xC0, 0xC1, 0xC2, 0xC3, 0xB6, 0xB2,
105 0xCC, 0xCB, 0xB7, 0xC8, 0xCD, 0xC9, 0xC7, 0xCA
106};
107
108/* WIN1251 to KOI8-R */
109static const unsigned char win12512koi[] = {
110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114 0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00,
115 0xB3, 0x00, 0xB4, 0x00, 0x00, 0x00, 0x00, 0xB7,
116 0x00, 0x00, 0xB6, 0xA6, 0xAD, 0x00, 0x00, 0x00,
117 0xA3, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, 0xA7,
118 0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA,
119 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0,
120 0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE,
121 0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1,
122 0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA,
123 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0,
124 0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE,
125 0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1
126};
127
128/* KOI8-R to WIN1251 */
129static const unsigned char koi2win1251[] = {
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0xB8, 0xBA, 0x00, 0xB3, 0xBF,
135 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00,
136 0x00, 0x00, 0x00, 0xA8, 0xAA, 0x00, 0xB2, 0xAF,
137 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00,
138 0xFE, 0xE0, 0xE1, 0xF6, 0xE4, 0xE5, 0xF4, 0xE3,
139 0xF5, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE,
140 0xEF, 0xFF, 0xF0, 0xF1, 0xF2, 0xF3, 0xE6, 0xE2,
141 0xFC, 0xFB, 0xE7, 0xF8, 0xFD, 0xF9, 0xF7, 0xFA,
142 0xDE, 0xC0, 0xC1, 0xD6, 0xC4, 0xC5, 0xD4, 0xC3,
143 0xD5, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE,
144 0xCF, 0xDF, 0xD0, 0xD1, 0xD2, 0xD3, 0xC6, 0xC2,
145 0xDC, 0xDB, 0xC7, 0xD8, 0xDD, 0xD9, 0xD7, 0xDA
146};
147
148/* WIN866 to KOI8-R */
149static const unsigned char win8662koi[] = {
150 0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA,
151 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0,
152 0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE,
153 0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1,
154 0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA,
155 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0,
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157 0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00,
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162 0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE,
163 0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1,
164 0xB3, 0xA3, 0xB4, 0xA4, 0xB7, 0xA7, 0x00, 0x00,
165 0xB6, 0xA6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
166};
167
168/* KOI8-R to WIN866 */
169static const unsigned char koi2win866[] = {
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x00, 0xF1, 0xF3, 0x00, 0xF9, 0xF5,
175 0x00, 0x00, 0x00, 0x00, 0x00, 0xAD, 0x00, 0x00,
176 0x00, 0x00, 0x00, 0xF0, 0xF2, 0x00, 0xF8, 0xF4,
177 0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00,
178 0xEE, 0xA0, 0xA1, 0xE6, 0xA4, 0xA5, 0xE4, 0xA3,
179 0xE5, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE,
180 0xAF, 0xEF, 0xE0, 0xE1, 0xE2, 0xE3, 0xA6, 0xA2,
181 0xEC, 0xEB, 0xA7, 0xE8, 0xED, 0xE9, 0xE7, 0xEA,
182 0x9E, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83,
183 0x95, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E,
184 0x8F, 0x9F, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82,
185 0x9C, 0x9B, 0x87, 0x98, 0x9D, 0x99, 0x97, 0x9A
186};
187
188/* WIN866 to WIN1251 */
189static const unsigned char win8662win1251[] = {
190 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
191 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
192 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
193 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
194 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
195 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x00,
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
203 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
204 0xA8, 0xB8, 0xAA, 0xBA, 0xAF, 0xBF, 0x00, 0x00,
205 0xB2, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
206};
207
208/* WIN1251 to WIN866 */
209static const unsigned char win12512win866[] = {
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214 0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00,
215 0xF0, 0x00, 0xF2, 0x00, 0x00, 0x00, 0x00, 0xF4,
216 0x00, 0x00, 0xF8, 0xF9, 0xAD, 0x00, 0x00, 0x00,
217 0xF1, 0x00, 0xF3, 0x00, 0x00, 0x00, 0x00, 0xF5,
218 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
219 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
220 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
221 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
222 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
223 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
224 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
225 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF
226};
227
228/* ISO-8859-5 to WIN1251 */
229static const unsigned char iso2win1251[] = {
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
237 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
238 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
239 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
240 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
241 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
242 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
243 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
244 0x00, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
246};
247
248/* WIN1251 to ISO-8859-5 */
249static const unsigned char win12512iso[] = {
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
259 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
260 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
261 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
262 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
263 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
264 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
265 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF
266};
267
268/* ISO-8859-5 to WIN866 */
269static const unsigned char iso2win866[] = {
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
277 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
278 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
279 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
280 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
281 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
282 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
283 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
284 0x00, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
286};
287
288/* WIN866 to ISO-8859-5 */
289static const unsigned char win8662iso[] = {
290 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
291 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
292 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
293 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
294 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
295 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
303 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
304 0xA1, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
306};
307
308
309Datum
311{
312 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
313 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
314 int len = PG_GETARG_INT32(4);
315 bool noError = PG_GETARG_BOOL(5);
316 int converted;
317
319
320 converted = latin2mic(src, dest, len, LC_KOI8_R, PG_KOI8R, noError);
321
322 PG_RETURN_INT32(converted);
323}
324
325Datum
327{
328 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
329 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
330 int len = PG_GETARG_INT32(4);
331 bool noError = PG_GETARG_BOOL(5);
332 int converted;
333
335
336 converted = mic2latin(src, dest, len, LC_KOI8_R, PG_KOI8R, noError);
337
338 PG_RETURN_INT32(converted);
339}
340
341Datum
343{
344 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
345 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
346 int len = PG_GETARG_INT32(4);
347 bool noError = PG_GETARG_BOOL(5);
348 int converted;
349
351
352 converted = latin2mic_with_table(src, dest, len, LC_KOI8_R, PG_ISO_8859_5, iso2koi, noError);
353
354 PG_RETURN_INT32(converted);
355}
356
357Datum
359{
360 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
361 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
362 int len = PG_GETARG_INT32(4);
363 bool noError = PG_GETARG_BOOL(5);
364 int converted;
365
367
368 converted = mic2latin_with_table(src, dest, len, LC_KOI8_R, PG_ISO_8859_5, koi2iso, noError);
369
370 PG_RETURN_INT32(converted);
371}
372
373Datum
375{
376 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
377 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
378 int len = PG_GETARG_INT32(4);
379 bool noError = PG_GETARG_BOOL(5);
380 int converted;
381
383
384 converted = latin2mic_with_table(src, dest, len, LC_KOI8_R, PG_WIN1251, win12512koi, noError);
385
386 PG_RETURN_INT32(converted);
387}
388
389Datum
391{
392 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
393 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
394 int len = PG_GETARG_INT32(4);
395 bool noError = PG_GETARG_BOOL(5);
396 int converted;
397
399
400 converted = mic2latin_with_table(src, dest, len, LC_KOI8_R, PG_WIN1251, koi2win1251, noError);
401
402 PG_RETURN_INT32(converted);
403}
404
405Datum
407{
408 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
409 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
410 int len = PG_GETARG_INT32(4);
411 bool noError = PG_GETARG_BOOL(5);
412 int converted;
413
415
416 converted = latin2mic_with_table(src, dest, len, LC_KOI8_R, PG_WIN866, win8662koi, noError);
417
418 PG_RETURN_INT32(converted);
419}
420
421Datum
423{
424 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
425 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
426 int len = PG_GETARG_INT32(4);
427 bool noError = PG_GETARG_BOOL(5);
428 int converted;
429
431
432 converted = mic2latin_with_table(src, dest, len, LC_KOI8_R, PG_WIN866, koi2win866, noError);
433
434 PG_RETURN_INT32(converted);
435}
436
437Datum
439{
440 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
441 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
442 int len = PG_GETARG_INT32(4);
443 bool noError = PG_GETARG_BOOL(5);
444 int converted;
445
447
448 converted = local2local(src, dest, len, PG_KOI8R, PG_WIN1251, koi2win1251, noError);
449
450 PG_RETURN_INT32(converted);
451}
452
453Datum
455{
456 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
457 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
458 int len = PG_GETARG_INT32(4);
459 bool noError = PG_GETARG_BOOL(5);
460 int converted;
461
463
464 converted = local2local(src, dest, len, PG_WIN1251, PG_KOI8R, win12512koi, noError);
465
466 PG_RETURN_INT32(converted);
467}
468
469Datum
471{
472 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
473 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
474 int len = PG_GETARG_INT32(4);
475 bool noError = PG_GETARG_BOOL(5);
476 int converted;
477
479
480 converted = local2local(src, dest, len, PG_KOI8R, PG_WIN866, koi2win866, noError);
481
482 PG_RETURN_INT32(converted);
483}
484
485Datum
487{
488 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
489 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
490 int len = PG_GETARG_INT32(4);
491 bool noError = PG_GETARG_BOOL(5);
492 int converted;
493
495
496 converted = local2local(src, dest, len, PG_WIN866, PG_KOI8R, win8662koi, noError);
497
498 PG_RETURN_INT32(converted);
499}
500
501Datum
503{
504 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
505 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
506 int len = PG_GETARG_INT32(4);
507 bool noError = PG_GETARG_BOOL(5);
508 int converted;
509
511
512 converted = local2local(src, dest, len, PG_WIN866, PG_WIN1251, win8662win1251, noError);
513
514 PG_RETURN_INT32(converted);
515}
516
517Datum
519{
520 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
521 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
522 int len = PG_GETARG_INT32(4);
523 bool noError = PG_GETARG_BOOL(5);
524 int converted;
525
527
528 converted = local2local(src, dest, len, PG_WIN1251, PG_WIN866, win12512win866, noError);
529
530 PG_RETURN_INT32(converted);
531}
532
533Datum
535{
536 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
537 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
538 int len = PG_GETARG_INT32(4);
539 bool noError = PG_GETARG_BOOL(5);
540 int converted;
541
543
544 converted = local2local(src, dest, len, PG_ISO_8859_5, PG_KOI8R, iso2koi, noError);
545
546 PG_RETURN_INT32(converted);
547}
548
549Datum
551{
552 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
553 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
554 int len = PG_GETARG_INT32(4);
555 bool noError = PG_GETARG_BOOL(5);
556 int converted;
557
559
560 converted = local2local(src, dest, len, PG_KOI8R, PG_ISO_8859_5, koi2iso, noError);
561
562 PG_RETURN_INT32(converted);
563}
564
565Datum
567{
568 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
569 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
570 int len = PG_GETARG_INT32(4);
571 bool noError = PG_GETARG_BOOL(5);
572 int converted;
573
575
576 converted = local2local(src, dest, len, PG_ISO_8859_5, PG_WIN1251, iso2win1251, noError);
577
578 PG_RETURN_INT32(converted);
579}
580
581Datum
583{
584 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
585 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
586 int len = PG_GETARG_INT32(4);
587 bool noError = PG_GETARG_BOOL(5);
588 int converted;
589
591
592 converted = local2local(src, dest, len, PG_WIN1251, PG_ISO_8859_5, win12512iso, noError);
593
594 PG_RETURN_INT32(converted);
595}
596
597Datum
599{
600 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
601 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
602 int len = PG_GETARG_INT32(4);
603 bool noError = PG_GETARG_BOOL(5);
604 int converted;
605
607
608 converted = local2local(src, dest, len, PG_ISO_8859_5, PG_WIN866, iso2win866, noError);
609
610 PG_RETURN_INT32(converted);
611}
612
613Datum
615{
616 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
617 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
618 int len = PG_GETARG_INT32(4);
619 bool noError = PG_GETARG_BOOL(5);
620 int converted;
621
623
624 converted = local2local(src, dest, len, PG_WIN866, PG_ISO_8859_5, win8662iso, noError);
625
626 PG_RETURN_INT32(converted);
627}
int mic2latin_with_table(const unsigned char *mic, unsigned char *p, int len, int lc, int encoding, const unsigned char *tab, bool noError)
Definition: conv.c:257
int latin2mic_with_table(const unsigned char *l, unsigned char *p, int len, int lc, int encoding, const unsigned char *tab, bool noError)
Definition: conv.c:194
int mic2latin(const unsigned char *mic, unsigned char *p, int len, int lc, int encoding, bool noError)
Definition: conv.c:127
int local2local(const unsigned char *l, unsigned char *p, int len, int src_encoding, int dest_encoding, const unsigned char *tab, bool noError)
Definition: conv.c:33
int latin2mic(const unsigned char *l, unsigned char *p, int len, int lc, int encoding, bool noError)
Definition: conv.c:89
static const unsigned char win8662koi[]
static const unsigned char iso2win866[]
Datum win866_to_win1251(PG_FUNCTION_ARGS)
Datum win1251_to_win866(PG_FUNCTION_ARGS)
static const unsigned char win12512win866[]
Datum koi8r_to_win1251(PG_FUNCTION_ARGS)
Datum win1251_to_mic(PG_FUNCTION_ARGS)
static const unsigned char win8662iso[]
Datum iso_to_win866(PG_FUNCTION_ARGS)
static const unsigned char win12512iso[]
static const unsigned char koi2iso[]
Datum win866_to_iso(PG_FUNCTION_ARGS)
static const unsigned char win12512koi[]
static const unsigned char iso2win1251[]
Datum win866_to_mic(PG_FUNCTION_ARGS)
Datum mic_to_win1251(PG_FUNCTION_ARGS)
Datum iso_to_mic(PG_FUNCTION_ARGS)
Datum koi8r_to_iso(PG_FUNCTION_ARGS)
static const unsigned char win8662win1251[]
static const unsigned char koi2win1251[]
static const unsigned char koi2win866[]
Datum win866_to_koi8r(PG_FUNCTION_ARGS)
Datum win1251_to_iso(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC_EXT(.name="cyrillic_and_mic",.version=PG_VERSION)
PG_FUNCTION_INFO_V1(koi8r_to_mic)
Datum mic_to_iso(PG_FUNCTION_ARGS)
Datum iso_to_koi8r(PG_FUNCTION_ARGS)
Datum koi8r_to_mic(PG_FUNCTION_ARGS)
Datum mic_to_win866(PG_FUNCTION_ARGS)
static const unsigned char iso2koi[]
Datum win1251_to_koi8r(PG_FUNCTION_ARGS)
Datum iso_to_win1251(PG_FUNCTION_ARGS)
Datum mic_to_koi8r(PG_FUNCTION_ARGS)
Datum koi8r_to_win866(PG_FUNCTION_ARGS)
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
const void size_t len
#define LC_KOI8_R
Definition: pg_wchar.h:119
@ PG_KOI8R
Definition: pg_wchar.h:248
@ PG_MULE_INTERNAL
Definition: pg_wchar.h:233
@ PG_ISO_8859_5
Definition: pg_wchar.h:251
@ PG_WIN1251
Definition: pg_wchar.h:249
@ PG_WIN866
Definition: pg_wchar.h:246
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:507
uintptr_t Datum
Definition: postgres.h:69
const char * name