PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
latin_and_mic.c
Go to the documentation of this file.
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
19
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
44{
45 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
46 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
47 int len = PG_GETARG_INT32(4);
48 bool noError = PG_GETARG_BOOL(5);
49 int converted;
50
52
53 converted = latin2mic(src, dest, len, LC_ISO8859_1, PG_LATIN1, noError);
54
55 PG_RETURN_INT32(converted);
56}
57
60{
61 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
62 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
63 int len = PG_GETARG_INT32(4);
64 bool noError = PG_GETARG_BOOL(5);
65 int converted;
66
68
69 converted = mic2latin(src, dest, len, LC_ISO8859_1, PG_LATIN1, noError);
70
71 PG_RETURN_INT32(converted);
72}
73
76{
77 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
78 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
79 int len = PG_GETARG_INT32(4);
80 bool noError = PG_GETARG_BOOL(5);
81 int converted;
82
84
85 converted = latin2mic(src, dest, len, LC_ISO8859_3, PG_LATIN3, noError);
86
87 PG_RETURN_INT32(converted);
88}
89
92{
93 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
94 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
95 int len = PG_GETARG_INT32(4);
96 bool noError = PG_GETARG_BOOL(5);
97 int converted;
98
100
101 converted = mic2latin(src, dest, len, LC_ISO8859_3, PG_LATIN3, noError);
102
103 PG_RETURN_INT32(converted);
104}
105
106Datum
108{
109 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
110 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
111 int len = PG_GETARG_INT32(4);
112 bool noError = PG_GETARG_BOOL(5);
113 int converted;
114
116
117 converted = latin2mic(src, dest, len, LC_ISO8859_4, PG_LATIN4, noError);
118
119 PG_RETURN_INT32(converted);
120}
121
122Datum
124{
125 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
126 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
127 int len = PG_GETARG_INT32(4);
128 bool noError = PG_GETARG_BOOL(5);
129 int converted;
130
132
133 converted = mic2latin(src, dest, len, LC_ISO8859_4, PG_LATIN4, noError);
134
135 PG_RETURN_INT32(converted);
136}
int mic2latin(const unsigned char *mic, unsigned char *p, int len, int lc, int encoding, bool noError)
Definition: conv.c:127
int latin2mic(const unsigned char *l, unsigned char *p, int len, int lc, int encoding, bool noError)
Definition: conv.c:89
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
PG_MODULE_MAGIC
Definition: latin_and_mic.c:18
Datum latin3_to_mic(PG_FUNCTION_ARGS)
Definition: latin_and_mic.c:75
PG_FUNCTION_INFO_V1(latin1_to_mic)
Datum mic_to_latin3(PG_FUNCTION_ARGS)
Definition: latin_and_mic.c:91
Datum mic_to_latin1(PG_FUNCTION_ARGS)
Definition: latin_and_mic.c:59
Datum mic_to_latin4(PG_FUNCTION_ARGS)
Datum latin1_to_mic(PG_FUNCTION_ARGS)
Definition: latin_and_mic.c:43
Datum latin4_to_mic(PG_FUNCTION_ARGS)
const void size_t len
@ PG_LATIN4
Definition: pg_wchar.h:237
@ PG_MULE_INTERNAL
Definition: pg_wchar.h:233
@ PG_LATIN3
Definition: pg_wchar.h:236
@ PG_LATIN1
Definition: pg_wchar.h:234
#define LC_ISO8859_3
Definition: pg_wchar.h:107
#define LC_ISO8859_4
Definition: pg_wchar.h:108
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:507
#define LC_ISO8859_1
Definition: pg_wchar.h:105
uintptr_t Datum
Definition: postgres.h:69