PostgreSQL Source Code git master
utf8_and_cyrillic.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * UTF8 and Cyrillic
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/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
23 .name = "utf8_and_cyrillic",
24 .version = PG_VERSION
25);
26
29
32
33/* ----------
34 * conv_proc(
35 * INTEGER, -- source encoding id
36 * INTEGER, -- destination encoding id
37 * CSTRING, -- source string (null terminated C string)
38 * CSTRING, -- destination string (null terminated C string)
39 * INTEGER, -- source string length
40 * BOOL -- if true, don't throw an error if conversion fails
41 * ) returns INTEGER;
42 *
43 * Returns the number of bytes successfully converted.
44 * ----------
45 */
46
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 bool noError = PG_GETARG_BOOL(5);
54 int converted;
55
57
58 converted = UtfToLocal(src, len, dest,
59 &koi8r_from_unicode_tree,
60 NULL, 0,
61 NULL,
63 noError);
64
65 PG_RETURN_INT32(converted);
66}
67
70{
71 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
72 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
73 int len = PG_GETARG_INT32(4);
74 bool noError = PG_GETARG_BOOL(5);
75 int converted;
76
78
79 converted = LocalToUtf(src, len, dest,
80 &koi8r_to_unicode_tree,
81 NULL, 0,
82 NULL,
84 noError);
85
86 PG_RETURN_INT32(converted);
87}
88
91{
92 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
93 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
94 int len = PG_GETARG_INT32(4);
95 bool noError = PG_GETARG_BOOL(5);
96 int converted;
97
99
100 converted = UtfToLocal(src, len, dest,
101 &koi8u_from_unicode_tree,
102 NULL, 0,
103 NULL,
104 PG_KOI8U,
105 noError);
106
107 PG_RETURN_INT32(converted);
108}
109
110Datum
112{
113 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
114 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
115 int len = PG_GETARG_INT32(4);
116 bool noError = PG_GETARG_BOOL(5);
117 int converted;
118
120
121 converted = LocalToUtf(src, len, dest,
122 &koi8u_to_unicode_tree,
123 NULL, 0,
124 NULL,
125 PG_KOI8U,
126 noError);
127
128 PG_RETURN_INT32(converted);
129}
int UtfToLocal(const unsigned char *utf, int len, unsigned char *iso, const pg_mb_radix_tree *map, const pg_utf_to_local_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding, bool noError)
Definition: conv.c:507
int LocalToUtf(const unsigned char *iso, int len, unsigned char *utf, const pg_mb_radix_tree *map, const pg_local_to_utf_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding, bool noError)
Definition: conv.c:717
#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
@ PG_KOI8R
Definition: pg_wchar.h:248
@ PG_KOI8U
Definition: pg_wchar.h:260
@ PG_UTF8
Definition: pg_wchar.h:232
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:507
uintptr_t Datum
Definition: postgres.h:69
Datum utf8_to_koi8r(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC_EXT(.name="utf8_and_cyrillic",.version=PG_VERSION)
Datum utf8_to_koi8u(PG_FUNCTION_ARGS)
Datum koi8r_to_utf8(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(utf8_to_koi8r)
Datum koi8u_to_utf8(PG_FUNCTION_ARGS)
const char * name