1/*-------------------------------------------------------------------------
3 * EUC_TW, BIG5 and MULE_INTERNAL
5 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c
11 *-------------------------------------------------------------------------
19 .
name =
"euc_tw_and_big5",
32 * INTEGER, -- source encoding id
33 * INTEGER, -- destination encoding id
34 * CSTRING, -- source string (null terminated C string)
35 * CSTRING, -- destination string (null terminated C string)
36 * INTEGER, -- source string length
37 * BOOL -- if true, don't throw an error if conversion fails
40 * Returns the number of bytes successfully converted.
44static int euc_tw2big5(
const unsigned char *euc,
unsigned char *p,
int len,
bool noError);
45static int big52euc_tw(
const unsigned char *big5,
unsigned char *p,
int len,
bool noError);
46static int big52mic(
const unsigned char *big5,
unsigned char *p,
int len,
bool noError);
47static int mic2big5(
const unsigned char *mic,
unsigned char *p,
int len,
bool noError);
48static int euc_tw2mic(
const unsigned char *euc,
unsigned char *p,
int len,
bool noError);
49static int mic2euc_tw(
const unsigned char *mic,
unsigned char *p,
int len,
bool noError);
154 const unsigned char *
start = euc;
156 unsigned short big5buf,
166 /* Verify and decode the next EUC_TW input character */
173 (
const char *) euc,
len);
177 c1 = euc[1];
/* plane No. */
184 cnsBuf = (euc[2] << 8) | euc[3];
189 cnsBuf = (c1 << 8) | euc[1];
192 /* Write it out in Big5 */
199 (
const char *) euc,
len);
201 *p++ = (big5buf >> 8) & 0x00ff;
202 *p++ = big5buf & 0x00ff;
208 {
/* should be ASCII */
214 (
const char *) euc,
len);
232 const unsigned char *
start = big5;
234 unsigned short big5buf,
241 /* Verify and decode the next Big5 input character */
251 (
const char *) big5,
len);
253 big5buf = (c1 << 8) | big5[1];
258 *p++ = (cnsBuf >> 8) & 0x00ff;
259 *p++ = cnsBuf & 0x00ff;
265 *p++ = (cnsBuf >> 8) & 0x00ff;
266 *p++ = cnsBuf & 0x00ff;
272 *p++ = (cnsBuf >> 8) & 0x00ff;
273 *p++ = cnsBuf & 0x00ff;
280 (
const char *) big5,
len);
294 (
const char *) big5,
len);
311 euc_tw2mic(
const unsigned char *euc,
unsigned char *p,
int len,
bool noError)
313 const unsigned char *
start = euc;
328 (
const char *) euc,
len);
332 c1 = euc[1];
/* plane No. */
339 /* other planes are MULE private charsets */
356 {
/* should be ASCII */
362 (
const char *) euc,
len);
378 mic2euc_tw(
const unsigned char *mic,
unsigned char *p,
int len,
bool noError)
380 const unsigned char *
start = mic;
395 (
const char *) mic,
len);
408 (
const char *) mic,
len);
435 (
const char *) mic,
len);
449 big52mic(
const unsigned char *big5,
unsigned char *p,
int len,
bool noError)
451 const unsigned char *
start = big5;
453 unsigned short big5buf,
469 (
const char *) big5,
len);
482 (
const char *) big5,
len);
484 big5buf = (c1 << 8) | big5[1];
488 /* Planes 3 and 4 are MULE private charsets */
491 *p++ = lc;
/* Plane No. */
492 *p++ = (cnsBuf >> 8) & 0x00ff;
493 *p++ = cnsBuf & 0x00ff;
500 (
const char *) big5,
len);
514 mic2big5(
const unsigned char *mic,
unsigned char *p,
int len,
bool noError)
516 const unsigned char *
start = mic;
518 unsigned short big5buf,
533 (
const char *) mic,
len);
546 (
const char *) mic,
len);
552 c1 = mic[1];
/* get plane no. */
553 cnsBuf = (mic[2] << 8) | mic[3];
557 cnsBuf = (mic[1] << 8) | mic[2];
565 (
const char *) mic,
len);
567 *p++ = (big5buf >> 8) & 0x00ff;
568 *p++ = big5buf & 0x00ff;
575 (
const char *) mic,
len);
unsigned short CNStoBIG5(unsigned short cns, unsigned char lc)
unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc)
#define IS_HIGHBIT_SET(ch)
static int euc_tw2mic(const unsigned char *euc, unsigned char *p, int len, bool noError)
static int big52mic(const unsigned char *big5, unsigned char *p, int len, bool noError)
Datum euc_tw_to_mic(PG_FUNCTION_ARGS)
Datum big5_to_euc_tw(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(euc_tw_to_big5)
Datum mic_to_big5(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC_EXT(.name="euc_tw_and_big5",.version=PG_VERSION)
Datum big5_to_mic(PG_FUNCTION_ARGS)
Datum euc_tw_to_big5(PG_FUNCTION_ARGS)
static int mic2euc_tw(const unsigned char *mic, unsigned char *p, int len, bool noError)
Datum mic_to_euc_tw(PG_FUNCTION_ARGS)
static int mic2big5(const unsigned char *mic, unsigned char *p, int len, bool noError)
static int euc_tw2big5(const unsigned char *euc, unsigned char *p, int len, bool noError)
static int big52euc_tw(const unsigned char *big5, unsigned char *p, int len, bool noError)
#define PG_GETARG_CSTRING(n)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
void report_untranslatable_char(int src_encoding, int dest_encoding, const char *mbstr, int len)
void report_invalid_encoding(int encoding, const char *mbstr, int len)
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding)
int pg_encoding_verifymbchar(int encoding, const char *mbstr, int len)