PostgreSQL Source Code git master
utf8_and_euc_tw.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * EUC_TW <--> UTF8
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/utf8_and_euc_tw/utf8_and_euc_tw.c
10 *
11 *-------------------------------------------------------------------------
12 */
13
14#include "postgres.h"
15#include "fmgr.h"
16#include "mb/pg_wchar.h"
17#include "../../Unicode/euc_tw_to_utf8.map"
18#include "../../Unicode/utf8_to_euc_tw.map"
19
21
24
25/* ----------
26 * conv_proc(
27 * INTEGER, -- source encoding id
28 * INTEGER, -- destination encoding id
29 * CSTRING, -- source string (null terminated C string)
30 * CSTRING, -- destination string (null terminated C string)
31 * INTEGER, -- source string length
32 * BOOL -- if true, don't throw an error if conversion fails
33 * ) returns INTEGER;
34 *
35 * Returns the number of bytes successfully converted.
36 * ----------
37 */
40{
41 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
42 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
43 int len = PG_GETARG_INT32(4);
44 bool noError = PG_GETARG_BOOL(5);
45 int converted;
46
48
49 converted = LocalToUtf(src, len, dest,
50 &euc_tw_to_unicode_tree,
51 NULL, 0,
52 NULL,
54 noError);
55
56 PG_RETURN_INT32(converted);
57}
58
61{
62 unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
63 unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
64 int len = PG_GETARG_INT32(4);
65 bool noError = PG_GETARG_BOOL(5);
66 int converted;
67
69
70 converted = UtfToLocal(src, len, dest,
71 &euc_tw_from_unicode_tree,
72 NULL, 0,
73 NULL,
75 noError);
76
77 PG_RETURN_INT32(converted);
78}
int UtfToLocal(const unsigned char *utf, int len, unsigned char *iso, const pg_mb_radix_tree *map, const pg_utf_to_local_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding, bool noError)
Definition: conv.c:507
int LocalToUtf(const unsigned char *iso, int len, unsigned char *utf, const pg_mb_radix_tree *map, const pg_local_to_utf_combined *cmap, int cmapsize, utf_local_conversion_func conv_func, int encoding, bool noError)
Definition: conv.c:717
#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
const void size_t len
@ PG_EUC_TW
Definition: pg_wchar.h:230
@ PG_UTF8
Definition: pg_wchar.h:232
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
Definition: pg_wchar.h:507
uintptr_t Datum
Definition: postgres.h:64
Datum euc_tw_to_utf8(PG_FUNCTION_ARGS)
Datum utf8_to_euc_tw(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC
PG_FUNCTION_INFO_V1(euc_tw_to_utf8)