Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * LATINn and MULE_INTERNAL
4 : *
5 : * Portions Copyright (c) 1996-2025, 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 :
18 6 : PG_MODULE_MAGIC;
19 :
20 6 : PG_FUNCTION_INFO_V1(latin1_to_mic);
21 6 : PG_FUNCTION_INFO_V1(mic_to_latin1);
22 6 : PG_FUNCTION_INFO_V1(latin3_to_mic);
23 6 : PG_FUNCTION_INFO_V1(mic_to_latin3);
24 6 : PG_FUNCTION_INFO_V1(latin4_to_mic);
25 6 : PG_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 : * BOOL -- if true, don't throw an error if conversion fails
35 : * ) returns INTEGER;
36 : *
37 : * Returns the number of bytes successfully converted.
38 : * ----------
39 : */
40 :
41 :
42 : Datum
43 6 : latin1_to_mic(PG_FUNCTION_ARGS)
44 : {
45 6 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
46 6 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
47 6 : int len = PG_GETARG_INT32(4);
48 6 : bool noError = PG_GETARG_BOOL(5);
49 : int converted;
50 :
51 6 : CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_MULE_INTERNAL);
52 :
53 6 : converted = latin2mic(src, dest, len, LC_ISO8859_1, PG_LATIN1, noError);
54 :
55 6 : PG_RETURN_INT32(converted);
56 : }
57 :
58 : Datum
59 6 : mic_to_latin1(PG_FUNCTION_ARGS)
60 : {
61 6 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
62 6 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
63 6 : int len = PG_GETARG_INT32(4);
64 6 : bool noError = PG_GETARG_BOOL(5);
65 : int converted;
66 :
67 6 : CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN1);
68 :
69 6 : converted = mic2latin(src, dest, len, LC_ISO8859_1, PG_LATIN1, noError);
70 :
71 6 : PG_RETURN_INT32(converted);
72 : }
73 :
74 : Datum
75 6 : latin3_to_mic(PG_FUNCTION_ARGS)
76 : {
77 6 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
78 6 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
79 6 : int len = PG_GETARG_INT32(4);
80 6 : bool noError = PG_GETARG_BOOL(5);
81 : int converted;
82 :
83 6 : CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN3, PG_MULE_INTERNAL);
84 :
85 6 : converted = latin2mic(src, dest, len, LC_ISO8859_3, PG_LATIN3, noError);
86 :
87 6 : PG_RETURN_INT32(converted);
88 : }
89 :
90 : Datum
91 6 : mic_to_latin3(PG_FUNCTION_ARGS)
92 : {
93 6 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
94 6 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
95 6 : int len = PG_GETARG_INT32(4);
96 6 : bool noError = PG_GETARG_BOOL(5);
97 : int converted;
98 :
99 6 : CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN3);
100 :
101 6 : converted = mic2latin(src, dest, len, LC_ISO8859_3, PG_LATIN3, noError);
102 :
103 6 : PG_RETURN_INT32(converted);
104 : }
105 :
106 : Datum
107 6 : latin4_to_mic(PG_FUNCTION_ARGS)
108 : {
109 6 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
110 6 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
111 6 : int len = PG_GETARG_INT32(4);
112 6 : bool noError = PG_GETARG_BOOL(5);
113 : int converted;
114 :
115 6 : CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN4, PG_MULE_INTERNAL);
116 :
117 6 : converted = latin2mic(src, dest, len, LC_ISO8859_4, PG_LATIN4, noError);
118 :
119 6 : PG_RETURN_INT32(converted);
120 : }
121 :
122 : Datum
123 6 : mic_to_latin4(PG_FUNCTION_ARGS)
124 : {
125 6 : unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
126 6 : unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
127 6 : int len = PG_GETARG_INT32(4);
128 6 : bool noError = PG_GETARG_BOOL(5);
129 : int converted;
130 :
131 6 : CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN4);
132 :
133 6 : converted = mic2latin(src, dest, len, LC_ISO8859_4, PG_LATIN4, noError);
134 :
135 6 : PG_RETURN_INT32(converted);
136 : }
|