1999-10-21 03:21:56 +04:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Intel Corporation.
|
|
|
|
*/
|
1999-09-13 23:27:05 +04:00
|
|
|
// =======================================================================
|
|
|
|
// Original Author: Yueheng Xu
|
|
|
|
// email: yueheng.xu@intel.com
|
|
|
|
// phone: (503)264-2248
|
|
|
|
// Intel Corporation, Oregon, USA
|
|
|
|
// Last Update: September 7, 1999
|
|
|
|
// Revision History:
|
|
|
|
// 09/07/1999 - initial version.
|
1999-10-21 03:21:56 +04:00
|
|
|
// 09/28/1999 - changed leftbyte and rightbyte from char to unsigned char
|
|
|
|
// in struct DByte
|
|
|
|
// 04/10/1999 - changed leftbyte. rightbyte to PRUint8 in struct DByte;
|
|
|
|
// added table UnicodeToGBKTable[0x5200]
|
|
|
|
//
|
|
|
|
// ======================================================================================
|
|
|
|
// Table GBKToUnicode[] maps the GBK code to its unicode.
|
1999-09-13 23:27:05 +04:00
|
|
|
// The mapping data of this GBK table is obtained from
|
|
|
|
// ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP936.TXT
|
|
|
|
// Frank Tang of Netscape wrote the original perl tool to re-align the
|
|
|
|
// mapping data into an 8-item per line format ( i.e. file cp936map.txt ).
|
|
|
|
//
|
|
|
|
// The valid GBK charset range: left byte is [0x81, 0xfe], right byte are
|
|
|
|
// [0x40, 0x7e] and [0x80, 0xfe]. But for the convenience of index
|
|
|
|
// calculation, the table here has a single consecutive range of
|
|
|
|
// [0x40, 0xfe] for the right byte. Those invalid chars whose right byte
|
|
|
|
// is 0x7f will be mapped to undefined unicode 0xFFFF.
|
|
|
|
//
|
1999-10-21 03:21:56 +04:00
|
|
|
//
|
|
|
|
// Table UnicodeToGBK[] maps the unicode to GBK code. To reduce memory usage, we
|
|
|
|
// only do Unicode to GBK table mapping for unicode between 0x4E00 and 0xA000;
|
|
|
|
// Others let converter to do search from table GBKToUnicode[]. If we want further
|
|
|
|
// trade memory for performance, we can let more unicode to do table mapping to get
|
|
|
|
// its GBK instead of searching table GBKToUnicode[].
|
1999-09-13 23:27:05 +04:00
|
|
|
|
|
|
|
#ifdef _GBKU_TABLE_
|
|
|
|
|
|
|
|
#define GB_UNDEFINED 0xFFFF
|
|
|
|
#define MAX_GBK_LENGTH 24066 /* (0xfe-0x80)*(0xfe-0x3f) */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
1999-10-21 03:21:56 +04:00
|
|
|
|
|
|
|
PRUint8 leftbyte;
|
|
|
|
PRUint8 rightbyte;
|
1999-09-13 23:27:05 +04:00
|
|
|
|
|
|
|
} DByte;
|
|
|
|
extern PRUnichar GBKToUnicodeTable[MAX_GBK_LENGTH];
|
|
|
|
|
1999-10-21 03:21:56 +04:00
|
|
|
#ifdef _UNICODE_TO_GBK_ENCODER_
|
|
|
|
DByte UnicodeToGBKTable[0x5200];
|
|
|
|
#else
|
|
|
|
extern DByte UnicodeToGBKTable[0x5200]; // 0xA000 - 0x4E00 = 0x5200
|
|
|
|
#endif
|
1999-09-13 23:27:05 +04:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define _GBKU_TABLE_
|
|
|
|
|
|
|
|
|
|
|
|
#define GB_UNDEFINED 0xFFFF
|
|
|
|
#define MAX_GBK_LENGTH 24066 /* (0xfe-0x80)*(0xfe-0x3f) */
|
|
|
|
|
1999-10-21 03:21:56 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
PRUint8 leftbyte;
|
|
|
|
PRUint8 rightbyte;
|
1999-09-13 23:27:05 +04:00
|
|
|
|
|
|
|
} DByte;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRUnichar GBKToUnicodeTable[MAX_GBK_LENGTH] =
|
|
|
|
{
|
|
|
|
#include "cp936map.h"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-10-21 03:21:56 +04:00
|
|
|
#ifdef _UNICODE_TO_GBK_ENCODER_
|
|
|
|
DByte UnicodeToGBKTable[0x5200];
|
|
|
|
#else
|
|
|
|
extern DByte UnicodeToGBKTable[0x5200]; // 0xA000 - 0x4E00 = 0x5200
|
|
|
|
#endif
|
|
|
|
|
1999-09-13 23:27:05 +04:00
|
|
|
|
|
|
|
#endif /* ifdef _GBKU_TABLE_ */
|
|
|
|
|