add new implementation of GB converters

This commit is contained in:
ftang%netscape.com 1999-09-07 20:04:53 +00:00
parent 4830472f75
commit bd6142fe1b
5 changed files with 8695 additions and 0 deletions

8236
intl/uconv/ucvcn/gbu.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,157 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#define INTEL_CHANGE
#include "nsGB2312ToUnicodeV2.h"
#include "nsUCvCnDll.h"
#ifdef INTEL_CHANGE
#include "gbu.h"
#endif
//----------------------------------------------------------------------
// Global functions and data [declaration]
static PRInt16 g_ASCIIShiftTable[] = {
0, u1ByteCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 g_GB2312ShiftTable[] = {
0, u2BytesGRCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 *g_GB2312ShiftTableSet [] = {
g_ASCIIShiftTable,
g_GB2312ShiftTable
};
static PRUint16 *g_GB2312MappingTableSet [] ={
g_AsciiMapping,
g_utGB2312Mapping
};
static uRange g_GB2312Ranges[] = {
{ 0x00, 0x7E },
{ 0xA1, 0xFE }
};
//----------------------------------------------------------------------
// Class nsGB2312ToUnicodeV2 [implementation]
nsGB2312ToUnicodeV2::nsGB2312ToUnicodeV2()
: nsMultiTableDecoderSupport(2,
(uRange *) &g_GB2312Ranges,
(uShiftTable**) &g_GB2312ShiftTableSet,
(uMappingTable**) &g_GB2312MappingTableSet)
{
}
nsresult nsGB2312ToUnicodeV2::CreateInstance(nsISupports ** aResult)
{
*aResult = new nsGB2312ToUnicodeV2();
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
//----------------------------------------------------------------------
// Subclassing of nsTablesDecoderSupport class [implementation]
NS_IMETHODIMP nsGB2312ToUnicodeV2::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// we are a single byte to Unicode converter, so...
*aDestLength = aSrcLength;
return NS_OK_UDEC_EXACTLENGTH;
}
#ifdef INTEL_CHANGE
//Overwriting the ConvertNoBuff() in nsUCvCnSupport.cpp.
//side effects: all the helper functions called by UCvCnSupport are deprecated
void GBToUnicode(DByte *pGBCode, PRUnichar * pUnicode)
{
short int iGBToUnicodeIndex;
if(pGBCode)
iGBToUnicodeIndex = ( (short int)(pGBCode->leftbyte & 0x7f) - 0x21)*(0x7e - 0x20 )+( (short int)(pGBCode->rightbyte &0x7f ) - 0x21);
if( (iGBToUnicodeIndex >= 0 ) && ( iGBToUnicodeIndex < MAX_GB_LENGTH) )
*pUnicode = GBToUnicodeTable[iGBToUnicodeIndex];
// e.g. 0xb0a1 --> Index = 0 --> left = 0x00, right = 0x30, value = 0x3000
}
NS_IMETHODIMP nsGB2312ToUnicodeV2::ConvertNoBuff(const char* aSrc,
PRInt32 * aSrcLength,
PRUnichar *aDest,
PRInt32 * aDestLength)
{
short int i=0;
short int iSrcLength = (short int)(*aSrcLength);
DByte *pSrcDBCode = (DByte *)aSrc;
PRUnichar *pDestDBCode = (PRUnichar *)aDest;
int iDestlen = 0;
for (i=0;i<iSrcLength;i++)
{
pSrcDBCode = (DByte *)aSrc;
pDestDBCode = aDest;
if ( iDestlen >= (*aDestLength) )
{
break;
}
if ( *aSrc & 0x80 )
{
// The source is a GBCode
GBToUnicode(pSrcDBCode, pDestDBCode);
aSrc += 2;
i++;
}
else
{
// The source is an ASCII
*pDestDBCode = (PRUnichar) ( ((char)(*aSrc) )& 0x00ff);
aSrc++;
}
iDestlen++;
aDest++;
*aSrcLength = i+1;
}
*aDestLength = iDestlen;
return NS_OK;
}
#endif

View File

@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsGB2312ToUnicodeV2_h___
#define nsGB2312ToUnicodeV2_h___
#include "nsUCvCnSupport.h"
//----------------------------------------------------------------------
// Class nsGB2312ToUnicodeV2 [declaration]
/**
* A character set converter from GB2312 to Unicode.
*
* @created 06/Apr/1999
* @author Catalin Rotaru [CATA]
*/
class nsGB2312ToUnicodeV2 : public nsMultiTableDecoderSupport
{
public:
/**
* Class constructor.
*/
nsGB2312ToUnicodeV2();
/**
* Static class constructor.
*/
static nsresult CreateInstance(nsISupports **aResult);
#ifdef INTEL_CHANGE
NS_IMETHODIMP nsGB2312ToUnicodeV2::ConvertNoBuff(const char* aSrc,
PRInt32 * aSrcLength,
PRUnichar *aDest,
PRInt32 * aDestLength);
#endif
protected:
//--------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [declaration]
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
};
#endif /* nsGB2312ToUnicodeV2_h___ */

View File

@ -0,0 +1,173 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#define INTEL_CHANGE
#include "nsUnicodeToGB2312V2.h"
#include "nsUCvCnDll.h"
#ifdef INTEL_CHANGE
#define _GBU_TABLE_ // make the table in the include file to be extern
#include "gbu.h"
#endif
//----------------------------------------------------------------------
// Global functions and data [declaration]
static PRInt16 g_ASCIIShiftTable[] = {
0, u1ByteCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 g_GB2312ShiftTable[] = {
0, u2BytesGRCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 *g_GB2312ShiftTableSet [] = {
g_ASCIIShiftTable,
g_GB2312ShiftTable
};
static PRUint16 *g_GB2312MappingTableSet [] ={
g_AsciiMapping,
g_ufGB2312Mapping
};
//----------------------------------------------------------------------
// Class nsUnicodeToGB2312V2 [implementation]
nsUnicodeToGB2312V2::nsUnicodeToGB2312V2()
: nsMultiTableEncoderSupport(2,
(uShiftTable**) &g_GB2312ShiftTableSet,
(uMappingTable**) &g_GB2312MappingTableSet)
{
}
#ifdef INTEL_CHANGE
#define TRUE 1
#define FALSE 0
void UnicodeToGB(PRUnichar SrcUnicode, DByte *pGBCode)
{
short int iRet = FALSE;
short int i = 0;
short int iGBToUnicodeIndex = 0;
for ( i=0; i<MAX_GB_LENGTH; i++)
{
if ( SrcUnicode == GBToUnicodeTable[i] )
{
iGBToUnicodeIndex = i;
iRet = TRUE;
break;
}
}
if ( iRet )
{
//convert from one dimensional index to (left, right) pair
if(pGBCode)
{
pGBCode->leftbyte = (char) ( iGBToUnicodeIndex / (0x007e - 0x0020) + 0x0021) ;
pGBCode->leftbyte |= 0x80;
pGBCode->rightbyte = (char) ( iGBToUnicodeIndex % (0x007e - 0x0020)+ 0x0021);
pGBCode->rightbyte |= 0x80;
}
}
}
NS_IMETHODIMP nsUnicodeToGB2312V2::ConvertNoBuff(const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength)
{
PRInt32 i=0;
PRInt32 iSrcLength = *aSrcLength;
DByte *pDestDBCode;
DByte *pSrcDBCode;
PRInt32 iDestLength = 0;
PRUnichar *pSrc = (PRUnichar *)aSrc;
pDestDBCode = (DByte *)aDest;
for (i=0;i< iSrcLength;i++)
{
pDestDBCode = (DByte *)aDest;
if( (*pSrc) & 0xff00 )
{
// hi byte has something, it is not ASCII, must be a GB
UnicodeToGB( *pSrc, pDestDBCode);
aDest += 2; // increment 2 bytes
pDestDBCode = (DByte *)aDest;
iDestLength +=2;
}
else
{
// this is an ASCII
pSrcDBCode = (DByte *)pSrc;
*aDest = pSrcDBCode->leftbyte;
aDest++; // increment 1 byte
iDestLength +=1;
}
pSrc++; // increment 2 bytes
if ( iDestLength >= (*aDestLength) )
{
break;
}
}
*aDestLength = iDestLength;
*aSrcLength = i;
return NS_OK;
}
#endif
nsresult nsUnicodeToGB2312V2::CreateInstance(nsISupports ** aResult)
{
nsIUnicodeEncoder *p = new nsUnicodeToGB2312V2();
if(p) {
*aResult = p;
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
//----------------------------------------------------------------------
// Subclassing of nsTableEncoderSupport class [implementation]
NS_IMETHODIMP nsUnicodeToGB2312V2::GetMaxLength(const PRUnichar * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
*aDestLength = 2 * aSrcLength;
return NS_OK;
}

View File

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsUnicodeToGB2312V2_h___
#define nsUnicodeToGB2312V2_h___
#include "nsUCvCnSupport.h"
//----------------------------------------------------------------------
// Class nsUnicodeToGB2312V2 [declaration]
/**
* A character set converter from Unicode to GB2312.
*
* @created 06/Apr/1999
* @author Catalin Rotaru [CATA]
*/
class nsUnicodeToGB2312V2 : public nsMultiTableEncoderSupport
{
public:
/**
* Class constructor.
*/
nsUnicodeToGB2312V2();
/**
* Static class constructor.
*/
static nsresult CreateInstance(nsISupports **aResult);
#ifdef INTEL_CHANGE
NS_IMETHODIMP ConvertNoBuff(const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength);
#endif
protected:
//--------------------------------------------------------------------
// Subclassing of nsEncoderSupport class [declaration]
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
};
#endif /* nsUnicodeToGB2312V2_h___ */