PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
utf8_and_cyrillic.c
Go to the documentation of this file.
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 
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  * ) returns VOID;
38  * ----------
39  */
40 
41 Datum
43 {
44  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
45  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
46  int len = PG_GETARG_INT32(4);
47 
49 
50  UtfToLocal(src, len, dest,
51  ULmapKOI8R, lengthof(ULmapKOI8R),
52  NULL, 0,
53  NULL,
54  PG_KOI8R);
55 
57 }
58 
59 Datum
61 {
62  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
63  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
64  int len = PG_GETARG_INT32(4);
65 
67 
68  LocalToUtf(src, len, dest,
69  LUmapKOI8R, lengthof(LUmapKOI8R),
70  NULL, 0,
71  NULL,
72  PG_KOI8R);
73 
75 }
76 
77 Datum
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 
85 
86  UtfToLocal(src, len, dest,
87  ULmapKOI8U, lengthof(ULmapKOI8U),
88  NULL, 0,
89  NULL,
90  PG_KOI8U);
91 
93 }
94 
95 Datum
97 {
98  unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
99  unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
100  int len = PG_GETARG_INT32(4);
101 
103 
104  LocalToUtf(src, len, dest,
105  LUmapKOI8U, lengthof(LUmapKOI8U),
106  NULL, 0,
107  NULL,
108  PG_KOI8U);
109 
110  PG_RETURN_VOID();
111 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
PG_MODULE_MAGIC
Datum koi8u_to_utf8(PG_FUNCTION_ARGS)
#define lengthof(array)
Definition: c.h:558
void UtfToLocal(const unsigned char *utf, int len, unsigned char *iso, const pg_utf_to_local *map, int mapsize, const pg_utf_to_local_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding)
Definition: conv.c:390
void LocalToUtf(const unsigned char *iso, int len, unsigned char *utf, const pg_local_to_utf *map, int mapsize, const pg_local_to_utf_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding)
Definition: conv.c:576
Datum koi8r_to_utf8(PG_FUNCTION_ARGS)
uintptr_t Datum
Definition: postgres.h:374
Datum utf8_to_koi8r(PG_FUNCTION_ARGS)
#define PG_RETURN_VOID()
Definition: fmgr.h:293
PG_FUNCTION_INFO_V1(utf8_to_koi8r)
#define NULL
Definition: c.h:226
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:428
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:233
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150
Datum utf8_to_koi8u(PG_FUNCTION_ARGS)