支持GB18030字符集
This commit is contained in:
@ -174,10 +174,10 @@ pg_enc2name pg_enc2name_tbl[] = {DEF_ENC2NAME(SQL_ASCII, 0),
|
||||
DEF_ENC2NAME(WIN1255, 1255),
|
||||
DEF_ENC2NAME(WIN1257, 1257),
|
||||
DEF_ENC2NAME(KOI8U, 21866),
|
||||
DEF_ENC2NAME(GB18030, 54936),
|
||||
DEF_ENC2NAME(SJIS, 932),
|
||||
DEF_ENC2NAME(BIG5, 950),
|
||||
DEF_ENC2NAME(UHC, 0),
|
||||
DEF_ENC2NAME(GB18030, 54936),
|
||||
DEF_ENC2NAME(JOHAB, 0),
|
||||
DEF_ENC2NAME(SHIFT_JIS_2004, 932)};
|
||||
|
||||
|
||||
@ -1083,6 +1083,64 @@ static int pg_uhc_dsplen(const unsigned char* s)
|
||||
* * GB18030
|
||||
* * Added by Bill Huang <bhuang@redhat.com>,<bill_huanghb@ybb.ne.jp>
|
||||
* */
|
||||
static int pg_gb180302wchar_with_len(const unsigned char* from, pg_wchar* to, int len)
|
||||
{
|
||||
int cnt = 0;
|
||||
while (len > 0) {
|
||||
if (*from <= 0x7f) { /* ASCII */
|
||||
*to = *from++;
|
||||
--len;
|
||||
} else if (IS_HIGHBIT_SET(*from) &&
|
||||
(*(from + 1) >= 0x30 && *(from + 1) < 0x40)) {
|
||||
if (len < 4) {
|
||||
break; /* drop trailing incomplete char */
|
||||
}
|
||||
*to = *from++ << 24;
|
||||
*to |= *from++ << 16;
|
||||
*to |= *from++ << 8;
|
||||
*to |= *from++;
|
||||
len -= 4;
|
||||
} else {
|
||||
if (len < 2) {
|
||||
break;
|
||||
}
|
||||
*to = *from++ << 8;
|
||||
*to |= *from++;
|
||||
len -= 2;
|
||||
}
|
||||
++to;
|
||||
++cnt;
|
||||
}
|
||||
*to = 0;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static int pg_wchar2gb18030_with_len(const pg_wchar* from, unsigned char* to, int len)
|
||||
{
|
||||
int cnt = 0;
|
||||
while (len > 0 && *from) {
|
||||
unsigned char c;
|
||||
if ((c = (*from >> 24))) {
|
||||
*to++ = c;
|
||||
*to++ = (*from >> 16) & 0xff;
|
||||
*to++ = (*from >> 8) & 0xff;
|
||||
*to++ = *from & 0xff;
|
||||
cnt += 4;
|
||||
} else if ((c = (*from >> 8))) {
|
||||
*to++ = c;
|
||||
*to++ = *from & 0xff;
|
||||
cnt += 2;
|
||||
} else {
|
||||
*to++ = *from;
|
||||
cnt++;
|
||||
}
|
||||
from++;
|
||||
len--;
|
||||
}
|
||||
*to = 0;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static int pg_gb18030_mblen(const unsigned char* s)
|
||||
{
|
||||
int len;
|
||||
@ -1926,10 +1984,15 @@ pg_wchar_tbl pg_wchar_table[] = {
|
||||
pg_latin1_dsplen,
|
||||
pg_latin1_verifier,
|
||||
1}, /* PG_KOI8U */
|
||||
{pg_gb180302wchar_with_len,
|
||||
pg_wchar2gb18030_with_len,
|
||||
pg_gb18030_mblen,
|
||||
pg_gb18030_dsplen,
|
||||
pg_gb18030_verifier,
|
||||
4}, /* PG_GB18030 */
|
||||
{0, 0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifier, 2}, /* PG_SJIS */
|
||||
{0, 0, pg_big5_mblen, pg_big5_dsplen, pg_big5_verifier, 2}, /* PG_BIG5 */
|
||||
{0, 0, pg_uhc_mblen, pg_uhc_dsplen, pg_uhc_verifier, 2}, /* PG_UHC */
|
||||
{0, 0, pg_gb18030_mblen, pg_gb18030_dsplen, pg_gb18030_verifier, 4}, /* PG_GB18030 */
|
||||
{0, 0, pg_johab_mblen, pg_johab_dsplen, pg_johab_verifier, 3}, /* PG_JOHAB */
|
||||
{0, 0, pg_sjis_mblen, pg_sjis_dsplen, pg_sjis_verifier, 2} /* PG_SHIFT_JIS_2004 */
|
||||
};
|
||||
|
||||
@ -221,20 +221,20 @@ typedef enum pg_enc {
|
||||
PG_WIN1255, /* windows-1255 */
|
||||
PG_WIN1257, /* windows-1257 */
|
||||
PG_KOI8U, /* KOI8-U */
|
||||
PG_GB18030, /* GB18030 */
|
||||
/* PG_ENCODING_BE_LAST points to the above entry */
|
||||
|
||||
/* followings are for client encoding only */
|
||||
PG_SJIS, /* Shift JIS (Winindows-932) */
|
||||
PG_BIG5, /* Big5 (Windows-950) */
|
||||
PG_UHC, /* UHC (Windows-949) */
|
||||
PG_GB18030, /* GB18030 */
|
||||
PG_JOHAB, /* EUC for Korean JOHAB */
|
||||
PG_SHIFT_JIS_2004, /* Shift-JIS-2004 */
|
||||
_PG_LAST_ENCODING_ /* mark only */
|
||||
|
||||
} pg_enc;
|
||||
|
||||
#define PG_ENCODING_BE_LAST PG_KOI8U
|
||||
#define PG_ENCODING_BE_LAST PG_GB18030
|
||||
|
||||
/*
|
||||
* Please use these tests before access to pg_encconv_tbl[]
|
||||
|
||||
Reference in New Issue
Block a user