1 /*-------------------------------------------------------------------------
5 * Portions Copyright (c) 1996-2004, 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.8 2004/08/29 04:12:57 momjian Exp $
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_win1251.map"
20 #include "../../Unicode/win1251_to_utf8.map"
21 #include "../../Unicode/utf8_to_alt.map"
22 #include "../../Unicode/alt_to_utf8.map"
24 PG_FUNCTION_INFO_V1(utf8_to_koi8r);
25 PG_FUNCTION_INFO_V1(koi8r_to_utf8);
26 PG_FUNCTION_INFO_V1(utf8_to_win1251);
27 PG_FUNCTION_INFO_V1(win1251_to_utf8);
28 PG_FUNCTION_INFO_V1(utf8_to_alt);
29 PG_FUNCTION_INFO_V1(alt_to_utf8);
31 extern Datum utf8_to_koi8r(PG_FUNCTION_ARGS);
32 extern Datum koi8r_to_utf8(PG_FUNCTION_ARGS);
33 extern Datum utf8_to_win1251(PG_FUNCTION_ARGS);
34 extern Datum win1251_to_utf8(PG_FUNCTION_ARGS);
35 extern Datum utf8_to_alt(PG_FUNCTION_ARGS);
36 extern Datum alt_to_utf8(PG_FUNCTION_ARGS);
40 * INTEGER, -- source encoding id
41 * INTEGER, -- destination encoding id
42 * CSTRING, -- source string (null terminated C string)
43 * CSTRING, -- destination string (null terminated C string)
44 * INTEGER -- source string length
50 utf8_to_koi8r(PG_FUNCTION_ARGS)
52 unsigned char *src = PG_GETARG_CSTRING(2);
53 unsigned char *dest = PG_GETARG_CSTRING(3);
54 int len = PG_GETARG_INT32(4);
56 Assert(PG_GETARG_INT32(0) == PG_UTF8);
57 Assert(PG_GETARG_INT32(1) == PG_KOI8R);
60 UtfToLocal(src, dest, ULmap_KOI8R,
61 sizeof(ULmap_KOI8R) / sizeof(pg_utf_to_local), len);
67 koi8r_to_utf8(PG_FUNCTION_ARGS)
69 unsigned char *src = PG_GETARG_CSTRING(2);
70 unsigned char *dest = PG_GETARG_CSTRING(3);
71 int len = PG_GETARG_INT32(4);
73 Assert(PG_GETARG_INT32(0) == PG_KOI8R);
74 Assert(PG_GETARG_INT32(1) == PG_UTF8);
77 LocalToUtf(src, dest, LUmapKOI8R,
78 sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), PG_KOI8R, len);
84 utf8_to_win1251(PG_FUNCTION_ARGS)
86 unsigned char *src = PG_GETARG_CSTRING(2);
87 unsigned char *dest = PG_GETARG_CSTRING(3);
88 int len = PG_GETARG_INT32(4);
90 Assert(PG_GETARG_INT32(0) == PG_UTF8);
91 Assert(PG_GETARG_INT32(1) == PG_WIN1251);
94 UtfToLocal(src, dest, ULmap_WIN1251,
95 sizeof(ULmap_WIN1251) / sizeof(pg_utf_to_local), len);
101 win1251_to_utf8(PG_FUNCTION_ARGS)
103 unsigned char *src = PG_GETARG_CSTRING(2);
104 unsigned char *dest = PG_GETARG_CSTRING(3);
105 int len = PG_GETARG_INT32(4);
107 Assert(PG_GETARG_INT32(0) == PG_WIN1251);
108 Assert(PG_GETARG_INT32(1) == PG_UTF8);
111 LocalToUtf(src, dest, LUmapWIN1251,
112 sizeof(LUmapWIN1251) / sizeof(pg_local_to_utf), PG_WIN1251, len);
118 utf8_to_alt(PG_FUNCTION_ARGS)
120 unsigned char *src = PG_GETARG_CSTRING(2);
121 unsigned char *dest = PG_GETARG_CSTRING(3);
122 int len = PG_GETARG_INT32(4);
124 Assert(PG_GETARG_INT32(0) == PG_UTF8);
125 Assert(PG_GETARG_INT32(1) == PG_ALT);
128 UtfToLocal(src, dest, ULmap_ALT,
129 sizeof(ULmap_ALT) / sizeof(pg_utf_to_local), len);
135 alt_to_utf8(PG_FUNCTION_ARGS)
137 unsigned char *src = PG_GETARG_CSTRING(2);
138 unsigned char *dest = PG_GETARG_CSTRING(3);
139 int len = PG_GETARG_INT32(4);
141 Assert(PG_GETARG_INT32(0) == PG_ALT);
142 Assert(PG_GETARG_INT32(1) == PG_UTF8);
145 LocalToUtf(src, dest, LUmapALT,
146 sizeof(LUmapALT) / sizeof(pg_local_to_utf), PG_ALT, len);