1 /*-------------------------------------------------------------------------
5 * Portions Copyright (c) 1996-2005, 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.13 2006/02/18 16:15:22 petere Exp $
11 *-------------------------------------------------------------------------
16 #include "mb/pg_wchar.h"
17 #include "../../Unicode/utf8_to_koi8r.map"
18 #include "../../Unicode/koi8r_to_utf8.map"
20 PG_FUNCTION_INFO_V1(utf8_to_koi8r);
21 PG_FUNCTION_INFO_V1(koi8r_to_utf8);
23 extern Datum utf8_to_koi8r(PG_FUNCTION_ARGS);
24 extern Datum koi8r_to_utf8(PG_FUNCTION_ARGS);
28 * INTEGER, -- source encoding id
29 * INTEGER, -- destination encoding id
30 * CSTRING, -- source string (null terminated C string)
31 * CSTRING, -- destination string (null terminated C string)
32 * INTEGER -- source string length
38 utf8_to_koi8r(PG_FUNCTION_ARGS)
40 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
41 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
42 int len = PG_GETARG_INT32(4);
44 Assert(PG_GETARG_INT32(0) == PG_UTF8);
45 Assert(PG_GETARG_INT32(1) == PG_KOI8R);
48 UtfToLocal(src, dest, ULmapKOI8R,
49 sizeof(ULmapKOI8R) / sizeof(pg_utf_to_local), len);
55 koi8r_to_utf8(PG_FUNCTION_ARGS)
57 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
58 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
59 int len = PG_GETARG_INT32(4);
61 Assert(PG_GETARG_INT32(0) == PG_KOI8R);
62 Assert(PG_GETARG_INT32(1) == PG_UTF8);
65 LocalToUtf(src, dest, LUmapKOI8R,
66 sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), PG_KOI8R, len);