зеркало из https://github.com/mozilla/pjs.git
add shift jis converter, add table driven decode utility and interface, change module name from intl to uconv
This commit is contained in:
Родитель
6d6b9bc555
Коммит
8b382bbe0a
|
@ -19,8 +19,8 @@ DEPTH=..\..\..
|
|||
|
||||
DEFINES=-D_IMPL_NS_INTL -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
MODULE=intl
|
||||
REQUIRES=xpcom
|
||||
MODULE=uconv
|
||||
REQUIRES=xpcom
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = uconv
|
||||
|
@ -29,22 +29,38 @@ DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
|||
CPPSRCS = \
|
||||
nsCharsetConverterManager.cpp \
|
||||
nsAscii2Unicode.cpp \
|
||||
nsUnicodeDecodeUtil.cpp \
|
||||
nsUConvDll.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsCharsetConverterManager.obj \
|
||||
.\$(OBJDIR)\nsAscii2Unicode.obj \
|
||||
.\$(OBJDIR)\nsUnicodeDecodeUtil.obj \
|
||||
.\$(OBJDIR)\nsUConvDll.obj \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
umap.c \
|
||||
ugen.c \
|
||||
uscan.c \
|
||||
$(NULL)
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\umap.obj \
|
||||
.\$(OBJDIR)\ugen.obj \
|
||||
.\$(OBJDIR)\uscan.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS= \
|
||||
$(NULL)
|
||||
|
||||
LINCS= \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\intl \
|
||||
-I$(PUBLIC)\uconv \
|
||||
# the following lines are hacks
|
||||
-I$(PUBLIC)\ucvja \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
|
@ -67,3 +83,4 @@ install:: $(DLL)
|
|||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\$(DLLNAME).dll
|
||||
rm -f $(DIST)\lib\$(DLLNAME).lib
|
||||
|
|
|
@ -1,233 +0,0 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsAscii2Unicode.h"
|
||||
#include "nsConverterCID.h"
|
||||
#include "nsUConvDll.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define NS_SRC_CHARSET "Ascii"
|
||||
#define NS_DEST_CHARSET "Unicode"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsAscii2Unicode [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from Ascii to Unicode.
|
||||
*
|
||||
* This particular converter does not use the general single-byte converter
|
||||
* helper object. That is because someone may want to optimise this converter
|
||||
* to the fullest, as it is the most heavily used one.
|
||||
*
|
||||
* Multithreading: not an issue, the object has one instance per user thread.
|
||||
* As a plus, it is also stateless!
|
||||
*
|
||||
* @created 23/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsAscii2Unicode : public nsIUnicodeDecoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsAscii2Unicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsAscii2Unicode();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIUnicodeDecoder [declaration]
|
||||
|
||||
NS_IMETHOD Convert(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength,const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 * aSrcLength);
|
||||
NS_IMETHOD Finish(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Length(const char * aSrc, PRInt32 aSrcOffset, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Reset();
|
||||
NS_IMETHOD SetInputErrorBehavior(PRInt32 aBehavior);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsAscii2Unicode [implementation]
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAscii2Unicode, kIUnicodeDecoderIID);
|
||||
|
||||
nsAscii2Unicode::nsAscii2Unicode()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsAscii2Unicode::~nsAscii2Unicode()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverter [implementation]
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::Convert(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength,
|
||||
const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 * aSrcLength)
|
||||
{
|
||||
if (aDest == NULL) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRInt32 len = PR_MIN(*aSrcLength, *aDestLength);
|
||||
for (PRInt32 i=0; i<len; i++) *aDest++ = ((PRUint8)*aSrc++);
|
||||
|
||||
nsresult res = (*aSrcLength > len)? NS_PARTIAL_MORE_OUTPUT : NS_OK;
|
||||
*aSrcLength = *aDestLength = len;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::Finish(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// it is really only a stateless converter...
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::Length(const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// we are a single byte to Unicode converter, so...
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_EXACT_LENGTH;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::Reset()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::SetInputErrorBehavior(PRInt32 aBehavior)
|
||||
{
|
||||
// no input error possible, this encoding is too simple
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsAscii2UnicodeFactory [implementation]
|
||||
|
||||
nsAscii2UnicodeFactory::nsAscii2UnicodeFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsAscii2UnicodeFactory::~nsAscii2UnicodeFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsAscii2UnicodeFactory);
|
||||
NS_IMPL_RELEASE(nsAscii2UnicodeFactory);
|
||||
|
||||
nsresult nsAscii2UnicodeFactory::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, kICharsetConverterInfoIID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
if (aIID.Equals(kClassIID)) {
|
||||
*aInstancePtr = (void*) ((nsICharsetConverterInfo*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*) ((nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIFactory [implementation]
|
||||
|
||||
NS_IMETHODIMP nsAscii2UnicodeFactory::CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsIUnicodeDecoder * t = new nsAscii2Unicode;
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2UnicodeFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsAscii2UnicodeFactory::GetCharsetSrc(nsString ** aCharset)
|
||||
{
|
||||
(*aCharset) = new nsString(NS_SRC_CHARSET);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2UnicodeFactory::GetCharsetDest(nsString ** aCharset)
|
||||
{
|
||||
(*aCharset) = new nsString(NS_DEST_CHARSET);
|
||||
return NS_OK;
|
||||
}
|
|
@ -27,9 +27,12 @@
|
|||
#include "nsICharsetConverterInfo.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
#include "nsUnicodeDecodeUtil.h"
|
||||
#include "nsCharsetConverterManager.h"
|
||||
#include "nsConverterCID.h"
|
||||
#include "nsUConvDll.h"
|
||||
#include "registryhack1.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
@ -206,13 +209,8 @@ nsresult nsCharsetConverterManager::CreateMapping()
|
|||
// slots.
|
||||
nsresult nsCharsetConverterManager::CreateConvertersList()
|
||||
{
|
||||
mDecSize = 1;
|
||||
mDecArray = new ConverterInfo [mDecSize];
|
||||
|
||||
mDecArray[0].mCID = &kAscii2UnicodeCID;
|
||||
|
||||
mEncSize = 0;
|
||||
mEncArray = NULL;
|
||||
#include "registryhack2.h"
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -425,11 +423,21 @@ NS_IMETHODIMP nsManagerFactory::CreateInstance(nsISupports *aDelegate,
|
|||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsICharsetConverterManager * t = nsCharsetConverterManager::GetInstance();
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (aIID.Equals(kICharsetConverterManagerIID))
|
||||
{
|
||||
nsICharsetConverterManager * t = nsCharsetConverterManager::GetInstance();
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
} else if(aIID.Equals(kIUnicodeDecodeUtilIID)) {
|
||||
nsIUnicodeDecodeUtil * t = new nsUnicodeDecodeUtil();
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
}
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -80,6 +80,8 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(const char * path)
|
|||
{
|
||||
nsresult res;
|
||||
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kAscii2UnicodeCID, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsUConvDll.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsUnicodeDecodeUtil.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
|
||||
|
||||
// #define NO_OPTIMIZATION_FOR_1TABLE
|
||||
#define UCONV_ASSERT(a)
|
||||
|
||||
NS_IMPL_ISUPPORTS( nsUnicodeDecodeUtil, kIUnicodeDecodeUtilIID);
|
||||
|
||||
nsUnicodeDecodeUtil::nsUnicodeDecodeUtil()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
nsUnicodeDecodeUtil::~nsUnicodeDecodeUtil()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
#ifdef NO_OPTIMIZATION_FOR_1TABLE
|
||||
NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertBy1Table(
|
||||
PRUnichar *aDest,
|
||||
PRInt32 aDestOffset,
|
||||
PRInt32 *aDestLength,
|
||||
const char *aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32 *aSrcLength,
|
||||
uShiftTable *aShiftTable,
|
||||
uMappingTable *aMappingTable
|
||||
)
|
||||
{
|
||||
uRange range = {0x00, 0xff};
|
||||
return ConvertByNTable(aDest, aDestOffset, aDestLength, aSrc, aSrcOffset, aSrcLength,
|
||||
1, &range,
|
||||
aShiftTable, aMappingTable);
|
||||
}
|
||||
#else
|
||||
NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertBy1Table(
|
||||
PRUnichar *aDest,
|
||||
PRInt32 aDestOffset,
|
||||
PRInt32 *aDestLength,
|
||||
const char *aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32 *aSrcLength,
|
||||
uShiftTable *aShiftTable,
|
||||
uMappingTable *aMappingTable
|
||||
)
|
||||
{
|
||||
PRUint32 ubuflen = *aDestLength;
|
||||
PRUint32 srclen = *aSrcLength;
|
||||
PRUint32 validlen,scanlen;
|
||||
PRUint16 med;
|
||||
unsigned char* src = (unsigned char*)aSrc + aSrcOffset;
|
||||
PRUnichar* dest = aDest + aDestOffset;
|
||||
|
||||
*dest = (PRUnichar) 0;
|
||||
for(validlen=0;
|
||||
((srclen > 0) && (ubuflen > 0));
|
||||
srclen -= scanlen, src += scanlen, dest++, ubuflen--,validlen++ ) {
|
||||
scanlen = 0;
|
||||
if(uScan(aShiftTable, (PRInt32*) 0, src, &med, srclen, &scanlen)) {
|
||||
uMapCode((uTable*) aMappingTable,med, dest);
|
||||
if(*dest == NOMAPPING) {
|
||||
//------
|
||||
// Fallback handling - need to change
|
||||
//------
|
||||
// ERROR_ILLEGAL_INPUT
|
||||
if(scanlen == 0)
|
||||
scanlen = 1;
|
||||
}
|
||||
} else {
|
||||
*aSrcLength -= srclen;
|
||||
*aDestLength = validlen;
|
||||
return NS_PARTIAL_MORE_INPUT;
|
||||
}
|
||||
}
|
||||
*aSrcLength -= srclen;
|
||||
*aDestLength = validlen;
|
||||
if(srclen > 0)
|
||||
return NS_PARTIAL_MORE_OUTPUT;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP nsUnicodeDecodeUtil::ConvertByNTable(
|
||||
PRUnichar *aDest,
|
||||
PRInt32 aDestOffset,
|
||||
PRInt32 *aDestLength,
|
||||
const char *aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32 *aSrcLength,
|
||||
PRUint16 numberOfTable,
|
||||
uRange *aRangeArray,
|
||||
uShiftTable *aShiftTableArray,
|
||||
uMappingTable *aMappingTableArray
|
||||
)
|
||||
{
|
||||
PRUint32 ubuflen = *aDestLength;
|
||||
PRUint32 srclen = *aSrcLength;
|
||||
PRUint32 validlen,scanlen;
|
||||
PRUint16 med;
|
||||
unsigned char* src = (unsigned char*)aSrc + aSrcOffset;
|
||||
PRUnichar* dest = aDest + aDestOffset;
|
||||
|
||||
*dest = (PRUnichar) 0;
|
||||
for(validlen=0;
|
||||
((srclen > 0) && (ubuflen > 0));
|
||||
srclen -= scanlen, src += scanlen, dest++, ubuflen--,validlen++ ) {
|
||||
PRUint16 i;
|
||||
scanlen = 0;
|
||||
for(i=0;i<numberOfTable;i++) {
|
||||
if((aRangeArray[i].min <= *src) &&
|
||||
(*src <= aRangeArray[i].max)) {
|
||||
if(uScan(&aShiftTableArray[i], (PRInt32*) 0,
|
||||
src, &med, srclen, &scanlen)) {
|
||||
uMapCode((uTable*) &aMappingTableArray[i],med, dest);
|
||||
if(*dest != NOMAPPING)
|
||||
break;
|
||||
} else {
|
||||
*aSrcLength -= srclen;
|
||||
*aDestLength = validlen;
|
||||
return NS_PARTIAL_MORE_INPUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(i == numberOfTable) {
|
||||
//------
|
||||
// Fallback handling - need to change
|
||||
//------
|
||||
// ERROR_ILLEGAL_INPUT
|
||||
if(scanlen == 0)
|
||||
scanlen = 1;
|
||||
*dest= NOMAPPING;
|
||||
}
|
||||
}
|
||||
*aSrcLength -= srclen;
|
||||
*aDestLength = validlen;
|
||||
if(srclen > 0)
|
||||
return NS_PARTIAL_MORE_OUTPUT;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- 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 nsUnicodeDecodeUtil_h__
|
||||
#define nsUnicodeDecodeUtil_h__
|
||||
|
||||
#include "unicpriv.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
|
||||
|
||||
#define UCONV_ASSERT(a)
|
||||
|
||||
|
||||
|
||||
class nsUnicodeDecodeUtil : public nsIUnicodeDecodeUtil {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
/**
|
||||
*
|
||||
*/
|
||||
nsUnicodeDecodeUtil();
|
||||
|
||||
~nsUnicodeDecodeUtil();
|
||||
|
||||
public:
|
||||
NS_IMETHOD ConvertBy1Table(
|
||||
PRUnichar *aDest,
|
||||
PRInt32 aDestOffset,
|
||||
PRInt32 *aDestLength,
|
||||
const char *aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32 *aSrcLength,
|
||||
uShiftTable *aShiftTable,
|
||||
uMappingTable *aMappingTable
|
||||
);
|
||||
|
||||
NS_IMETHOD ConvertByNTable(
|
||||
PRUnichar *aDest,
|
||||
PRInt32 aDestOffset,
|
||||
PRInt32 *aDestLength,
|
||||
const char *aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32 *aSrcLength,
|
||||
PRUint16 numOfTable,
|
||||
uRange *aRangeArray,
|
||||
uShiftTable *aShiftTableArray,
|
||||
uMappingTable *aMappingTableArray
|
||||
);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,25 @@
|
|||
/* -*- 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 __REGISTRYHACK1_H__
|
||||
#define __REGISTRYHACK1_H__
|
||||
|
||||
#include "nsConverterCID.h"
|
||||
#include "nsUCVJACID.h"
|
||||
|
||||
#endif /* __REGISTRYHACK1_H__ */
|
|
@ -0,0 +1,28 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
mDecSize = 2;
|
||||
mDecArray = new ConverterInfo [mDecSize];
|
||||
|
||||
mDecArray[0].mCID = &kAscii2UnicodeCID;
|
||||
mDecArray[1].mCID = &kSJIS2UnicodeCID;
|
||||
|
||||
mEncSize = 0;
|
||||
mEncArray = NULL;
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/* -*- 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 ubase_h__
|
||||
#define ubase_h__
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef NS_WIN32
|
||||
#define NS_WIN32 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__unix)
|
||||
#ifndef NS_UNIX
|
||||
#define NS_UNIX 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
#define PRIVATE
|
||||
#define MODULE_PRIVATE
|
||||
|
||||
#endif
|
|
@ -0,0 +1,380 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#include "unicpriv.h"
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
typedef PRBool (*uSubGeneratorFunc) (PRUint16 in, unsigned char* out);
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
|
||||
typedef PRBool (*uGeneratorFunc) (
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
|
||||
MODULE_PRIVATE PRBool uGenerate(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
|
||||
#define uSubGennerator(sub,in,out) (* m_subgenerator[sub])((in),(out))
|
||||
|
||||
PRIVATE PRBool uCheckAndGenAlways1Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGenAlways2Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGenAlways2ByteShiftGR(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGenByTable(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGen2ByteGRPrefix8F(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA2(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
|
||||
|
||||
PRIVATE PRBool uGenAlways2Byte(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways2ByteShiftGR(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways1Byte(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways1BytePrefix8E(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways2ByteUTF8(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways3ByteUTF8(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE uGeneratorFunc m_generator[uNumOfCharsetType] =
|
||||
{
|
||||
uCheckAndGenAlways1Byte,
|
||||
uCheckAndGenAlways2Byte,
|
||||
uCheckAndGenByTable,
|
||||
uCheckAndGenAlways2ByteShiftGR,
|
||||
uCheckAndGen2ByteGRPrefix8F,
|
||||
uCheckAndGen2ByteGRPrefix8EA2,
|
||||
};
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
|
||||
PRIVATE uSubGeneratorFunc m_subgenerator[uNumOfCharType] =
|
||||
{
|
||||
uGenAlways1Byte,
|
||||
uGenAlways2Byte,
|
||||
uGenAlways2ByteShiftGR,
|
||||
uGenAlways1BytePrefix8E,
|
||||
uGenAlways2ByteUTF8,
|
||||
uGenAlways3ByteUTF8
|
||||
|
||||
};
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
MODULE_PRIVATE PRBool uGenerate(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
return (* m_generator[shift->classID]) (shift,state,in,out,outbuflen,outlen);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways1Byte(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)in;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways2Byte(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)((in >> 8) & 0xff);
|
||||
out[1] = (unsigned char)(in & 0xff);
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways2ByteShiftGR(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)(((in >> 8) & 0xff) | 0x80);
|
||||
out[1] = (unsigned char)((in & 0xff) | 0x80);
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways1BytePrefix8E(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = 0x8E;
|
||||
out[1] = (unsigned char)(in & 0xff);
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways2ByteUTF8(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)(0xC0 | (( in >> 6 ) & 0x1F));
|
||||
out[1] = (unsigned char)(0x80 | (( in ) & 0x3F));
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways3ByteUTF8(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)(0xE0 | (( in >> 12 ) & 0x0F));
|
||||
out[1] = (unsigned char)(0x80 | (( in >> 6 ) & 0x3F));
|
||||
out[2] = (unsigned char)(0x80 | (( in ) & 0x3F));
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGenAlways1Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
/* Don't check inlen. The caller should ensure it is larger than 0 */
|
||||
*outlen = 1;
|
||||
out[0] = in & 0xff;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGenAlways2Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
if(outbuflen < 2)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = 2;
|
||||
out[0] = ((in >> 8 ) & 0xff);
|
||||
out[1] = in & 0xff;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGenAlways2ByteShiftGR(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
if(outbuflen < 2)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = 2;
|
||||
out[0] = ((in >> 8 ) & 0xff) | 0x80;
|
||||
out[1] = (in & 0xff) | 0x80;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGenByTable(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
PRInt16 i;
|
||||
uShiftCell* cell = &(shift->shiftcell[0]);
|
||||
PRInt16 itemnum = shift->numOfItem;
|
||||
unsigned char inH, inL;
|
||||
inH = (in >> 8) & 0xff;
|
||||
inL = (in & 0xff );
|
||||
for(i=0;i<itemnum;i++)
|
||||
{
|
||||
if( ( inL >= cell[i].shiftout.MinLB) &&
|
||||
( inL <= cell[i].shiftout.MaxLB) &&
|
||||
( inH >= cell[i].shiftout.MinHB) &&
|
||||
( inH <= cell[i].shiftout.MaxHB) )
|
||||
{
|
||||
if(outbuflen < cell[i].reserveLen)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = cell[i].reserveLen;
|
||||
return (uSubGennerator(cell[i].classID,in,out));
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGen2ByteGRPrefix8F( uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
if(outbuflen < 3)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = 3;
|
||||
out[0] = 0x8F;
|
||||
out[1] = ((in >> 8 ) & 0xff) | 0x80;
|
||||
out[2] = (in & 0xff) | 0x80;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA2( uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
if(outbuflen < 4)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = 4;
|
||||
out[0] = 0x8E;
|
||||
out[1] = 0xA2;
|
||||
out[2] = ((in >> 8 ) & 0xff) | 0x80;
|
||||
out[3] = (in & 0xff) | 0x80;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* #include "PRIntlpriv.h" */
|
||||
#include "unicpriv.h"
|
||||
|
||||
|
||||
typedef PRUint16 (* MapFormatFunc)(PRUint16 in,uTable *uT,uMapCell *cell);
|
||||
typedef PRBool (* HitFormateFunc)(PRUint16 in,uMapCell *cell);
|
||||
|
||||
|
||||
PRIVATE PRBool uHitFormate0(PRUint16 in,uMapCell *cell);
|
||||
PRIVATE PRBool uHitFormate1(PRUint16 in,uMapCell *cell);
|
||||
PRIVATE PRBool uHitFormate2(PRUint16 in,uMapCell *cell);
|
||||
PRIVATE PRUint16 uMapFormate0(PRUint16 in,uTable *uT,uMapCell *cell);
|
||||
PRIVATE PRUint16 uMapFormate1(PRUint16 in,uTable *uT,uMapCell *cell);
|
||||
PRIVATE PRUint16 uMapFormate2(PRUint16 in,uTable *uT,uMapCell *cell);
|
||||
|
||||
|
||||
PRIVATE uMapCell *uGetMapCell(uTable *uT, PRInt16 item);
|
||||
PRIVATE char uGetFormat(uTable *uT, PRInt16 item);
|
||||
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE MapFormatFunc m_map[uNumFormatTag] =
|
||||
{
|
||||
uMapFormate0,
|
||||
uMapFormate1,
|
||||
uMapFormate2,
|
||||
};
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE HitFormateFunc m_hit[uNumFormatTag] =
|
||||
{
|
||||
uHitFormate0,
|
||||
uHitFormate1,
|
||||
uHitFormate2,
|
||||
};
|
||||
|
||||
/*
|
||||
Need more work
|
||||
*/
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uHit(unsigned char format, PRUint16 in,uMapCell *cell)
|
||||
{
|
||||
return (* m_hit[format])((in),(cell));
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
/*
|
||||
Switch to Macro later for performance
|
||||
|
||||
#define uHit(format,in,cell) (* m_hit[format])((in),(cell))
|
||||
*/
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRUint16 uMap(unsigned char format, PRUint16 in,uTable *uT,uMapCell *cell)
|
||||
{
|
||||
return (* m_map[format])((in),(uT),(cell));
|
||||
}
|
||||
/*
|
||||
Switch to Macro later for performance
|
||||
|
||||
#define uMap(format,in,cell) (* m_map[format])((in),(cell))
|
||||
*/
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
/*
|
||||
Switch to Macro later for performance
|
||||
*/
|
||||
PRIVATE uMapCell *uGetMapCell(uTable *uT, PRInt16 item)
|
||||
{
|
||||
return ((uMapCell *)(((PRUint16 *)uT) + uT->offsetToMapCellArray) + item) ;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
/*
|
||||
Switch to Macro later for performance
|
||||
*/
|
||||
PRIVATE char uGetFormat(uTable *uT, PRInt16 item)
|
||||
{
|
||||
return (((((PRUint16 *)uT) + uT->offsetToFormatArray)[ item >> 2 ]
|
||||
>> (( item % 4 ) << 2)) & 0x0f);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
MODULE_PRIVATE PRBool uMapCode(uTable *uT, PRUint16 in, PRUint16* out)
|
||||
{
|
||||
PRBool done = PR_FALSE;
|
||||
PRUint16 itemOfList = uT->itemOfList;
|
||||
PRUint16 i;
|
||||
*out = NOMAPPING;
|
||||
for(i=0;i<itemOfList;i++)
|
||||
{
|
||||
uMapCell* uCell;
|
||||
char format = uGetFormat(uT,i);
|
||||
uCell = uGetMapCell(uT,i);
|
||||
if(uHit(format, in, uCell))
|
||||
{
|
||||
*out = uMap(format, in, uT,uCell);
|
||||
done = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ( done && (*out != NOMAPPING));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
member function
|
||||
*/
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uHitFormate0(PRUint16 in,uMapCell *cell)
|
||||
{
|
||||
return ( (in >= cell->fmt.format0.srcBegin) &&
|
||||
(in <= cell->fmt.format0.srcEnd) ) ;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uHitFormate1(PRUint16 in,uMapCell *cell)
|
||||
{
|
||||
return uHitFormate0(in,cell);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uHitFormate2(PRUint16 in,uMapCell *cell)
|
||||
{
|
||||
return (in == cell->fmt.format2.srcBegin);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRUint16 uMapFormate0(PRUint16 in,uTable *uT,uMapCell *cell)
|
||||
{
|
||||
return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRUint16 uMapFormate1(PRUint16 in,uTable *uT,uMapCell *cell)
|
||||
{
|
||||
return (*(((PRUint16 *)uT) + uT->offsetToMappingTable
|
||||
+ cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin));
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRUint16 uMapFormate2(PRUint16 in,uTable *uT,uMapCell *cell)
|
||||
{
|
||||
return (cell->fmt.format2.destBegin);
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef __UMAP__
|
||||
#define __UMAP__
|
||||
|
||||
#define NOMAPPING 0xfffd
|
||||
|
||||
enum {
|
||||
uFormat0Tag = 0,
|
||||
uFormat1Tag,
|
||||
uFormat2Tag,
|
||||
uNumFormatTag
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PRUint16 srcBegin; /* 2 byte */
|
||||
PRUint16 srcEnd; /* 2 byte */
|
||||
PRUint16 destBegin; /* 2 byte */
|
||||
} uFormat0;
|
||||
|
||||
typedef struct {
|
||||
PRUint16 srcBegin; /* 2 byte */
|
||||
PRUint16 srcEnd; /* 2 byte */
|
||||
PRUint16 mappingOffset; /* 2 byte */
|
||||
} uFormat1;
|
||||
|
||||
typedef struct {
|
||||
PRUint16 srcBegin; /* 2 byte */
|
||||
PRUint16 srcEnd; /* 2 byte -waste */
|
||||
PRUint16 destBegin; /* 2 byte */
|
||||
} uFormat2;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
uFormat0 format0;
|
||||
uFormat1 format1;
|
||||
uFormat2 format2;
|
||||
} fmt;
|
||||
} uMapCell;
|
||||
|
||||
typedef struct {
|
||||
PRUint16 itemOfList;
|
||||
PRUint16 offsetToFormatArray;
|
||||
PRUint16 offsetToMapCellArray;
|
||||
PRUint16 offsetToMappingTable;
|
||||
PRUint16 data[1];
|
||||
} uTable;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef __UNIPRIV__
|
||||
#define __UNIPRIV__
|
||||
|
||||
#include "ubase.h"
|
||||
#include "umap.h"
|
||||
#include "uconvutil.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
PRBool uMapCode( uTable *uT,
|
||||
PRUint16 in,
|
||||
PRUint16* out);
|
||||
|
||||
PRBool uGenerate( uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen);
|
||||
|
||||
PRBool uScan( uShiftTable *shift,
|
||||
PRInt32 *state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* __UNIPRIV__ */
|
|
@ -0,0 +1,366 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#include "unicpriv.h"
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
typedef PRBool (*uSubScannerFunc) (unsigned char* in, PRUint16* out);
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
|
||||
typedef PRBool (*uScannerFunc) (
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
|
||||
MODULE_PRIVATE PRBool uScan(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
|
||||
#define uSubScanner(sub,in,out) (* m_subscanner[sub])((in),(out))
|
||||
|
||||
PRIVATE PRBool uCheckAndScanAlways1Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScanAlways2Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScanAlways2ByteShiftGR(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScanByTable(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScan2ByteGRPrefix8F(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA2(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
|
||||
|
||||
PRIVATE PRBool uScanAlways2Byte(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways2ByteShiftGR(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways1Byte(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways1BytePrefix8E(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways2ByteUTF8(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways3ByteUTF8(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE uScannerFunc m_scanner[uNumOfCharsetType] =
|
||||
{
|
||||
uCheckAndScanAlways1Byte,
|
||||
uCheckAndScanAlways2Byte,
|
||||
uCheckAndScanByTable,
|
||||
uCheckAndScanAlways2ByteShiftGR,
|
||||
uCheckAndScan2ByteGRPrefix8F,
|
||||
uCheckAndScan2ByteGRPrefix8EA2,
|
||||
};
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
|
||||
PRIVATE uSubScannerFunc m_subscanner[uNumOfCharType] =
|
||||
{
|
||||
uScanAlways1Byte,
|
||||
uScanAlways2Byte,
|
||||
uScanAlways2ByteShiftGR,
|
||||
uScanAlways1BytePrefix8E,
|
||||
uScanAlways2ByteUTF8,
|
||||
uScanAlways3ByteUTF8
|
||||
};
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
MODULE_PRIVATE PRBool uScan(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
return (* m_scanner[shift->classID]) (shift,state,in,out,inbuflen,inscanlen);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways1Byte(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) in[0];
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways2Byte(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) (( in[0] << 8) | (in[1]));
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways2ByteShiftGR(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) ((( in[0] << 8) | (in[1])) & 0x7F7F);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways1BytePrefix8E(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) in[1];
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways2ByteUTF8(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) (((in[0] & 0x001F) << 6 )| (in[1] & 0x003F));
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways3ByteUTF8(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) (((in[0] & 0x000F) << 12 ) | ((in[1] & 0x003F) << 6)
|
||||
| (in[2] & 0x003F));
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScanAlways1Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
/* Don't check inlen. The caller should ensure it is larger than 0 */
|
||||
*inscanlen = 1;
|
||||
*out = (PRUint16) in[0];
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScanAlways2Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
if(inbuflen < 2)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = 2;
|
||||
*out = ((in[0] << 8) | ( in[1])) ;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScanAlways2ByteShiftGR(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
if(inbuflen < 2)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = 2;
|
||||
*out = (((in[0] << 8) | ( in[1])) & 0x7F7F);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScanByTable(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
PRInt16 i;
|
||||
uShiftCell* cell = &(shift->shiftcell[0]);
|
||||
PRInt16 itemnum = shift->numOfItem;
|
||||
for(i=0;i<itemnum;i++)
|
||||
{
|
||||
if( ( in[0] >= cell[i].shiftin.Min) &&
|
||||
( in[0] <= cell[i].shiftin.Max))
|
||||
{
|
||||
if(inbuflen < cell[i].reserveLen)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = cell[i].reserveLen;
|
||||
return (uSubScanner(cell[i].classID,in,out));
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScan2ByteGRPrefix8F(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
if((inbuflen < 3) ||(in[0] != 0x8F))
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = 3;
|
||||
*out = (((in[1] << 8) | ( in[2])) & 0x7F7F);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA2(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA2))
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = 4;
|
||||
*out = (((in[2] << 8) | ( in[3])) & 0x7F7F);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/* -*- 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 ubase_h__
|
||||
#define ubase_h__
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef NS_WIN32
|
||||
#define NS_WIN32 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__unix)
|
||||
#ifndef NS_UNIX
|
||||
#define NS_UNIX 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
#define PRIVATE
|
||||
#define MODULE_PRIVATE
|
||||
|
||||
#endif
|
|
@ -0,0 +1,380 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#include "unicpriv.h"
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
typedef PRBool (*uSubGeneratorFunc) (PRUint16 in, unsigned char* out);
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
|
||||
typedef PRBool (*uGeneratorFunc) (
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
|
||||
MODULE_PRIVATE PRBool uGenerate(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
|
||||
#define uSubGennerator(sub,in,out) (* m_subgenerator[sub])((in),(out))
|
||||
|
||||
PRIVATE PRBool uCheckAndGenAlways1Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGenAlways2Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGenAlways2ByteShiftGR(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGenByTable(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGen2ByteGRPrefix8F(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA2(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
);
|
||||
|
||||
|
||||
PRIVATE PRBool uGenAlways2Byte(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways2ByteShiftGR(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways1Byte(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways1BytePrefix8E(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways2ByteUTF8(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
PRIVATE PRBool uGenAlways3ByteUTF8(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
);
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE uGeneratorFunc m_generator[uNumOfCharsetType] =
|
||||
{
|
||||
uCheckAndGenAlways1Byte,
|
||||
uCheckAndGenAlways2Byte,
|
||||
uCheckAndGenByTable,
|
||||
uCheckAndGenAlways2ByteShiftGR,
|
||||
uCheckAndGen2ByteGRPrefix8F,
|
||||
uCheckAndGen2ByteGRPrefix8EA2,
|
||||
};
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
|
||||
PRIVATE uSubGeneratorFunc m_subgenerator[uNumOfCharType] =
|
||||
{
|
||||
uGenAlways1Byte,
|
||||
uGenAlways2Byte,
|
||||
uGenAlways2ByteShiftGR,
|
||||
uGenAlways1BytePrefix8E,
|
||||
uGenAlways2ByteUTF8,
|
||||
uGenAlways3ByteUTF8
|
||||
|
||||
};
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
MODULE_PRIVATE PRBool uGenerate(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
return (* m_generator[shift->classID]) (shift,state,in,out,outbuflen,outlen);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways1Byte(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)in;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways2Byte(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)((in >> 8) & 0xff);
|
||||
out[1] = (unsigned char)(in & 0xff);
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways2ByteShiftGR(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)(((in >> 8) & 0xff) | 0x80);
|
||||
out[1] = (unsigned char)((in & 0xff) | 0x80);
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways1BytePrefix8E(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = 0x8E;
|
||||
out[1] = (unsigned char)(in & 0xff);
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways2ByteUTF8(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)(0xC0 | (( in >> 6 ) & 0x1F));
|
||||
out[1] = (unsigned char)(0x80 | (( in ) & 0x3F));
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uGenAlways3ByteUTF8(
|
||||
PRUint16 in,
|
||||
unsigned char* out
|
||||
)
|
||||
{
|
||||
out[0] = (unsigned char)(0xE0 | (( in >> 12 ) & 0x0F));
|
||||
out[1] = (unsigned char)(0x80 | (( in >> 6 ) & 0x3F));
|
||||
out[2] = (unsigned char)(0x80 | (( in ) & 0x3F));
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGenAlways1Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
/* Don't check inlen. The caller should ensure it is larger than 0 */
|
||||
*outlen = 1;
|
||||
out[0] = in & 0xff;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGenAlways2Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
if(outbuflen < 2)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = 2;
|
||||
out[0] = ((in >> 8 ) & 0xff);
|
||||
out[1] = in & 0xff;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGenAlways2ByteShiftGR(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
if(outbuflen < 2)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = 2;
|
||||
out[0] = ((in >> 8 ) & 0xff) | 0x80;
|
||||
out[1] = (in & 0xff) | 0x80;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGenByTable(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
PRInt16 i;
|
||||
uShiftCell* cell = &(shift->shiftcell[0]);
|
||||
PRInt16 itemnum = shift->numOfItem;
|
||||
unsigned char inH, inL;
|
||||
inH = (in >> 8) & 0xff;
|
||||
inL = (in & 0xff );
|
||||
for(i=0;i<itemnum;i++)
|
||||
{
|
||||
if( ( inL >= cell[i].shiftout.MinLB) &&
|
||||
( inL <= cell[i].shiftout.MaxLB) &&
|
||||
( inH >= cell[i].shiftout.MinHB) &&
|
||||
( inH <= cell[i].shiftout.MaxHB) )
|
||||
{
|
||||
if(outbuflen < cell[i].reserveLen)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = cell[i].reserveLen;
|
||||
return (uSubGennerator(cell[i].classID,in,out));
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGen2ByteGRPrefix8F( uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
if(outbuflen < 3)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = 3;
|
||||
out[0] = 0x8F;
|
||||
out[1] = ((in >> 8 ) & 0xff) | 0x80;
|
||||
out[2] = (in & 0xff) | 0x80;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndGen2ByteGRPrefix8EA2( uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen
|
||||
)
|
||||
{
|
||||
if(outbuflen < 4)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*outlen = 4;
|
||||
out[0] = 0x8E;
|
||||
out[1] = 0xA2;
|
||||
out[2] = ((in >> 8 ) & 0xff) | 0x80;
|
||||
out[3] = (in & 0xff) | 0x80;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* #include "PRIntlpriv.h" */
|
||||
#include "unicpriv.h"
|
||||
|
||||
|
||||
typedef PRUint16 (* MapFormatFunc)(PRUint16 in,uTable *uT,uMapCell *cell);
|
||||
typedef PRBool (* HitFormateFunc)(PRUint16 in,uMapCell *cell);
|
||||
|
||||
|
||||
PRIVATE PRBool uHitFormate0(PRUint16 in,uMapCell *cell);
|
||||
PRIVATE PRBool uHitFormate1(PRUint16 in,uMapCell *cell);
|
||||
PRIVATE PRBool uHitFormate2(PRUint16 in,uMapCell *cell);
|
||||
PRIVATE PRUint16 uMapFormate0(PRUint16 in,uTable *uT,uMapCell *cell);
|
||||
PRIVATE PRUint16 uMapFormate1(PRUint16 in,uTable *uT,uMapCell *cell);
|
||||
PRIVATE PRUint16 uMapFormate2(PRUint16 in,uTable *uT,uMapCell *cell);
|
||||
|
||||
|
||||
PRIVATE uMapCell *uGetMapCell(uTable *uT, PRInt16 item);
|
||||
PRIVATE char uGetFormat(uTable *uT, PRInt16 item);
|
||||
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE MapFormatFunc m_map[uNumFormatTag] =
|
||||
{
|
||||
uMapFormate0,
|
||||
uMapFormate1,
|
||||
uMapFormate2,
|
||||
};
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE HitFormateFunc m_hit[uNumFormatTag] =
|
||||
{
|
||||
uHitFormate0,
|
||||
uHitFormate1,
|
||||
uHitFormate2,
|
||||
};
|
||||
|
||||
/*
|
||||
Need more work
|
||||
*/
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uHit(unsigned char format, PRUint16 in,uMapCell *cell)
|
||||
{
|
||||
return (* m_hit[format])((in),(cell));
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
/*
|
||||
Switch to Macro later for performance
|
||||
|
||||
#define uHit(format,in,cell) (* m_hit[format])((in),(cell))
|
||||
*/
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRUint16 uMap(unsigned char format, PRUint16 in,uTable *uT,uMapCell *cell)
|
||||
{
|
||||
return (* m_map[format])((in),(uT),(cell));
|
||||
}
|
||||
/*
|
||||
Switch to Macro later for performance
|
||||
|
||||
#define uMap(format,in,cell) (* m_map[format])((in),(cell))
|
||||
*/
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
/*
|
||||
Switch to Macro later for performance
|
||||
*/
|
||||
PRIVATE uMapCell *uGetMapCell(uTable *uT, PRInt16 item)
|
||||
{
|
||||
return ((uMapCell *)(((PRUint16 *)uT) + uT->offsetToMapCellArray) + item) ;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
/*
|
||||
Switch to Macro later for performance
|
||||
*/
|
||||
PRIVATE char uGetFormat(uTable *uT, PRInt16 item)
|
||||
{
|
||||
return (((((PRUint16 *)uT) + uT->offsetToFormatArray)[ item >> 2 ]
|
||||
>> (( item % 4 ) << 2)) & 0x0f);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
MODULE_PRIVATE PRBool uMapCode(uTable *uT, PRUint16 in, PRUint16* out)
|
||||
{
|
||||
PRBool done = PR_FALSE;
|
||||
PRUint16 itemOfList = uT->itemOfList;
|
||||
PRUint16 i;
|
||||
*out = NOMAPPING;
|
||||
for(i=0;i<itemOfList;i++)
|
||||
{
|
||||
uMapCell* uCell;
|
||||
char format = uGetFormat(uT,i);
|
||||
uCell = uGetMapCell(uT,i);
|
||||
if(uHit(format, in, uCell))
|
||||
{
|
||||
*out = uMap(format, in, uT,uCell);
|
||||
done = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ( done && (*out != NOMAPPING));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
member function
|
||||
*/
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uHitFormate0(PRUint16 in,uMapCell *cell)
|
||||
{
|
||||
return ( (in >= cell->fmt.format0.srcBegin) &&
|
||||
(in <= cell->fmt.format0.srcEnd) ) ;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uHitFormate1(PRUint16 in,uMapCell *cell)
|
||||
{
|
||||
return uHitFormate0(in,cell);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uHitFormate2(PRUint16 in,uMapCell *cell)
|
||||
{
|
||||
return (in == cell->fmt.format2.srcBegin);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRUint16 uMapFormate0(PRUint16 in,uTable *uT,uMapCell *cell)
|
||||
{
|
||||
return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRUint16 uMapFormate1(PRUint16 in,uTable *uT,uMapCell *cell)
|
||||
{
|
||||
return (*(((PRUint16 *)uT) + uT->offsetToMappingTable
|
||||
+ cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin));
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRUint16 uMapFormate2(PRUint16 in,uTable *uT,uMapCell *cell)
|
||||
{
|
||||
return (cell->fmt.format2.destBegin);
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef __UMAP__
|
||||
#define __UMAP__
|
||||
|
||||
#define NOMAPPING 0xfffd
|
||||
|
||||
enum {
|
||||
uFormat0Tag = 0,
|
||||
uFormat1Tag,
|
||||
uFormat2Tag,
|
||||
uNumFormatTag
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PRUint16 srcBegin; /* 2 byte */
|
||||
PRUint16 srcEnd; /* 2 byte */
|
||||
PRUint16 destBegin; /* 2 byte */
|
||||
} uFormat0;
|
||||
|
||||
typedef struct {
|
||||
PRUint16 srcBegin; /* 2 byte */
|
||||
PRUint16 srcEnd; /* 2 byte */
|
||||
PRUint16 mappingOffset; /* 2 byte */
|
||||
} uFormat1;
|
||||
|
||||
typedef struct {
|
||||
PRUint16 srcBegin; /* 2 byte */
|
||||
PRUint16 srcEnd; /* 2 byte -waste */
|
||||
PRUint16 destBegin; /* 2 byte */
|
||||
} uFormat2;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
uFormat0 format0;
|
||||
uFormat1 format1;
|
||||
uFormat2 format2;
|
||||
} fmt;
|
||||
} uMapCell;
|
||||
|
||||
typedef struct {
|
||||
PRUint16 itemOfList;
|
||||
PRUint16 offsetToFormatArray;
|
||||
PRUint16 offsetToMapCellArray;
|
||||
PRUint16 offsetToMappingTable;
|
||||
PRUint16 data[1];
|
||||
} uTable;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef __UNIPRIV__
|
||||
#define __UNIPRIV__
|
||||
|
||||
#include "ubase.h"
|
||||
#include "umap.h"
|
||||
#include "uconvutil.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
PRBool uMapCode( uTable *uT,
|
||||
PRUint16 in,
|
||||
PRUint16* out);
|
||||
|
||||
PRBool uGenerate( uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
PRUint16 in,
|
||||
unsigned char* out,
|
||||
PRUint32 outbuflen,
|
||||
PRUint32* outlen);
|
||||
|
||||
PRBool uScan( uShiftTable *shift,
|
||||
PRInt32 *state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* __UNIPRIV__ */
|
|
@ -0,0 +1,366 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#include "unicpriv.h"
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
typedef PRBool (*uSubScannerFunc) (unsigned char* in, PRUint16* out);
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
|
||||
typedef PRBool (*uScannerFunc) (
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
|
||||
MODULE_PRIVATE PRBool uScan(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
|
||||
#define uSubScanner(sub,in,out) (* m_subscanner[sub])((in),(out))
|
||||
|
||||
PRIVATE PRBool uCheckAndScanAlways1Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScanAlways2Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScanAlways2ByteShiftGR(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScanByTable(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScan2ByteGRPrefix8F(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA2(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
);
|
||||
|
||||
|
||||
PRIVATE PRBool uScanAlways2Byte(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways2ByteShiftGR(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways1Byte(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways1BytePrefix8E(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways2ByteUTF8(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
PRIVATE PRBool uScanAlways3ByteUTF8(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
);
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE uScannerFunc m_scanner[uNumOfCharsetType] =
|
||||
{
|
||||
uCheckAndScanAlways1Byte,
|
||||
uCheckAndScanAlways2Byte,
|
||||
uCheckAndScanByTable,
|
||||
uCheckAndScanAlways2ByteShiftGR,
|
||||
uCheckAndScan2ByteGRPrefix8F,
|
||||
uCheckAndScan2ByteGRPrefix8EA2,
|
||||
};
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
|
||||
PRIVATE uSubScannerFunc m_subscanner[uNumOfCharType] =
|
||||
{
|
||||
uScanAlways1Byte,
|
||||
uScanAlways2Byte,
|
||||
uScanAlways2ByteShiftGR,
|
||||
uScanAlways1BytePrefix8E,
|
||||
uScanAlways2ByteUTF8,
|
||||
uScanAlways3ByteUTF8
|
||||
};
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
MODULE_PRIVATE PRBool uScan(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
return (* m_scanner[shift->classID]) (shift,state,in,out,inbuflen,inscanlen);
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways1Byte(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) in[0];
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways2Byte(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) (( in[0] << 8) | (in[1]));
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways2ByteShiftGR(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) ((( in[0] << 8) | (in[1])) & 0x7F7F);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways1BytePrefix8E(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) in[1];
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways2ByteUTF8(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) (((in[0] & 0x001F) << 6 )| (in[1] & 0x003F));
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uScanAlways3ByteUTF8(
|
||||
unsigned char* in,
|
||||
PRUint16* out
|
||||
)
|
||||
{
|
||||
*out = (PRUint16) (((in[0] & 0x000F) << 12 ) | ((in[1] & 0x003F) << 6)
|
||||
| (in[2] & 0x003F));
|
||||
return PR_TRUE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScanAlways1Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
/* Don't check inlen. The caller should ensure it is larger than 0 */
|
||||
*inscanlen = 1;
|
||||
*out = (PRUint16) in[0];
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScanAlways2Byte(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
if(inbuflen < 2)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = 2;
|
||||
*out = ((in[0] << 8) | ( in[1])) ;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScanAlways2ByteShiftGR(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
if(inbuflen < 2)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = 2;
|
||||
*out = (((in[0] << 8) | ( in[1])) & 0x7F7F);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScanByTable(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
PRInt16 i;
|
||||
uShiftCell* cell = &(shift->shiftcell[0]);
|
||||
PRInt16 itemnum = shift->numOfItem;
|
||||
for(i=0;i<itemnum;i++)
|
||||
{
|
||||
if( ( in[0] >= cell[i].shiftin.Min) &&
|
||||
( in[0] <= cell[i].shiftin.Max))
|
||||
{
|
||||
if(inbuflen < cell[i].reserveLen)
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = cell[i].reserveLen;
|
||||
return (uSubScanner(cell[i].classID,in,out));
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScan2ByteGRPrefix8F(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
if((inbuflen < 3) ||(in[0] != 0x8F))
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = 3;
|
||||
*out = (((in[1] << 8) | ( in[2])) & 0x7F7F);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
/*=================================================================================
|
||||
|
||||
=================================================================================*/
|
||||
PRIVATE PRBool uCheckAndScan2ByteGRPrefix8EA2(
|
||||
uShiftTable *shift,
|
||||
PRInt32* state,
|
||||
unsigned char *in,
|
||||
PRUint16 *out,
|
||||
PRUint32 inbuflen,
|
||||
PRUint32* inscanlen
|
||||
)
|
||||
{
|
||||
if((inbuflen < 4) || (in[0] != 0x8E) || (in[1] != 0xA2))
|
||||
return PR_FALSE;
|
||||
else
|
||||
{
|
||||
*inscanlen = 4;
|
||||
*out = (((in[2] << 8) | ( in[3])) & 0x7F7F);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче