--- postgresql-7.2.1/src/backend/utils/mb/conv.c.org Thu Jun 6 11:52:24 2002 +++ postgresql-7.2.1/src/backend/utils/mb/conv.c Thu Jun 6 12:20:36 2002 @@ -502,6 +502,96 @@ } /* + * GB18030 ---> MIC + * Added by Bill Huang , + */ +static void +gb180302mic(unsigned char *gb18030, unsigned char *p, int len) +{ + int c1; + int c2; + + while (len > 0 && (c1 = *gb18030++)) + { + if (c1 < 0x80) + { /* should be ASCII */ + len--; + *p++ = c1; + } + else if(c1 >= 0x81 && c1 <= 0xfe) + { + c2 = *gb18030++; + + if(c2 >= 0x30 && c2 <= 0x69){ + len -= 4; + *p++ = c1; + *p++ = c2; + *p++ = *gb18030++; + *p++ = *gb18030++; + *p++ = *gb18030++; + } + else if ((c2 >=0x40 && c2 <= 0x7e) ||(c2 >=0x80 && c2 <= 0xfe)){ + len -= 2; + *p++ = c1; + *p++ = c2; + *p++ = *gb18030++; + } + else{ /*throw the strange code*/ + len--; + } + } + } + *p = '\0'; +} + +/* + * MIC ---> GB18030 + * Added by Bill Huang , + */ +static void +mic2gb18030(unsigned char *mic, unsigned char *p, int len) +{ + int c1; + int c2; + + while (len > 0 && (c1 = *mic)) + { + len -= pg_mic_mblen(mic++); + + if (c1 <= 0x7f) /*ASCII*/ + { + *p++ = c1; + } + else if (c1 >= 0x81 && c1 <= 0xfe) + { + c2 = *mic++; + + if((c2 >= 0x40 && c2 <= 0x7e) || (c2 >= 0x80 && c2 <= 0xfe)){ + *p++ = c1; + *p++ = c2; + } + else if(c2 >= 0x30 && c2 <= 0x39){ + *p++ = c1; + *p++ = c2; + *p++ = *mic++; + *p++ = *mic++; + } + else{ + mic--; + printBogusChar(&mic, &p); + mic--; + printBogusChar(&mic, &p); + } + } + else{ + mic--; + printBogusChar(&mic, &p); + } + } + *p = '\0'; +} + +/* * EUC_TW ---> MIC */ static void @@ -1583,6 +1673,26 @@ } /* + * UTF-8 ---> GB18030 + */ +static void +utf_to_gb18030(unsigned char *utf, unsigned char *euc, int len) + +{ + utf_to_local(utf, euc, ULmapEUC_CN, + sizeof(ULmapEUC_CN) / sizeof(pg_utf_to_local), len); +} + +/* + * GB18030 ---> UTF-8 + */ +static void +gb18030_to_utf(unsigned char *euc, unsigned char *utf, int len) +{ + local_to_utf(euc, utf, LUmapEUC_CN, + sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), PG_EUC_CN, len); +} +/* * UTF-8 ---> EUC_KR */ static void @@ -1754,6 +1864,9 @@ PG_BIG5, big52mic, mic2big5, big5_to_utf, utf_to_big5 }, { + PG_GB18030, gb180302mic, mic2gb18030, gb18030_to_utf, utf_to_gb18030 + }, + { PG_WIN1250, win12502mic, mic2win1250, 0, 0 }, }; @@ -1841,6 +1954,9 @@ PG_BIG5, big52mic, mic2big5, 0, 0 }, { + PG_GB18030, gb180302mic, mic2gb18030, 0, 0 + }, + { PG_WIN1250, win12502mic, mic2win1250, 0, 0 }, };