Support class for fast table decoder added.
This commit is contained in:
Родитель
c6aeb132c1
Коммит
31f1ddea8b
|
@ -1,84 +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 "nsBIG5ToUnicode.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
static PRUint16 g_BIG5MappingTable[] = {
|
||||
#include "big5.ut"
|
||||
};
|
||||
static PRUint16 g_ASCIIMappingTable[] = {
|
||||
0x0001, 0x0004, 0x0005, 0x0008, 0x0000, 0x0000, 0x007F, 0x0000
|
||||
};
|
||||
|
||||
static PRInt16 g_BIG5ShiftTable[] = {
|
||||
0, u2BytesCharset,
|
||||
ShiftCell(0,0,0,0,0,0,0,0)
|
||||
};
|
||||
|
||||
static PRInt16 g_ASCIIShiftTable[] = {
|
||||
0, u1ByteCharset,
|
||||
ShiftCell(0,0,0,0,0,0,0,0)
|
||||
};
|
||||
|
||||
static PRInt16 *g_BIG5ShiftTableSet [] = {
|
||||
g_ASCIIShiftTable,
|
||||
g_BIG5ShiftTable
|
||||
};
|
||||
|
||||
static PRUint16 *g_BIG5MappingTableSet [] ={
|
||||
g_ASCIIMappingTable,
|
||||
g_BIG5MappingTable
|
||||
};
|
||||
|
||||
static uRange g_BIG5Ranges[] = {
|
||||
{ 0x00, 0x7E },
|
||||
{ 0x81, 0xFC }
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsBIG5ToUnicode [implementation]
|
||||
|
||||
nsBIG5ToUnicode::nsBIG5ToUnicode()
|
||||
: nsTablesDecoderSupport(2,
|
||||
(uRange* ) &g_BIG5Ranges,
|
||||
(uShiftTable**) &g_BIG5ShiftTableSet,
|
||||
(uMappingTable**) &g_BIG5MappingTableSet)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsBIG5ToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsBIG5ToUnicode();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTablesDecoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsBIG5ToUnicode::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 nsBIG5ToUnicode_h___
|
||||
#define nsBIG5ToUnicode_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsBIG5ToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from BIG5 to Unicode.
|
||||
*
|
||||
* @created 06/Apr/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsBIG5ToUnicode : public nsTablesDecoderSupport
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsBIG5ToUnicode();
|
||||
|
||||
/**
|
||||
* 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 /* nsBIG5ToUnicode_h___ */
|
|
@ -1,104 +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 "nsEUCKRToUnicode.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
static PRUint16 g_ASCIIMappingTable[] = {
|
||||
0x0001, 0x0004, 0x0005, 0x0008, 0x0000, 0x0000, 0x007F, 0x0000
|
||||
};
|
||||
|
||||
static PRInt16 g_ASCIIShiftTable[] = {
|
||||
0, u1ByteCharset,
|
||||
ShiftCell(0,0,0,0,0,0,0,0)
|
||||
};
|
||||
|
||||
#ifdef MS_EUCKR
|
||||
static PRUint16 g_EUCKRMappingTable[] = {
|
||||
#include "u20ksc.ut"
|
||||
};
|
||||
|
||||
static PRInt16 g_EUCKRShiftTable[] = {
|
||||
0, u2BytesCharset,
|
||||
ShiftCell(0, 0, 0, 0, 0, 0, 0, 0)
|
||||
};
|
||||
|
||||
static uRange g_EUCKRRanges[] = {
|
||||
{ 0x00, 0x7E },
|
||||
{ 0x81, 0xFE }
|
||||
};
|
||||
#else
|
||||
|
||||
static PRUint16 g_EUCKRMappingTable[] = {
|
||||
#include "u20kscgl.ut"
|
||||
};
|
||||
|
||||
static PRInt16 g_EUCKRShiftTable[] = {
|
||||
0, u2BytesGRCharset,
|
||||
ShiftCell(0, 0, 0, 0, 0, 0, 0, 0)
|
||||
};
|
||||
|
||||
static uRange g_EUCKRRanges[] = {
|
||||
{ 0x00, 0x7E },
|
||||
{ 0xA1, 0xFE }
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
static PRInt16 *g_EUCKRShiftTableSet [] = {
|
||||
g_ASCIIShiftTable,
|
||||
g_EUCKRShiftTable
|
||||
};
|
||||
|
||||
static PRUint16 *g_EUCKRMappingTableSet [] ={
|
||||
g_ASCIIMappingTable,
|
||||
g_EUCKRMappingTable
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEUCKRToUnicode [implementation]
|
||||
|
||||
nsEUCKRToUnicode::nsEUCKRToUnicode()
|
||||
: nsTablesDecoderSupport(2,
|
||||
(uRange*) &g_EUCKRRanges,
|
||||
(uShiftTable**) &g_EUCKRShiftTableSet,
|
||||
(uMappingTable**) &g_EUCKRMappingTableSet)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsEUCKRToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsEUCKRToUnicode();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTablesDecoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsEUCKRToUnicode::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 nsEUCKRToUnicode_h___
|
||||
#define nsEUCKRToUnicode_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEUCKRToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from EUCKR to Unicode.
|
||||
*
|
||||
* @created 06/Apr/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsEUCKRToUnicode : public nsTablesDecoderSupport
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsEUCKRToUnicode();
|
||||
|
||||
/**
|
||||
* 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 /* nsEUCKRToUnicode_h___ */
|
|
@ -1,100 +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 "nsEUCTWToUnicode.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
static PRUint16 g_ASCIIMappingTable[] = {
|
||||
0x0001, 0x0004, 0x0005, 0x0008, 0x0000, 0x0000, 0x007F, 0x0000
|
||||
};
|
||||
|
||||
static PRUint16 g_CNS1MappingTable[] = {
|
||||
#include "cns_1.ut"
|
||||
};
|
||||
|
||||
static PRUint16 g_CNS2MappingTable[] = {
|
||||
#include "cns_2.ut"
|
||||
};
|
||||
|
||||
static PRInt16 g_ASCIIShiftTable[] = {
|
||||
0, u1ByteCharset,
|
||||
ShiftCell(0,0,0,0,0,0,0,0)
|
||||
};
|
||||
|
||||
static PRInt16 g_CNS1ShiftTable[] = {
|
||||
0, u2BytesGRCharset,
|
||||
ShiftCell(0, 0, 0, 0, 0, 0, 0, 0),
|
||||
};
|
||||
|
||||
|
||||
static PRInt16 g_CNS2ShiftTable[] = {
|
||||
0, u2BytesGRPrefix8EA2Charset,
|
||||
ShiftCell(0, 0, 0, 0, 0, 0, 0, 0),
|
||||
};
|
||||
|
||||
|
||||
static PRInt16 *g_EUCTWShiftTableSet [] = {
|
||||
g_ASCIIShiftTable,
|
||||
g_CNS1ShiftTable,
|
||||
g_CNS2ShiftTable
|
||||
};
|
||||
|
||||
static PRUint16 *g_EUCTWMappingTableSet [] ={
|
||||
g_ASCIIMappingTable,
|
||||
g_CNS1MappingTable,
|
||||
g_CNS2MappingTable
|
||||
};
|
||||
|
||||
static uRange g_EUCTWRanges[] = {
|
||||
{ 0x00, 0x7E },
|
||||
{ 0xA1, 0xFE },
|
||||
{ 0x8E, 0x8E }
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEUCTWToUnicode [implementation]
|
||||
|
||||
nsEUCTWToUnicode::nsEUCTWToUnicode()
|
||||
: nsTablesDecoderSupport(3,
|
||||
(uRange*) &g_EUCTWRanges,
|
||||
(uShiftTable**) &g_EUCTWShiftTableSet,
|
||||
(uMappingTable**) &g_EUCTWMappingTableSet)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsEUCTWToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsEUCTWToUnicode();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTablesDecoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsEUCTWToUnicode::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 nsEUCTWToUnicode_h___
|
||||
#define nsEUCTWToUnicode_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEUCTWToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from EUCTW to Unicode.
|
||||
*
|
||||
* @created 06/Apr/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsEUCTWToUnicode : public nsTablesDecoderSupport
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsEUCTWToUnicode();
|
||||
|
||||
/**
|
||||
* 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 /* nsEUCTWToUnicode_h___ */
|
|
@ -62,7 +62,7 @@ static uRange g_GB2312Ranges[] = {
|
|||
// Class nsGB2312ToUnicode [implementation]
|
||||
|
||||
nsGB2312ToUnicode::nsGB2312ToUnicode()
|
||||
: nsTablesDecoderSupport(2,
|
||||
: nsMultiTableDecoderSupport(2,
|
||||
(uRange *) &g_GB2312Ranges,
|
||||
(uShiftTable**) &g_GB2312ShiftTableSet,
|
||||
(uMappingTable**) &g_GB2312MappingTableSet)
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* @created 06/Apr/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsGB2312ToUnicode : public nsTablesDecoderSupport
|
||||
class nsGB2312ToUnicode : public nsMultiTableDecoderSupport
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
|
@ -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 /* nsUCvCnSupport_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 /* nsUCvJaSupport_h___ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче