1 /*-------------------------------------------------------------------------
5 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c
11 *-------------------------------------------------------------------------
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"
24 PG_FUNCTION_INFO_V1(utf8_to_koi8r);
25 PG_FUNCTION_INFO_V1(koi8r_to_utf8);
27 PG_FUNCTION_INFO_V1(utf8_to_koi8u);
28 PG_FUNCTION_INFO_V1(koi8u_to_utf8);
30 extern Datum utf8_to_koi8r(PG_FUNCTION_ARGS);
31 extern Datum koi8r_to_utf8(PG_FUNCTION_ARGS);
33 extern Datum utf8_to_koi8u(PG_FUNCTION_ARGS);
34 extern Datum koi8u_to_utf8(PG_FUNCTION_ARGS);
38 * INTEGER, -- source encoding id
39 * INTEGER, -- destination encoding id
40 * CSTRING, -- source string (null terminated C string)
41 * CSTRING, -- destination string (null terminated C string)
42 * INTEGER -- source string length
48 utf8_to_koi8r(PG_FUNCTION_ARGS)
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);
54 CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8R);
56 UtfToLocal(src, dest, ULmapKOI8R, NULL,
57 sizeof(ULmapKOI8R) / sizeof(pg_utf_to_local), 0, PG_KOI8R, len);
63 koi8r_to_utf8(PG_FUNCTION_ARGS)
65 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
66 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
67 int len = PG_GETARG_INT32(4);
69 CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_UTF8);
71 LocalToUtf(src, dest, LUmapKOI8R, NULL,
72 sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), 0, PG_KOI8R, len);
78 utf8_to_koi8u(PG_FUNCTION_ARGS)
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);
84 CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8U);
86 UtfToLocal(src, dest, ULmapKOI8U, NULL,
87 sizeof(ULmapKOI8U) / sizeof(pg_utf_to_local), 0, PG_KOI8U, len);
93 koi8u_to_utf8(PG_FUNCTION_ARGS)
95 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
96 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
97 int len = PG_GETARG_INT32(4);
99 CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8U, PG_UTF8);
101 LocalToUtf(src, dest, LUmapKOI8U, NULL,
102 sizeof(LUmapKOI8U) / sizeof(pg_local_to_utf), 0, PG_KOI8U, len);