1 /*-------------------------------------------------------------------------
5 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
9 * $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c,v 1.20 2007/11/15 21:14:40 momjian Exp $
11 *-------------------------------------------------------------------------
16 #include "mb/pg_wchar.h"
17 #include "../../Unicode/utf8_to_koi8r.map"
18 #include "../../Unicode/koi8r_to_utf8.map"
22 PG_FUNCTION_INFO_V1(utf8_to_koi8r);
23 PG_FUNCTION_INFO_V1(koi8r_to_utf8);
25 extern Datum utf8_to_koi8r(PG_FUNCTION_ARGS);
26 extern Datum koi8r_to_utf8(PG_FUNCTION_ARGS);
30 * INTEGER, -- source encoding id
31 * INTEGER, -- destination encoding id
32 * CSTRING, -- source string (null terminated C string)
33 * CSTRING, -- destination string (null terminated C string)
34 * INTEGER -- source string length
40 utf8_to_koi8r(PG_FUNCTION_ARGS)
42 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
43 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
44 int len = PG_GETARG_INT32(4);
46 Assert(PG_GETARG_INT32(0) == PG_UTF8);
47 Assert(PG_GETARG_INT32(1) == PG_KOI8R);
50 UtfToLocal(src, dest, ULmapKOI8R, NULL,
51 sizeof(ULmapKOI8R) / sizeof(pg_utf_to_local), 0, PG_KOI8R, len);
57 koi8r_to_utf8(PG_FUNCTION_ARGS)
59 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
60 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
61 int len = PG_GETARG_INT32(4);
63 Assert(PG_GETARG_INT32(0) == PG_KOI8R);
64 Assert(PG_GETARG_INT32(1) == PG_UTF8);
67 LocalToUtf(src, dest, LUmapKOI8R, NULL,
68 sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), 0, PG_KOI8R, len);