Support class for fast table decoder added.

This commit is contained in:
cata%netscape.com 1999-04-19 20:28:08 +00:00
Родитель 517cab269c
Коммит 516e7fb583
10 изменённых файлов: 1185 добавлений и 1177 удалений

Просмотреть файл

@ -1,89 +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 "nsEUCJPToUnicode.h"
#include "nsUCVJA2Dll.h"
//----------------------------------------------------------------------
// Global functions and data [declaration]
// Shift Table
static PRInt16 g_0201ShiftTable[] = {
2, uMultibytesCharset,
ShiftCell(u1ByteChar, 1, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7F),
ShiftCell(u1BytePrefix8EChar, 2, 0x8E, 0x8E, 0x00, 0xA1, 0x00, 0xDF)
};
static PRInt16 g_0208ShiftTable[] = {
0, u2BytesGRCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 g_0212ShiftTable[] = {
0, u2BytesGRPrefix8FCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 *g_EUCJPShiftTable[4] = {
g_0208ShiftTable,
g_0201ShiftTable,
g_0201ShiftTable,
g_0212ShiftTable
};
static PRUint16 *g_EUCJPMappingTable[4] = {
g_ut0208Mapping,
g_ut0201Mapping,
g_ut0201Mapping,
g_ut0212Mapping
};
static uRange g_EUCJPRanges[] = {
{ 0xA1, 0xFE },
{ 0x00, 0x7F },
{ 0x8E, 0x8E },
{ 0x8F, 0x8F }
};
//----------------------------------------------------------------------
// Class nsEUCJPToUnicode [implementation]
nsEUCJPToUnicode::nsEUCJPToUnicode()
: nsTablesDecoderSupport(4,
(uRange *) &g_EUCJPRanges,
(uShiftTable**) &g_EUCJPShiftTable,
(uMappingTable**) &g_EUCJPMappingTable)
{
}
nsresult nsEUCJPToUnicode::CreateInstance(nsISupports ** aResult)
{
*aResult = new nsEUCJPToUnicode();
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
//----------------------------------------------------------------------
// Subclassing of nsTableDecoderSupport class [implementation]
NS_IMETHODIMP nsEUCJPToUnicode::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// worst case
*aDestLength = aSrcLength;
return NS_OK;
}

Просмотреть файл

@ -1,57 +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.
*/
#ifndef nsEUCJPToUnicode_h___
#define nsEUCJPToUnicode_h___
#include "nsUCvJa2Support.h"
//----------------------------------------------------------------------
// Class nsEUCJPToUnicode [declaration]
/**
* A character set converter from EUCJP to Unicode.
*
* @created 24/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsEUCJPToUnicode : public nsTablesDecoderSupport
{
public:
/**
* Class constructor.
*/
nsEUCJPToUnicode();
/**
* Static class constructor.
*/
static nsresult CreateInstance(nsISupports **aResult);
protected:
//--------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [declaration]
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
};
#endif /* nsEUCJPToUnicode_h___ */

Просмотреть файл

@ -24,6 +24,360 @@
#define DEFAULT_BUFFER_CAPACITY 16
// XXX review the buffer growth limitation code
//----------------------------------------------------------------------
// Class nsBasicDecoderSupport [implementation]
nsBasicDecoderSupport::nsBasicDecoderSupport()
{
NS_INIT_REFCNT();
PR_AtomicIncrement(&g_InstanceCount);
}
nsBasicDecoderSupport::~nsBasicDecoderSupport()
{
PR_AtomicDecrement(&g_InstanceCount);
}
//----------------------------------------------------------------------
// Interface nsISupports [implementation]
NS_IMPL_ADDREF(nsBasicDecoderSupport);
NS_IMPL_RELEASE(nsBasicDecoderSupport);
nsresult nsBasicDecoderSupport::QueryInterface(REFNSIID aIID,
void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kIUnicodeDecoderIID)) {
*aInstancePtr = (void*) ((nsIUnicodeDecoder*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
//----------------------------------------------------------------------
// Interface nsIUnicodeDecoder [implementation]
NS_IMETHODIMP nsBasicDecoderSupport::Convert(PRUnichar * aDest,
PRInt32 aDestOffset,
PRInt32 * aDestLength,
const char * aSrc,
PRInt32 aSrcOffset,
PRInt32 * aSrcLength)
{
// XXX deprecated
return Convert(aSrc + aSrcOffset, aSrcLength, aDest + aDestOffset,
aDestLength);
}
NS_IMETHODIMP nsBasicDecoderSupport::Finish(PRUnichar * aDest,
PRInt32 aDestOffset,
PRInt32 * aDestLength)
{
// XXX deprecated
return NS_OK;
}
NS_IMETHODIMP nsBasicDecoderSupport::Length(const char * aSrc,
PRInt32 aSrcOffset,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// XXX deprecated
return GetMaxLength(aSrc + aSrcOffset, aSrcLength, aDestLength);
}
NS_IMETHODIMP nsBasicDecoderSupport::SetInputErrorBehavior(PRInt32 aBehavior)
{
// XXX deprecated
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [implementation]
nsBufferDecoderSupport::nsBufferDecoderSupport()
: nsBasicDecoderSupport()
{
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
mBuffer = new char[mBufferCapacity];
Reset();
}
nsBufferDecoderSupport::~nsBufferDecoderSupport()
{
delete [] mBuffer;
}
void nsBufferDecoderSupport::FillBuffer(const char ** aSrc, PRInt32 aSrcLength)
{
PRInt32 bcr = PR_MIN(mBufferCapacity - mBufferLength, aSrcLength);
memcpy(mBuffer + mBufferLength, *aSrc, bcr);
mBufferLength += bcr;
(*aSrc) += bcr;
}
void nsBufferDecoderSupport::DoubleBuffer()
{
mBufferCapacity *= 2;
char * newBuffer = new char [mBufferCapacity];
if (mBufferLength > 0) memcpy(newBuffer, mBuffer, mBufferLength);
delete [] mBuffer;
mBuffer = newBuffer;
}
//----------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [implementation]
NS_IMETHODIMP nsBufferDecoderSupport::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
// we do all operations using pointers internally
const char * src = aSrc;
const char * srcEnd = aSrc + *aSrcLength;
PRUnichar * dest = aDest;
PRUnichar * destEnd = aDest + *aDestLength;
PRInt32 bcr, bcw; // byte counts for read & write;
nsresult res = NS_OK;
// do we have some residual data from the last conversion?
if (mBufferLength > 0) if (dest == destEnd) {
res = NS_OK_UDEC_MOREOUTPUT;
} else for (;;) {
// we need new data to add to the buffer
if (src == srcEnd) {
res = NS_OK_UDEC_MOREINPUT;
break;
}
// fill that buffer
PRInt32 buffLen = mBufferLength; // initial buffer length
FillBuffer(&src, srcEnd - src);
// convert that buffer
bcr = mBufferLength;
bcw = destEnd - dest;
res = ConvertNoBuff(mBuffer, &bcr, dest, &bcw);
dest += bcw;
if ((res == NS_OK_UDEC_MOREINPUT) && (bcw == 0)) {
// not enough input to convert even a single char: repeat!
if (mBufferLength <= 32) DoubleBuffer();
else {
// somehow we got into an error state and the buffer is growing out of control
res = NS_ERROR_UNEXPECTED;
break;
}
} else {
if (bcr < buffLen) {
// we didn't convert that residual data - unfill the buffer
src -= mBufferLength - buffLen;
mBufferLength = buffLen;
} else {
// the buffer and some extra data was converted - unget the rest
src -= mBufferLength - bcr;
mBufferLength = 0;
}
break;
}
}
if (res == NS_OK) {
bcr = srcEnd - src;
bcw = destEnd - dest;
res = ConvertNoBuff(src, &bcr, dest, &bcw);
src += bcr;
dest += bcw;
// if we have partial input, store it in our internal buffer.
if (res == NS_OK_UDEC_MOREINPUT) {
bcr = srcEnd - src;
// make sure buffer is large enough
while (bcr > mBufferCapacity) {
if (mBufferLength <= 32) DoubleBuffer();
else {
// somehow we got into an error state and the buffer is growing out of control
res = NS_ERROR_UNEXPECTED;
break;
}
}
FillBuffer(&src, bcr);
}
}
*aSrcLength -= srcEnd - src;
*aDestLength -= destEnd - dest;
return res;
}
NS_IMETHODIMP nsBufferDecoderSupport::Reset()
{
mBufferLength = 0;
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [implementation]
nsTableDecoderSupport::nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable)
: nsBufferDecoderSupport()
{
mHelper = NULL;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsTableDecoderSupport::~nsTableDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [implementation]
NS_IMETHODIMP nsTableDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByTable(aSrc, aSrcLength, aDest, aDestLength,
mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsMultiTableDecoderSupport [implementation]
nsMultiTableDecoderSupport::nsMultiTableDecoderSupport(
PRInt32 aTableCount,
uRange * aRangeArray,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
: nsBufferDecoderSupport()
{
mHelper = NULL;
mTableCount = aTableCount;
mRangeArray = aRangeArray;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsMultiTableDecoderSupport::~nsMultiTableDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [implementation]
NS_IMETHODIMP nsMultiTableDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) &mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
mTableCount, mRangeArray, mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsOneByteDecoderSupport [implementation]
nsOneByteDecoderSupport::nsOneByteDecoderSupport(
uShiftTable * aShiftTable,
uMappingTable * aMappingTable)
: nsBasicDecoderSupport()
{
mHelper = NULL;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsOneByteDecoderSupport::~nsOneByteDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [implementation]
NS_IMETHODIMP nsOneByteDecoderSupport::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) &mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
res = mHelper -> CreateFastTable(mShiftTable, mMappingTable, mFastTable,
ONE_BYTE_TABLE_SIZE);
if (NS_FAILED(res)) return res;
}
res = mHelper->ConvertByFastTable(aSrc, aSrcLength, aDest, aDestLength,
mFastTable, ONE_BYTE_TABLE_SIZE);
return res;
}
NS_IMETHODIMP nsOneByteDecoderSupport::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// single byte to Unicode converter
*aDestLength = aSrcLength;
return NS_OK_UDEC_EXACTLENGTH;
}
NS_IMETHODIMP nsOneByteDecoderSupport::Reset()
{
// nothing to reset, no internal state in this case
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsEncoderSupport [implementation]
@ -309,11 +663,12 @@ NS_IMETHODIMP nsTableEncoderSupport::ConvertNoBuffNoErr(
}
//----------------------------------------------------------------------
// Class nsTablesEncoderSupport [implementation]
// Class nsMultiTableEncoderSupport [implementation]
nsTablesEncoderSupport::nsTablesEncoderSupport(PRInt32 aTableCount,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
nsMultiTableEncoderSupport::nsMultiTableEncoderSupport(
PRInt32 aTableCount,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
: nsEncoderSupport()
{
mHelper = NULL;
@ -322,7 +677,7 @@ nsTablesEncoderSupport::nsTablesEncoderSupport(PRInt32 aTableCount,
mMappingTable = aMappingTable;
}
nsTablesEncoderSupport::~nsTablesEncoderSupport()
nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport()
{
NS_IF_RELEASE(mHelper);
}
@ -330,11 +685,11 @@ nsTablesEncoderSupport::~nsTablesEncoderSupport()
//----------------------------------------------------------------------
// Subclassing of nsEncoderSupport class [implementation]
NS_IMETHODIMP nsTablesEncoderSupport::ConvertNoBuffNoErr(
const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength)
NS_IMETHODIMP nsMultiTableEncoderSupport::ConvertNoBuffNoErr(
const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength)
{
nsresult res;
@ -345,269 +700,7 @@ NS_IMETHODIMP nsTablesEncoderSupport::ConvertNoBuffNoErr(
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
}
res = mHelper->ConvertByTables(aSrc, aSrcLength, aDest, aDestLength,
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
mTableCount, mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsDecoderSupport [implementation]
nsDecoderSupport::nsDecoderSupport()
{
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
mBuffer = new char[mBufferCapacity];
Reset();
NS_INIT_REFCNT();
PR_AtomicIncrement(&g_InstanceCount);
}
nsDecoderSupport::~nsDecoderSupport()
{
delete [] mBuffer;
PR_AtomicDecrement(&g_InstanceCount);
}
void nsDecoderSupport::FillBuffer(const char ** aSrc, PRInt32 aSrcLength)
{
PRInt32 bcr = PR_MIN(mBufferCapacity - mBufferLength, aSrcLength);
memcpy(mBuffer + mBufferLength, *aSrc, bcr);
mBufferLength += bcr;
(*aSrc) += bcr;
}
void nsDecoderSupport::DoubleBuffer()
{
mBufferCapacity *= 2;
char * newBuffer = new char [mBufferCapacity];
if (mBufferLength > 0) memcpy(newBuffer, mBuffer, mBufferLength);
delete [] mBuffer;
mBuffer = newBuffer;
}
//----------------------------------------------------------------------
// Interface nsISupports [implementation]
NS_IMPL_ADDREF(nsDecoderSupport);
NS_IMPL_RELEASE(nsDecoderSupport);
nsresult nsDecoderSupport::QueryInterface(REFNSIID aIID,
void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kIUnicodeDecoderIID)) {
*aInstancePtr = (void*) ((nsIUnicodeDecoder*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
//----------------------------------------------------------------------
// Interface nsIUnicodeDecoder [implementation]
NS_IMETHODIMP nsDecoderSupport::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
// we do all operations using pointers internally
const char * src = aSrc;
const char * srcEnd = aSrc + *aSrcLength;
PRUnichar * dest = aDest;
PRUnichar * destEnd = aDest + *aDestLength;
PRInt32 bcr, bcw; // byte counts for read & write;
nsresult res = NS_OK;
// do we have some residual data from the last conversion?
if (mBufferLength > 0) if (dest == destEnd) {
res = NS_OK_UDEC_MOREOUTPUT;
} else for (;;) {
// we need new data to add to the buffer
if (src == srcEnd) {
res = NS_OK_UDEC_MOREINPUT;
break;
}
// fill that buffer
PRInt32 buffLen = mBufferLength; // initial buffer length
FillBuffer(&src, srcEnd - src);
// convert that buffer
bcr = mBufferLength;
bcw = destEnd - dest;
res = ConvertNoBuff(mBuffer, &bcr, dest, &bcw);
dest += bcw;
if ((res == NS_OK_UDEC_MOREINPUT) && (bcw == 0)) {
// not enough input to convert even a single char: repeat!
DoubleBuffer();
} else {
if (bcr < buffLen) {
// we didn't convert that residual data - unfill the buffer
src -= mBufferLength - buffLen;
mBufferLength = buffLen;
} else {
// the buffer and some extra data was converted - unget the rest
src -= mBufferLength - bcr;
mBufferLength = 0;
}
break;
}
}
if (res == NS_OK) {
bcr = srcEnd - src;
bcw = destEnd - dest;
res = ConvertNoBuff(src, &bcr, dest, &bcw);
src += bcr;
dest += bcw;
// if we have partial input, store it in our internal buffer.
if (res == NS_OK_UDEC_MOREINPUT) {
bcr = srcEnd - src;
// make sure buffer is large enough
while (bcr > mBufferCapacity) DoubleBuffer();
FillBuffer(&src, bcr);
}
}
*aSrcLength -= srcEnd - src;
*aDestLength -= destEnd - dest;
return res;
}
NS_IMETHODIMP nsDecoderSupport::Reset()
{
mBufferLength = 0;
return NS_OK;
}
NS_IMETHODIMP nsDecoderSupport::Convert(PRUnichar * aDest,
PRInt32 aDestOffset,
PRInt32 * aDestLength,
const char * aSrc,
PRInt32 aSrcOffset,
PRInt32 * aSrcLength)
{
// XXX deprecated
return Convert(aSrc + aSrcOffset, aSrcLength, aDest + aDestOffset,
aDestLength);
}
NS_IMETHODIMP nsDecoderSupport::Finish(PRUnichar * aDest, PRInt32 aDestOffset,
PRInt32 * aDestLength)
{
// XXX deprecated
return NS_OK;
}
NS_IMETHODIMP nsDecoderSupport::Length(const char * aSrc, PRInt32 aSrcOffset,
PRInt32 aSrcLength, PRInt32 * aDestLength)
{
// XXX deprecated
return GetMaxLength(aSrc + aSrcOffset, aSrcLength, aDestLength);
}
NS_IMETHODIMP nsDecoderSupport::SetInputErrorBehavior(PRInt32 aBehavior)
{
// XXX deprecated
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [implementation]
nsTableDecoderSupport::nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable)
: nsDecoderSupport()
{
mHelper = NULL;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsTableDecoderSupport::~nsTableDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [implementation]
NS_IMETHODIMP nsTableDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByTable(aSrc, aSrcLength, aDest, aDestLength,
mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsTablesDecoderSupport [implementation]
nsTablesDecoderSupport::nsTablesDecoderSupport(PRInt32 aTableCount,
uRange * aRangeArray,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
: nsDecoderSupport()
{
mHelper = NULL;
mTableCount = aTableCount;
mRangeArray = aRangeArray;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsTablesDecoderSupport::~nsTablesDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [implementation]
NS_IMETHODIMP nsTablesDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByTables(aSrc, aSrcLength, aDest, aDestLength,
mTableCount, mRangeArray, mShiftTable, mMappingTable);
return res;
}

Просмотреть файл

@ -25,11 +25,13 @@
#include "nsIUnicodeEncodeHelper.h"
#include "nsIUnicodeDecodeHelper.h"
#define ONE_BYTE_TABLE_SIZE 256
//----------------------------------------------------------------------
// Class nsEncoderSupport [declaration]
// Class nsBasicDecoderSupport [declaration]
/**
* Support class for the Unicode encoders.
* Support class for the Unicode decoders.
*
* The class source files for this class are in /ucvlatin/nsUCvLatinSupport.
* However, because these objects requires non-xpcom subclassing, local copies
@ -38,6 +40,224 @@
*
* This class implements:
* - nsISupports
* - nsIUnicodeDecoder
*
* @created 19/Apr/1999
* @author Catalin Rotaru [CATA]
*/
class nsBasicDecoderSupport : public nsIUnicodeDecoder
{
NS_DECL_ISUPPORTS
public:
/**
* Class constructor.
*/
nsBasicDecoderSupport();
/**
* Class destructor.
*/
virtual ~nsBasicDecoderSupport();
//--------------------------------------------------------------------
// Interface nsIUnicodeDecoder [declaration]
// XXX delete when interface change, this is already declared in the new one
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength) = 0;
// XXX deprecated methods - to go away when interface change.
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 SetInputErrorBehavior(PRInt32 aBehavior);
};
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [declaration]
/**
* Support class for the Unicode decoders.
*
* This class implements:
* - the buffer management
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsBufferDecoderSupport : public nsBasicDecoderSupport
{
protected:
/**
* Internal buffer for partial conversions.
*/
char * mBuffer;
PRInt32 mBufferCapacity;
PRInt32 mBufferLength;
/**
* Convert method but *without* the buffer management stuff.
*/
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
void FillBuffer(const char ** aSrc, PRInt32 aSrcLength);
void DoubleBuffer();
public:
/**
* Class constructor.
*/
nsBufferDecoderSupport();
/**
* Class destructor.
*/
virtual ~nsBufferDecoderSupport();
//--------------------------------------------------------------------
// Interface nsIUnicodeDecoder [declaration]
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD Reset();
};
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [declaration]
/**
* Support class for a single-table-driven Unicode decoder.
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTableDecoderSupport : public nsBufferDecoderSupport
{
public:
/**
* Class constructor.
*/
nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTableDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
uShiftTable * mShiftTable;
uMappingTable * mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsMultiTableDecoderSupport [declaration]
/**
* Support class for a multi-table-driven Unicode decoder.
*
* @created 24/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsMultiTableDecoderSupport : public nsBufferDecoderSupport
{
public:
/**
* Class constructor.
*/
nsMultiTableDecoderSupport(PRInt32 aTableCount, uRange * aRangeArray,
uShiftTable ** aShiftTable, uMappingTable ** aMappingTable);
/**
* Class destructor.
*/
virtual ~nsMultiTableDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
PRInt32 mTableCount;
uRange * mRangeArray;
uShiftTable ** mShiftTable;
uMappingTable ** mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [declaration]
/**
* Support class for a single-byte Unicode decoder.
*
* @created 19/Apr/1999
* @author Catalin Rotaru [CATA]
*/
class nsOneByteDecoderSupport : public nsBasicDecoderSupport
{
public:
/**
* Class constructor.
*/
nsOneByteDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
/**
* Class destructor.
*/
virtual ~nsOneByteDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
uShiftTable * mShiftTable;
uMappingTable * mMappingTable;
PRUnichar mFastTable[ONE_BYTE_TABLE_SIZE];
//--------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [declaration]
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
NS_IMETHOD Reset();
};
//----------------------------------------------------------------------
// Class nsEncoderSupport [declaration]
/**
* Support class for the Unicode encoders.
*
* This class implements:
* - nsISupports
* - the buffer management
* - error handling procedure(s)
*
@ -150,7 +370,7 @@ protected:
};
//----------------------------------------------------------------------
// Class nsTablesEncoderSupport [declaration]
// Class nsMultiTableEncoderSupport [declaration]
/**
* Support class for a multi-table-driven Unicode encoder.
@ -158,20 +378,20 @@ protected:
* @created 11/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTablesEncoderSupport : public nsEncoderSupport
class nsMultiTableEncoderSupport : public nsEncoderSupport
{
public:
/**
* Class constructor.
*/
nsTablesEncoderSupport(PRInt32 aTableCount, uShiftTable ** aShiftTable,
nsMultiTableEncoderSupport(PRInt32 aTableCount, uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTablesEncoderSupport();
virtual ~nsMultiTableEncoderSupport();
protected:
@ -187,147 +407,4 @@ protected:
char * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsDecoderSupport [declaration]
/**
* Support class for the Unicode decoders.
*
* This class implements:
* - nsISupports
* - the buffer management
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsDecoderSupport : public nsIUnicodeDecoder
{
NS_DECL_ISUPPORTS
protected:
/**
* Internal buffer for partial conversions.
*/
char * mBuffer;
PRInt32 mBufferCapacity;
PRInt32 mBufferLength;
/**
* Convert method but *without* the buffer management stuff.
*/
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
void FillBuffer(const char ** aSrc, PRInt32 aSrcLength);
void DoubleBuffer();
public:
/**
* Class constructor.
*/
nsDecoderSupport();
/**
* Class destructor.
*/
virtual ~nsDecoderSupport();
//--------------------------------------------------------------------
// Interface nsIUnicodeDecoder [declaration]
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength) = 0;
NS_IMETHOD Reset();
// XXX deprecated methods - to go away when interface change.
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 SetInputErrorBehavior(PRInt32 aBehavior);
};
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [declaration]
/**
* Support class for a single-table-driven Unicode decoder.
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTableDecoderSupport : public nsDecoderSupport
{
public:
/**
* Class constructor.
*/
nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTableDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
uShiftTable * mShiftTable;
uMappingTable * mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsTablesDecoderSupport [declaration]
/**
* Support class for a multi-table-driven Unicode decoder.
*
* @created 24/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTablesDecoderSupport : public nsDecoderSupport
{
public:
/**
* Class constructor.
*/
nsTablesDecoderSupport(PRInt32 aTableCount, uRange * aRangeArray,
uShiftTable ** aShiftTable, uMappingTable ** aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTablesDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
PRInt32 mTableCount;
uRange * mRangeArray;
uShiftTable ** mShiftTable;
uMappingTable ** mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
#endif /* nsUCvJa2Support_h___ */

Просмотреть файл

@ -56,7 +56,7 @@ static PRUint16 *gMappingTables[4] = {
// Class nsUnicodeToEUCJP [implementation]
nsUnicodeToEUCJP::nsUnicodeToEUCJP()
: nsTablesEncoderSupport(4,
: nsMultiTableEncoderSupport(4,
(uShiftTable**) gShiftTables,
(uMappingTable**) gMappingTables)
{

Просмотреть файл

@ -1,57 +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.
*/
#ifndef nsUnicodeToEUCJP_h___
#define nsUnicodeToEUCJP_h___
#include "nsUCvJa2Support.h"
//----------------------------------------------------------------------
// Class nsUnicodeToEUCJP [declaration]
/**
* A character set converter from Unicode to EUCJP.
*
* @created 17/Feb/1999
* @author Catalin Rotaru [CATA]
*/
class nsUnicodeToEUCJP : public nsTablesEncoderSupport
{
public:
/**
* Class constructor.
*/
nsUnicodeToEUCJP();
/**
* Static class constructor.
*/
static nsresult CreateInstance(nsISupports **aResult);
protected:
//--------------------------------------------------------------------
// Subclassing of nsEncoderSupport class [declaration]
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
};
#endif /* nsUnicodeToEUCJP_h___ */

Просмотреть файл

@ -1,59 +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 "nsLatin1ToUnicode.h"
//----------------------------------------------------------------------
// Global functions and data [declaration]
static PRUint16 g_Latin1MappingTable[] = {
#include "cp1252.ut"
};
static PRInt16 g_Latin1ShiftTable[] = {
1, u1ByteCharset ,
ShiftCell(0,0,0,0,0,0,0,0)
};
//----------------------------------------------------------------------
// Class nsLatin1ToUnicode [implementation]
nsLatin1ToUnicode::nsLatin1ToUnicode()
: nsTableDecoderSupport((uShiftTable*) &g_Latin1ShiftTable,
(uMappingTable*) &g_Latin1MappingTable)
{
}
nsresult nsLatin1ToUnicode::CreateInstance(nsISupports ** aResult)
{
*aResult = new nsLatin1ToUnicode();
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
//----------------------------------------------------------------------
// Subclassing of nsTableDecoderSupport class [implementation]
NS_IMETHODIMP nsLatin1ToUnicode::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// we are a single byte to Unicode converter, so...
*aDestLength = aSrcLength;
return NS_OK_UDEC_EXACTLENGTH;
}

Просмотреть файл

@ -1,57 +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.
*/
#ifndef nsLatin1ToUnicode_h___
#define nsLatin1ToUnicode_h___
#include "nsUCvLatinSupport.h"
//----------------------------------------------------------------------
// Class nsLatin1ToUnicode [declaration]
/**
* A character set converter from Latin1 to Unicode.
*
* @created 23/Nov/1998
* @author Catalin Rotaru [CATA]
*/
class nsLatin1ToUnicode : public nsTableDecoderSupport
{
public:
/**
* Class constructor.
*/
nsLatin1ToUnicode();
/**
* Static class constructor.
*/
static nsresult CreateInstance(nsISupports **aResult);
protected:
//--------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [declaration]
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
};
#endif /* nsLatin1ToUnicode_h___ */

Просмотреть файл

@ -24,6 +24,360 @@
#define DEFAULT_BUFFER_CAPACITY 16
// XXX review the buffer growth limitation code
//----------------------------------------------------------------------
// Class nsBasicDecoderSupport [implementation]
nsBasicDecoderSupport::nsBasicDecoderSupport()
{
NS_INIT_REFCNT();
PR_AtomicIncrement(&g_InstanceCount);
}
nsBasicDecoderSupport::~nsBasicDecoderSupport()
{
PR_AtomicDecrement(&g_InstanceCount);
}
//----------------------------------------------------------------------
// Interface nsISupports [implementation]
NS_IMPL_ADDREF(nsBasicDecoderSupport);
NS_IMPL_RELEASE(nsBasicDecoderSupport);
nsresult nsBasicDecoderSupport::QueryInterface(REFNSIID aIID,
void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kIUnicodeDecoderIID)) {
*aInstancePtr = (void*) ((nsIUnicodeDecoder*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
//----------------------------------------------------------------------
// Interface nsIUnicodeDecoder [implementation]
NS_IMETHODIMP nsBasicDecoderSupport::Convert(PRUnichar * aDest,
PRInt32 aDestOffset,
PRInt32 * aDestLength,
const char * aSrc,
PRInt32 aSrcOffset,
PRInt32 * aSrcLength)
{
// XXX deprecated
return Convert(aSrc + aSrcOffset, aSrcLength, aDest + aDestOffset,
aDestLength);
}
NS_IMETHODIMP nsBasicDecoderSupport::Finish(PRUnichar * aDest,
PRInt32 aDestOffset,
PRInt32 * aDestLength)
{
// XXX deprecated
return NS_OK;
}
NS_IMETHODIMP nsBasicDecoderSupport::Length(const char * aSrc,
PRInt32 aSrcOffset,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// XXX deprecated
return GetMaxLength(aSrc + aSrcOffset, aSrcLength, aDestLength);
}
NS_IMETHODIMP nsBasicDecoderSupport::SetInputErrorBehavior(PRInt32 aBehavior)
{
// XXX deprecated
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [implementation]
nsBufferDecoderSupport::nsBufferDecoderSupport()
: nsBasicDecoderSupport()
{
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
mBuffer = new char[mBufferCapacity];
Reset();
}
nsBufferDecoderSupport::~nsBufferDecoderSupport()
{
delete [] mBuffer;
}
void nsBufferDecoderSupport::FillBuffer(const char ** aSrc, PRInt32 aSrcLength)
{
PRInt32 bcr = PR_MIN(mBufferCapacity - mBufferLength, aSrcLength);
memcpy(mBuffer + mBufferLength, *aSrc, bcr);
mBufferLength += bcr;
(*aSrc) += bcr;
}
void nsBufferDecoderSupport::DoubleBuffer()
{
mBufferCapacity *= 2;
char * newBuffer = new char [mBufferCapacity];
if (mBufferLength > 0) memcpy(newBuffer, mBuffer, mBufferLength);
delete [] mBuffer;
mBuffer = newBuffer;
}
//----------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [implementation]
NS_IMETHODIMP nsBufferDecoderSupport::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
// we do all operations using pointers internally
const char * src = aSrc;
const char * srcEnd = aSrc + *aSrcLength;
PRUnichar * dest = aDest;
PRUnichar * destEnd = aDest + *aDestLength;
PRInt32 bcr, bcw; // byte counts for read & write;
nsresult res = NS_OK;
// do we have some residual data from the last conversion?
if (mBufferLength > 0) if (dest == destEnd) {
res = NS_OK_UDEC_MOREOUTPUT;
} else for (;;) {
// we need new data to add to the buffer
if (src == srcEnd) {
res = NS_OK_UDEC_MOREINPUT;
break;
}
// fill that buffer
PRInt32 buffLen = mBufferLength; // initial buffer length
FillBuffer(&src, srcEnd - src);
// convert that buffer
bcr = mBufferLength;
bcw = destEnd - dest;
res = ConvertNoBuff(mBuffer, &bcr, dest, &bcw);
dest += bcw;
if ((res == NS_OK_UDEC_MOREINPUT) && (bcw == 0)) {
// not enough input to convert even a single char: repeat!
if (mBufferLength <= 32) DoubleBuffer();
else {
// somehow we got into an error state and the buffer is growing out of control
res = NS_ERROR_UNEXPECTED;
break;
}
} else {
if (bcr < buffLen) {
// we didn't convert that residual data - unfill the buffer
src -= mBufferLength - buffLen;
mBufferLength = buffLen;
} else {
// the buffer and some extra data was converted - unget the rest
src -= mBufferLength - bcr;
mBufferLength = 0;
}
break;
}
}
if (res == NS_OK) {
bcr = srcEnd - src;
bcw = destEnd - dest;
res = ConvertNoBuff(src, &bcr, dest, &bcw);
src += bcr;
dest += bcw;
// if we have partial input, store it in our internal buffer.
if (res == NS_OK_UDEC_MOREINPUT) {
bcr = srcEnd - src;
// make sure buffer is large enough
while (bcr > mBufferCapacity) {
if (mBufferLength <= 32) DoubleBuffer();
else {
// somehow we got into an error state and the buffer is growing out of control
res = NS_ERROR_UNEXPECTED;
break;
}
}
FillBuffer(&src, bcr);
}
}
*aSrcLength -= srcEnd - src;
*aDestLength -= destEnd - dest;
return res;
}
NS_IMETHODIMP nsBufferDecoderSupport::Reset()
{
mBufferLength = 0;
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [implementation]
nsTableDecoderSupport::nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable)
: nsBufferDecoderSupport()
{
mHelper = NULL;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsTableDecoderSupport::~nsTableDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [implementation]
NS_IMETHODIMP nsTableDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByTable(aSrc, aSrcLength, aDest, aDestLength,
mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsMultiTableDecoderSupport [implementation]
nsMultiTableDecoderSupport::nsMultiTableDecoderSupport(
PRInt32 aTableCount,
uRange * aRangeArray,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
: nsBufferDecoderSupport()
{
mHelper = NULL;
mTableCount = aTableCount;
mRangeArray = aRangeArray;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsMultiTableDecoderSupport::~nsMultiTableDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [implementation]
NS_IMETHODIMP nsMultiTableDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) &mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
mTableCount, mRangeArray, mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsOneByteDecoderSupport [implementation]
nsOneByteDecoderSupport::nsOneByteDecoderSupport(
uShiftTable * aShiftTable,
uMappingTable * aMappingTable)
: nsBasicDecoderSupport()
{
mHelper = NULL;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsOneByteDecoderSupport::~nsOneByteDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [implementation]
NS_IMETHODIMP nsOneByteDecoderSupport::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) &mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
res = mHelper -> CreateFastTable(mShiftTable, mMappingTable, mFastTable,
ONE_BYTE_TABLE_SIZE);
if (NS_FAILED(res)) return res;
}
res = mHelper->ConvertByFastTable(aSrc, aSrcLength, aDest, aDestLength,
mFastTable, ONE_BYTE_TABLE_SIZE);
return res;
}
NS_IMETHODIMP nsOneByteDecoderSupport::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// single byte to Unicode converter
*aDestLength = aSrcLength;
return NS_OK_UDEC_EXACTLENGTH;
}
NS_IMETHODIMP nsOneByteDecoderSupport::Reset()
{
// nothing to reset, no internal state in this case
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsEncoderSupport [implementation]
@ -309,11 +663,12 @@ NS_IMETHODIMP nsTableEncoderSupport::ConvertNoBuffNoErr(
}
//----------------------------------------------------------------------
// Class nsTablesEncoderSupport [implementation]
// Class nsMultiTableEncoderSupport [implementation]
nsTablesEncoderSupport::nsTablesEncoderSupport(PRInt32 aTableCount,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
nsMultiTableEncoderSupport::nsMultiTableEncoderSupport(
PRInt32 aTableCount,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
: nsEncoderSupport()
{
mHelper = NULL;
@ -322,7 +677,7 @@ nsTablesEncoderSupport::nsTablesEncoderSupport(PRInt32 aTableCount,
mMappingTable = aMappingTable;
}
nsTablesEncoderSupport::~nsTablesEncoderSupport()
nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport()
{
NS_IF_RELEASE(mHelper);
}
@ -330,11 +685,11 @@ nsTablesEncoderSupport::~nsTablesEncoderSupport()
//----------------------------------------------------------------------
// Subclassing of nsEncoderSupport class [implementation]
NS_IMETHODIMP nsTablesEncoderSupport::ConvertNoBuffNoErr(
const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength)
NS_IMETHODIMP nsMultiTableEncoderSupport::ConvertNoBuffNoErr(
const PRUnichar * aSrc,
PRInt32 * aSrcLength,
char * aDest,
PRInt32 * aDestLength)
{
nsresult res;
@ -345,282 +700,7 @@ NS_IMETHODIMP nsTablesEncoderSupport::ConvertNoBuffNoErr(
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
}
res = mHelper->ConvertByTables(aSrc, aSrcLength, aDest, aDestLength,
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
mTableCount, mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsDecoderSupport [implementation]
nsDecoderSupport::nsDecoderSupport()
{
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
mBuffer = new char[mBufferCapacity];
Reset();
NS_INIT_REFCNT();
PR_AtomicIncrement(&g_InstanceCount);
}
nsDecoderSupport::~nsDecoderSupport()
{
delete [] mBuffer;
PR_AtomicDecrement(&g_InstanceCount);
}
void nsDecoderSupport::FillBuffer(const char ** aSrc, PRInt32 aSrcLength)
{
PRInt32 bcr = PR_MIN(mBufferCapacity - mBufferLength, aSrcLength);
memcpy(mBuffer + mBufferLength, *aSrc, bcr);
mBufferLength += bcr;
(*aSrc) += bcr;
}
void nsDecoderSupport::DoubleBuffer()
{
mBufferCapacity *= 2;
char * newBuffer = new char [mBufferCapacity];
if (mBufferLength > 0) memcpy(newBuffer, mBuffer, mBufferLength);
delete [] mBuffer;
mBuffer = newBuffer;
}
//----------------------------------------------------------------------
// Interface nsISupports [implementation]
NS_IMPL_ADDREF(nsDecoderSupport);
NS_IMPL_RELEASE(nsDecoderSupport);
nsresult nsDecoderSupport::QueryInterface(REFNSIID aIID,
void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kIUnicodeDecoderIID)) {
*aInstancePtr = (void*) ((nsIUnicodeDecoder*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
//----------------------------------------------------------------------
// Interface nsIUnicodeDecoder [implementation]
NS_IMETHODIMP nsDecoderSupport::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
// we do all operations using pointers internally
const char * src = aSrc;
const char * srcEnd = aSrc + *aSrcLength;
PRUnichar * dest = aDest;
PRUnichar * destEnd = aDest + *aDestLength;
PRInt32 bcr, bcw; // byte counts for read & write;
nsresult res = NS_OK;
// do we have some residual data from the last conversion?
if (mBufferLength > 0) if (dest == destEnd) {
res = NS_OK_UDEC_MOREOUTPUT;
} else for (;;) {
// we need new data to add to the buffer
if (src == srcEnd) {
res = NS_OK_UDEC_MOREINPUT;
break;
}
// fill that buffer
PRInt32 buffLen = mBufferLength; // initial buffer length
FillBuffer(&src, srcEnd - src);
// convert that buffer
bcr = mBufferLength;
bcw = destEnd - dest;
res = ConvertNoBuff(mBuffer, &bcr, dest, &bcw);
dest += bcw;
if ((res == NS_OK_UDEC_MOREINPUT) && (bcw == 0)) {
// not enough input to convert even a single char: repeat!
if (mBufferLength <= 32) DoubleBuffer();
else {
// somehow we got into an error state and the buffer is growing out of control
res = NS_ERROR_UNEXPECTED;
break;
}
} else {
if (bcr < buffLen) {
// we didn't convert that residual data - unfill the buffer
src -= mBufferLength - buffLen;
mBufferLength = buffLen;
} else {
// the buffer and some extra data was converted - unget the rest
src -= mBufferLength - bcr;
mBufferLength = 0;
}
break;
}
}
if (res == NS_OK) {
bcr = srcEnd - src;
bcw = destEnd - dest;
res = ConvertNoBuff(src, &bcr, dest, &bcw);
src += bcr;
dest += bcw;
// if we have partial input, store it in our internal buffer.
if (res == NS_OK_UDEC_MOREINPUT) {
bcr = srcEnd - src;
// make sure buffer is large enough
while (bcr > mBufferCapacity) {
if (mBufferLength <= 32) DoubleBuffer();
else {
// somehow we got into an error state and the buffer is growing out of control
res = NS_ERROR_UNEXPECTED;
break;
}
}
FillBuffer(&src, bcr);
}
}
*aSrcLength -= srcEnd - src;
*aDestLength -= destEnd - dest;
return res;
}
NS_IMETHODIMP nsDecoderSupport::Reset()
{
mBufferLength = 0;
return NS_OK;
}
NS_IMETHODIMP nsDecoderSupport::Convert(PRUnichar * aDest,
PRInt32 aDestOffset,
PRInt32 * aDestLength,
const char * aSrc,
PRInt32 aSrcOffset,
PRInt32 * aSrcLength)
{
// XXX deprecated
return Convert(aSrc + aSrcOffset, aSrcLength, aDest + aDestOffset,
aDestLength);
}
NS_IMETHODIMP nsDecoderSupport::Finish(PRUnichar * aDest, PRInt32 aDestOffset,
PRInt32 * aDestLength)
{
// XXX deprecated
return NS_OK;
}
NS_IMETHODIMP nsDecoderSupport::Length(const char * aSrc, PRInt32 aSrcOffset,
PRInt32 aSrcLength, PRInt32 * aDestLength)
{
// XXX deprecated
return GetMaxLength(aSrc + aSrcOffset, aSrcLength, aDestLength);
}
NS_IMETHODIMP nsDecoderSupport::SetInputErrorBehavior(PRInt32 aBehavior)
{
// XXX deprecated
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [implementation]
nsTableDecoderSupport::nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable)
: nsDecoderSupport()
{
mHelper = NULL;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsTableDecoderSupport::~nsTableDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [implementation]
NS_IMETHODIMP nsTableDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByTable(aSrc, aSrcLength, aDest, aDestLength,
mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsTablesDecoderSupport [implementation]
nsTablesDecoderSupport::nsTablesDecoderSupport(PRInt32 aTableCount,
uRange * aRangeArray,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
: nsDecoderSupport()
{
mHelper = NULL;
mTableCount = aTableCount;
mRangeArray = aRangeArray;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsTablesDecoderSupport::~nsTablesDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [implementation]
NS_IMETHODIMP nsTablesDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByTables(aSrc, aSrcLength, aDest, aDestLength,
mTableCount, mRangeArray, mShiftTable, mMappingTable);
return res;
}

Просмотреть файл

@ -25,11 +25,13 @@
#include "nsIUnicodeEncodeHelper.h"
#include "nsIUnicodeDecodeHelper.h"
#define ONE_BYTE_TABLE_SIZE 256
//----------------------------------------------------------------------
// Class nsEncoderSupport [declaration]
// Class nsBasicDecoderSupport [declaration]
/**
* Support class for the Unicode encoders.
* Support class for the Unicode decoders.
*
* The class source files for this class are in /ucvlatin/nsUCvLatinSupport.
* However, because these objects requires non-xpcom subclassing, local copies
@ -38,6 +40,224 @@
*
* This class implements:
* - nsISupports
* - nsIUnicodeDecoder
*
* @created 19/Apr/1999
* @author Catalin Rotaru [CATA]
*/
class nsBasicDecoderSupport : public nsIUnicodeDecoder
{
NS_DECL_ISUPPORTS
public:
/**
* Class constructor.
*/
nsBasicDecoderSupport();
/**
* Class destructor.
*/
virtual ~nsBasicDecoderSupport();
//--------------------------------------------------------------------
// Interface nsIUnicodeDecoder [declaration]
// XXX delete when interface change, this is already declared in the new one
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength) = 0;
// XXX deprecated methods - to go away when interface change.
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 SetInputErrorBehavior(PRInt32 aBehavior);
};
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [declaration]
/**
* Support class for the Unicode decoders.
*
* This class implements:
* - the buffer management
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsBufferDecoderSupport : public nsBasicDecoderSupport
{
protected:
/**
* Internal buffer for partial conversions.
*/
char * mBuffer;
PRInt32 mBufferCapacity;
PRInt32 mBufferLength;
/**
* Convert method but *without* the buffer management stuff.
*/
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
void FillBuffer(const char ** aSrc, PRInt32 aSrcLength);
void DoubleBuffer();
public:
/**
* Class constructor.
*/
nsBufferDecoderSupport();
/**
* Class destructor.
*/
virtual ~nsBufferDecoderSupport();
//--------------------------------------------------------------------
// Interface nsIUnicodeDecoder [declaration]
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD Reset();
};
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [declaration]
/**
* Support class for a single-table-driven Unicode decoder.
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTableDecoderSupport : public nsBufferDecoderSupport
{
public:
/**
* Class constructor.
*/
nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTableDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
uShiftTable * mShiftTable;
uMappingTable * mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsMultiTableDecoderSupport [declaration]
/**
* Support class for a multi-table-driven Unicode decoder.
*
* @created 24/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsMultiTableDecoderSupport : public nsBufferDecoderSupport
{
public:
/**
* Class constructor.
*/
nsMultiTableDecoderSupport(PRInt32 aTableCount, uRange * aRangeArray,
uShiftTable ** aShiftTable, uMappingTable ** aMappingTable);
/**
* Class destructor.
*/
virtual ~nsMultiTableDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
PRInt32 mTableCount;
uRange * mRangeArray;
uShiftTable ** mShiftTable;
uMappingTable ** mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [declaration]
/**
* Support class for a single-byte Unicode decoder.
*
* @created 19/Apr/1999
* @author Catalin Rotaru [CATA]
*/
class nsOneByteDecoderSupport : public nsBasicDecoderSupport
{
public:
/**
* Class constructor.
*/
nsOneByteDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
/**
* Class destructor.
*/
virtual ~nsOneByteDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
uShiftTable * mShiftTable;
uMappingTable * mMappingTable;
PRUnichar mFastTable[ONE_BYTE_TABLE_SIZE];
//--------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [declaration]
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
NS_IMETHOD Reset();
};
//----------------------------------------------------------------------
// Class nsEncoderSupport [declaration]
/**
* Support class for the Unicode encoders.
*
* This class implements:
* - nsISupports
* - the buffer management
* - error handling procedure(s)
*
@ -150,7 +370,7 @@ protected:
};
//----------------------------------------------------------------------
// Class nsTablesEncoderSupport [declaration]
// Class nsMultiTableEncoderSupport [declaration]
/**
* Support class for a multi-table-driven Unicode encoder.
@ -158,20 +378,20 @@ protected:
* @created 11/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTablesEncoderSupport : public nsEncoderSupport
class nsMultiTableEncoderSupport : public nsEncoderSupport
{
public:
/**
* Class constructor.
*/
nsTablesEncoderSupport(PRInt32 aTableCount, uShiftTable ** aShiftTable,
nsMultiTableEncoderSupport(PRInt32 aTableCount, uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTablesEncoderSupport();
virtual ~nsMultiTableEncoderSupport();
protected:
@ -187,147 +407,4 @@ protected:
char * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsDecoderSupport [declaration]
/**
* Support class for the Unicode decoders.
*
* This class implements:
* - nsISupports
* - the buffer management
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsDecoderSupport : public nsIUnicodeDecoder
{
NS_DECL_ISUPPORTS
protected:
/**
* Internal buffer for partial conversions.
*/
char * mBuffer;
PRInt32 mBufferCapacity;
PRInt32 mBufferLength;
/**
* Convert method but *without* the buffer management stuff.
*/
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
void FillBuffer(const char ** aSrc, PRInt32 aSrcLength);
void DoubleBuffer();
public:
/**
* Class constructor.
*/
nsDecoderSupport();
/**
* Class destructor.
*/
virtual ~nsDecoderSupport();
//--------------------------------------------------------------------
// Interface nsIUnicodeDecoder [declaration]
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength) = 0;
NS_IMETHOD Reset();
// XXX deprecated methods - to go away when interface change.
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 SetInputErrorBehavior(PRInt32 aBehavior);
};
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [declaration]
/**
* Support class for a single-table-driven Unicode decoder.
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTableDecoderSupport : public nsDecoderSupport
{
public:
/**
* Class constructor.
*/
nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTableDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
uShiftTable * mShiftTable;
uMappingTable * mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsTablesDecoderSupport [declaration]
/**
* Support class for a multi-table-driven Unicode decoder.
*
* @created 24/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTablesDecoderSupport : public nsDecoderSupport
{
public:
/**
* Class constructor.
*/
nsTablesDecoderSupport(PRInt32 aTableCount, uRange * aRangeArray,
uShiftTable ** aShiftTable, uMappingTable ** aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTablesDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
PRInt32 mTableCount;
uRange * mRangeArray;
uShiftTable ** mShiftTable;
uMappingTable ** mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
#endif /* nsUCvLatinSupport_h___ */