mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Support classes used.
This commit is contained in:
parent
b17d3addb0
commit
94d06b784d
@ -17,34 +17,27 @@
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsCP1253ToUnicode.h"
|
||||
#include "nsUCvLatinDll.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
static PRUint16 gMappingTable[] = {
|
||||
static PRUint16 g_CP1253MappingTable[] = {
|
||||
#include "cp1253.ut"
|
||||
};
|
||||
|
||||
static PRBool gFastTableInit = PR_FALSE;
|
||||
static PRUnichar gFastTable[256];
|
||||
static PRInt16 g_CP1253ShiftTable[] = {
|
||||
1, u1ByteCharset ,
|
||||
ShiftCell(0,0,0,0,0,0,0,0)
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP1253ToUnicode [implementation]
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCP1253ToUnicode, kIUnicodeDecoderIID);
|
||||
|
||||
nsCP1253ToUnicode::nsCP1253ToUnicode()
|
||||
: nsTableDecoderSupport((uShiftTable*) &g_CP1253ShiftTable,
|
||||
(uMappingTable*) &g_CP1253MappingTable)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsCP1253ToUnicode::~nsCP1253ToUnicode()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsresult nsCP1253ToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
@ -53,22 +46,14 @@ nsresult nsCP1253ToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
uMappingTable* nsCP1253ToUnicode::GetMappingTable()
|
||||
{
|
||||
return (uMappingTable*) &gMappingTable;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableDecoderSupport class [implementation]
|
||||
|
||||
PRUnichar * nsCP1253ToUnicode::GetFastTable()
|
||||
NS_IMETHODIMP nsCP1253ToUnicode::GetMaxLength(const char * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
return gFastTable;
|
||||
}
|
||||
|
||||
PRBool nsCP1253ToUnicode::GetFastTableInitState()
|
||||
{
|
||||
return gFastTableInit;
|
||||
}
|
||||
|
||||
void nsCP1253ToUnicode::SetFastTableInit()
|
||||
{
|
||||
gFastTableInit = PR_TRUE;
|
||||
// we are a single byte to Unicode converter, so...
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UDEC_EXACTLENGTH;
|
||||
}
|
||||
|
@ -20,15 +20,19 @@
|
||||
#ifndef nsCP1253ToUnicode_h___
|
||||
#define nsCP1253ToUnicode_h___
|
||||
|
||||
#include "ns1ByteToUnicodeBase.h"
|
||||
#include "nsUCvLatinSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP1253ToUnicode [declaration]
|
||||
|
||||
class nsCP1253ToUnicode : public ns1ByteToUnicodeBase
|
||||
/**
|
||||
* A character set converter from CP1253 to Unicode.
|
||||
*
|
||||
* @created 24/Mar/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsCP1253ToUnicode : public nsTableDecoderSupport
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -36,22 +40,18 @@ public:
|
||||
*/
|
||||
nsCP1253ToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
virtual ~nsCP1253ToUnicode();
|
||||
|
||||
/**
|
||||
* Static class constructor.
|
||||
*/
|
||||
static nsresult CreateInstance(nsISupports **aResult);
|
||||
|
||||
protected:
|
||||
virtual uMappingTable* GetMappingTable();
|
||||
virtual PRUnichar* GetFastTable();
|
||||
virtual PRBool GetFastTableInitState();
|
||||
virtual void SetFastTableInit();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsDecoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif /* nsCP1253ToUnicode_h___ */
|
||||
|
@ -420,17 +420,11 @@ nsresult nsDecoderSupport::QueryInterface(REFNSIID aIID,
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIUnicodeDecoder [implementation]
|
||||
|
||||
NS_IMETHODIMP nsDecoderSupport::Convert(PRUnichar * aDest,
|
||||
PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength,
|
||||
const char * aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32 * aSrcLength)
|
||||
NS_IMETHODIMP nsDecoderSupport::Convert(const char * aSrc,
|
||||
PRInt32 * aSrcLength,
|
||||
PRUnichar * aDest,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// XXX this will go away when interface is cleaned
|
||||
aSrc += aSrcOffset;
|
||||
aDest += aDestOffset;
|
||||
|
||||
// we do all operations using pointers internally
|
||||
const char * src = aSrc;
|
||||
const char * srcEnd = aSrc + *aSrcLength;
|
||||
@ -498,6 +492,24 @@ NS_IMETHODIMP nsDecoderSupport::Convert(PRUnichar * aDest,
|
||||
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)
|
||||
{
|
||||
@ -508,17 +520,10 @@ NS_IMETHODIMP nsDecoderSupport::Finish(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
NS_IMETHODIMP nsDecoderSupport::Length(const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 aSrcLength, PRInt32 * aDestLength)
|
||||
{
|
||||
// XXX this will silently go away when interface will change and the right
|
||||
// method will be called because it's already there!!!
|
||||
// XXX deprecated
|
||||
return GetMaxLength(aSrc + aSrcOffset, aSrcLength, aDestLength);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDecoderSupport::Reset()
|
||||
{
|
||||
mBufferLength = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDecoderSupport::SetInputErrorBehavior(PRInt32 aBehavior)
|
||||
{
|
||||
// XXX deprecated
|
||||
@ -563,3 +568,46 @@ NS_IMETHODIMP nsTableDecoderSupport::ConvertNoBuff(const char * aSrc,
|
||||
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;
|
||||
}
|
||||
|
@ -234,12 +234,16 @@ public:
|
||||
*/
|
||||
virtual ~nsDecoderSupport();
|
||||
|
||||
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength) = 0;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// 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);
|
||||
@ -247,7 +251,6 @@ public:
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Length(const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 aSrcLength, PRInt32 * aDestLength);
|
||||
NS_IMETHOD Reset();
|
||||
NS_IMETHOD SetInputErrorBehavior(PRInt32 aBehavior);
|
||||
};
|
||||
|
||||
@ -268,7 +271,7 @@ public:
|
||||
* Class constructor.
|
||||
*/
|
||||
nsTableDecoderSupport(uShiftTable * aShiftTable,
|
||||
uMappingTable * aMappingTable);
|
||||
uMappingTable * aMappingTable);
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
@ -288,4 +291,43 @@ protected:
|
||||
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___ */
|
||||
|
Loading…
Reference in New Issue
Block a user