22 #define PGSJISALTCODE 0x81ac
23 #define PGEUCALTCODE 0xa2ae
53 static int sjis2mic(
const unsigned char *sjis,
unsigned char *p,
int len,
bool noError);
54 static int mic2sjis(
const unsigned char *mic,
unsigned char *p,
int len,
bool noError);
55 static int euc_jp2mic(
const unsigned char *euc,
unsigned char *p,
int len,
bool noError);
56 static int mic2euc_jp(
const unsigned char *mic,
unsigned char *p,
int len,
bool noError);
57 static int euc_jp2sjis(
const unsigned char *euc,
unsigned char *p,
int len,
bool noError);
58 static int sjis2euc_jp(
const unsigned char *sjis,
unsigned char *p,
int len,
bool noError);
160 sjis2mic(
const unsigned char *sjis,
unsigned char *p,
int len,
bool noError)
162 const unsigned char *
start = sjis;
172 if (c1 >= 0xa1 && c1 <= 0xdf)
193 if (k >= 0xed40 && k < 0xf040)
198 k2 = ibmkanji[
i].nec;
203 k = ibmkanji[
i].sjis;
204 c1 = (k >> 8) & 0xff;
214 *p++ = ((c1 & 0x3f) << 1) + 0x9f + (c2 > 0x9e);
215 *p++ = c2 + ((c2 > 0x9e) ? 2 : 0x60) + (c2 < 0x80);
217 else if ((k >= 0xeb40 && k < 0xf040) || (k >= 0xfc4c && k <= 0xfcfc))
224 else if (k >= 0xf040 && k < 0xf540)
232 *p++ = ((c1 & 0x3f) << 1) + 0xf3 + (c2 > 0x9e);
233 *p++ = c2 + ((c2 > 0x9e) ? 2 : 0x60) + (c2 < 0x80);
235 else if (k >= 0xf540 && k < 0xfa40)
243 *p++ = ((c1 & 0x3f) << 1) + 0xf3 + (c2 > 0x9e);
244 *p++ = c2 + ((c2 > 0x9e) ? 2 : 0x60) + (c2 < 0x80);
246 else if (k >= 0xfa40)
253 k2 = ibmkanji[
i].sjis;
262 *p++ = 0x80 | ((k & 0xff00) >> 8);
263 *p++ = 0x80 | (k & 0xff);
268 *p++ = 0x80 | (k >> 8);
269 *p++ = 0x80 | (k & 0xff);
299 mic2sjis(
const unsigned char *mic,
unsigned char *p,
int len,
bool noError)
301 const unsigned char *
start = mic;
318 (
const char *) mic,
len);
331 (
const char *) mic,
len);
339 k = (c1 << 8) | (c2 & 0xff);
344 *p++ = ((c1 - 0xa1) >> 1) + ((c1 < 0xdf) ? 0x81 : 0xc1) + 0x6f;
347 *p++ = ((c1 - 0xa1) >> 1) + ((c1 < 0xdf) ? 0x81 : 0xc1);
348 *p++ = c2 - ((c1 & 1) ? ((c2 < 0xe0) ? 0x61 : 0x60) : 2);
362 *p++ = ((c1 - 0xa1) >> 1) + ((c1 < 0xdf) ? 0x81 : 0xc1) + 0x74;
363 *p++ = c2 - ((c1 & 1) ? ((c2 < 0xe0) ? 0x61 : 0x60) : 2);
370 k2 = ibmkanji[
i].euc & 0xffff;
379 k = ibmkanji[
i].sjis;
392 (
const char *) mic,
len);
406 euc_jp2mic(
const unsigned char *euc,
unsigned char *p,
int len,
bool noError)
408 const unsigned char *
start = euc;
423 (
const char *) euc,
len);
436 (
const char *) euc,
len);
467 mic2euc_jp(
const unsigned char *mic,
unsigned char *p,
int len,
bool noError)
469 const unsigned char *
start = mic;
484 (
const char *) mic,
len);
497 (
const char *) mic,
len);
520 (
const char *) mic,
len);
536 const unsigned char *
start = euc;
553 (
const char *) euc,
len);
566 (
const char *) euc,
len);
583 *p++ = ((c1 - 0xa1) >> 1) + ((c1 < 0xdf) ? 0x81 : 0xc1) + 0x74;
584 *p++ = c2 - ((c1 & 1) ? ((c2 < 0xe0) ? 0x61 : 0x60) : 2);
594 k2 = ibmkanji[
i].euc & 0xffff;
603 k = ibmkanji[
i].sjis;
615 k = (c1 << 8) | (c2 & 0xff);
620 *p++ = ((c1 - 0xa1) >> 1) + ((c1 < 0xdf) ? 0x81 : 0xc1) + 0x6f;
623 *p++ = ((c1 - 0xa1) >> 1) + ((c1 < 0xdf) ? 0x81 : 0xc1);
624 *p++ = c2 - ((c1 & 1) ? ((c2 < 0xe0) ? 0x61 : 0x60) : 2);
640 const unsigned char *
start = sjis;
659 (
const char *) sjis,
len);
672 (
const char *) sjis,
len);
674 if (c1 >= 0xa1 && c1 <= 0xdf)
687 if (k >= 0xed40 && k < 0xf040)
692 k2 = ibmkanji[
i].nec;
697 k = ibmkanji[
i].sjis;
698 c1 = (k >> 8) & 0xff;
707 *p++ = ((c1 & 0x3f) << 1) + 0x9f + (c2 > 0x9e);
708 *p++ = c2 + ((c2 > 0x9e) ? 2 : 0x60) + (c2 < 0x80);
710 else if ((k >= 0xeb40 && k < 0xf040) || (k >= 0xfc4c && k <= 0xfcfc))
716 else if (k >= 0xf040 && k < 0xf540)
723 *p++ = ((c1 & 0x3f) << 1) + 0xf3 + (c2 > 0x9e);
724 *p++ = c2 + ((c2 > 0x9e) ? 2 : 0x60) + (c2 < 0x80);
726 else if (k >= 0xf540 && k < 0xfa40)
734 *p++ = ((c1 & 0x3f) << 1) + 0xf3 + (c2 > 0x9e);
735 *p++ = c2 + ((c2 > 0x9e) ? 2 : 0x60) + (c2 < 0x80);
737 else if (k >= 0xfa40)
745 k2 = ibmkanji[
i].sjis;
754 *p++ = 0x80 | ((k & 0xff00) >> 8);
755 *p++ = 0x80 | (k & 0xff);
759 *p++ = 0x80 | (k >> 8);
760 *p++ = 0x80 | (k & 0xff);
#define IS_HIGHBIT_SET(ch)
static int mic2euc_jp(const unsigned char *mic, unsigned char *p, int len, bool noError)
Datum mic_to_sjis(PG_FUNCTION_ARGS)
Datum euc_jp_to_sjis(PG_FUNCTION_ARGS)
static int sjis2euc_jp(const unsigned char *sjis, unsigned char *p, int len, bool noError)
PG_FUNCTION_INFO_V1(euc_jp_to_sjis)
Datum euc_jp_to_mic(PG_FUNCTION_ARGS)
static int sjis2mic(const unsigned char *sjis, unsigned char *p, int len, bool noError)
Datum sjis_to_euc_jp(PG_FUNCTION_ARGS)
Datum mic_to_euc_jp(PG_FUNCTION_ARGS)
Datum sjis_to_mic(PG_FUNCTION_ARGS)
static int euc_jp2mic(const unsigned char *euc, unsigned char *p, int len, bool noError)
static int euc_jp2sjis(const unsigned char *euc, unsigned char *p, int len, bool noError)
static int mic2sjis(const unsigned char *mic, 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)