1/*-------------------------------------------------------------------------
2 *
3 * LATINn and MULE_INTERNAL
4 *
5 * Portions Copyright (c) 1996-2019, 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/latin_and_mic/latin_and_mic.c
10 *
11 *-------------------------------------------------------------------------
12 */
13
14#include "postgres.h"
15#include "fmgr.h"
16#include "mb/pg_wchar.h"
17
18PG_MODULE_MAGIC;
19
20PG_FUNCTION_INFO_V1(latin1_to_mic);
21PG_FUNCTION_INFO_V1(mic_to_latin1);
22PG_FUNCTION_INFO_V1(latin3_to_mic);
23PG_FUNCTION_INFO_V1(mic_to_latin3);
24PG_FUNCTION_INFO_V1(latin4_to_mic);
25PG_FUNCTION_INFO_V1(mic_to_latin4);
26
27/* ----------
28 * conv_proc(
29 * INTEGER, -- source encoding id
30 * INTEGER, -- destination encoding id
31 * CSTRING, -- source string (null terminated C string)
32 * CSTRING, -- destination string (null terminated C string)
33 * INTEGER -- source string length
34 * ) returns VOID;
35 * ----------
36 */
37
38
39Datum
40latin1_to_mic(PG_FUNCTION_ARGS)
41{
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);
45
46 CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_MULE_INTERNAL);
47
48 latin2mic(src, dest, len, LC_ISO8859_1, PG_LATIN1);
49
50 PG_RETURN_VOID();
51}
52
53Datum
54mic_to_latin1(PG_FUNCTION_ARGS)
55{
56 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
57 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
58 int len = PG_GETARG_INT32(4);
59
60 CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN1);
61
62 mic2latin(src, dest, len, LC_ISO8859_1, PG_LATIN1);
63
64 PG_RETURN_VOID();
65}
66
67Datum
68latin3_to_mic(PG_FUNCTION_ARGS)
69{
70 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
71 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
72 int len = PG_GETARG_INT32(4);
73
74 CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN3, PG_MULE_INTERNAL);
75
76 latin2mic(src, dest, len, LC_ISO8859_3, PG_LATIN3);
77
78 PG_RETURN_VOID();
79}
80
81Datum
82mic_to_latin3(PG_FUNCTION_ARGS)
83{
84 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
85 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
86 int len = PG_GETARG_INT32(4);
87
88 CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN3);
89
90 mic2latin(src, dest, len, LC_ISO8859_3, PG_LATIN3);
91
92 PG_RETURN_VOID();
93}
94
95Datum
96latin4_to_mic(PG_FUNCTION_ARGS)
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
102 CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN4, PG_MULE_INTERNAL);
103
104 latin2mic(src, dest, len, LC_ISO8859_4, PG_LATIN4);
105
106 PG_RETURN_VOID();
107}
108
109Datum
110mic_to_latin4(PG_FUNCTION_ARGS)
111{
112 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
113 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
114 int len = PG_GETARG_INT32(4);
115
116 CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN4);
117
118 mic2latin(src, dest, len, LC_ISO8859_4, PG_LATIN4);
119
120 PG_RETURN_VOID();
121}
122