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
26
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 * BOOL -- if true, don't throw an error if conversion fails
38 * ) returns INTEGER;
39 *
40 * Returns the number of bytes successfully converted.
41 * ----------
42 */
43
46{
47 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
48 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
49 int len = PG_GETARG_INT32(4);
50 bool noError = PG_GETARG_BOOL(5);
51 int converted;
52
54
55 converted = UtfToLocal(src, len, dest,
56 &koi8r_from_unicode_tree,
57 NULL, 0,
58 NULL,
60 noError);
61
62 PG_RETURN_INT32(converted);
63}
64
67{
68 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
69 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
70 int len = PG_GETARG_INT32(4);
71 bool noError = PG_GETARG_BOOL(5);
72 int converted;
73
75
76 converted = LocalToUtf(src, len, dest,
77 &koi8r_to_unicode_tree,
78 NULL, 0,
79 NULL,
81 noError);
82
83 PG_RETURN_INT32(converted);
84}
85
88{
89 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
90 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
91 int len = PG_GETARG_INT32(4);
92 bool noError = PG_GETARG_BOOL(5);
93 int converted;
94
96
97 converted = UtfToLocal(src, len, dest,
98 &koi8u_from_unicode_tree,
99 NULL, 0,
100 NULL,
101 PG_KOI8U,
102 noError);
103
104 PG_RETURN_INT32(converted);
105}
106
107Datum
109{
110 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
111 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
112 int len = PG_GETARG_INT32(4);
113 bool noError = PG_GETARG_BOOL(5);
114 int converted;
115
117
118 converted = LocalToUtf(src, len, dest,
119 &koi8u_to_unicode_tree,
120 NULL, 0,
121 NULL,
122 PG_KOI8U,
123 noError);
124
125 PG_RETURN_INT32(converted);
126}
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
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)