зеркало из https://github.com/mozilla/pjs.git
Generic factory used.
This commit is contained in:
Родитель
76360d335d
Коммит
59928f53ca
|
@ -18,51 +18,12 @@
|
|||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
#include "nsCP1253ToUnicode.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "ns1ByteToUnicodeBase.h"
|
||||
#include "nsUCvLatinDll.h"
|
||||
#include "nsUCvLatinCID.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define NS_SRC_CHARSET "windows-1253"
|
||||
#define NS_DEST_CHARSET "Unicode"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP1253ToUnicode [declaration]
|
||||
|
||||
class nsCP1253ToUnicode : public ns1ByteToUnicodeBase
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsCP1253ToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsCP1253ToUnicode();
|
||||
|
||||
protected:
|
||||
virtual uMappingTable* GetMappingTable();
|
||||
virtual PRUnichar* GetFastTable();
|
||||
virtual PRBool GetFastTableInitState();
|
||||
virtual void SetFastTableInit();
|
||||
|
||||
};
|
||||
|
||||
|
||||
static PRUint16 gMappingTable[] = {
|
||||
#include "cp1253.ut"
|
||||
};
|
||||
|
@ -86,6 +47,12 @@ nsCP1253ToUnicode::~nsCP1253ToUnicode()
|
|||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsresult nsCP1253ToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsCP1253ToUnicode();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
uMappingTable* nsCP1253ToUnicode::GetMappingTable()
|
||||
{
|
||||
return (uMappingTable*) &gMappingTable;
|
||||
|
@ -105,96 +72,3 @@ void nsCP1253ToUnicode::SetFastTableInit()
|
|||
{
|
||||
gFastTableInit = PR_TRUE;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP1253ToUnicodeFactory [implementation]
|
||||
|
||||
nsCP1253ToUnicodeFactory::nsCP1253ToUnicodeFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsCP1253ToUnicodeFactory::~nsCP1253ToUnicodeFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsCP1253ToUnicodeFactory);
|
||||
NS_IMPL_RELEASE(nsCP1253ToUnicodeFactory);
|
||||
|
||||
nsresult nsCP1253ToUnicodeFactory::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, kICharsetConverterInfoIID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
if (aIID.Equals(kClassIID)) {
|
||||
*aInstancePtr = (void*) ((nsICharsetConverterInfo*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*) ((nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIFactory [implementation]
|
||||
|
||||
NS_IMETHODIMP nsCP1253ToUnicodeFactory::CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsIUnicodeDecoder * t = new nsCP1253ToUnicode;
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCP1253ToUnicodeFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsCP1253ToUnicodeFactory::GetCharsetSrc(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_SRC_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCP1253ToUnicodeFactory::GetCharsetDest(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_DEST_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -20,18 +20,12 @@
|
|||
#ifndef nsCP1253ToUnicode_h___
|
||||
#define nsCP1253ToUnicode_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "ns1ByteToUnicodeBase.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP1253ToUnicodeFactory [declaration]
|
||||
// Class nsCP1253ToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* Factory class for the nsCP1253ToUnicode objects.
|
||||
*
|
||||
*/
|
||||
class nsCP1253ToUnicodeFactory : public nsIFactory,
|
||||
public nsICharsetConverterInfo
|
||||
class nsCP1253ToUnicode : public ns1ByteToUnicodeBase
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -40,28 +34,24 @@ public:
|
|||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsCP1253ToUnicodeFactory();
|
||||
nsCP1253ToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsCP1253ToUnicodeFactory();
|
||||
~nsCP1253ToUnicode();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIFactory [declaration]
|
||||
/**
|
||||
* Static class constructor.
|
||||
*/
|
||||
static nsresult CreateInstance(nsISupports **aResult);
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID,
|
||||
void **aResult);
|
||||
protected:
|
||||
virtual uMappingTable* GetMappingTable();
|
||||
virtual PRUnichar* GetFastTable();
|
||||
virtual PRBool GetFastTableInitState();
|
||||
virtual void SetFastTableInit();
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [declaration]
|
||||
|
||||
NS_IMETHOD GetCharsetSrc(char ** aCharset);
|
||||
NS_IMETHOD GetCharsetDest(char ** aCharset);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,49 +18,8 @@
|
|||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
#include "nsISO88597ToUnicode.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "ns1ByteToUnicodeBase.h"
|
||||
#include "nsUCvLatinDll.h"
|
||||
#include "nsUCvLatinCID.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define NS_SRC_CHARSET "ISO-8859-7"
|
||||
#define NS_DEST_CHARSET "Unicode"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsISO88597ToUnicode [declaration]
|
||||
|
||||
class nsISO88597ToUnicode : public ns1ByteToUnicodeBase
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsISO88597ToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsISO88597ToUnicode();
|
||||
|
||||
protected:
|
||||
virtual uMappingTable* GetMappingTable();
|
||||
virtual PRUnichar* GetFastTable();
|
||||
virtual PRBool GetFastTableInitState();
|
||||
virtual void SetFastTableInit();
|
||||
|
||||
};
|
||||
|
||||
|
||||
static PRUint16 gMappingTable[] = {
|
||||
#include "8859-7.ut"
|
||||
|
@ -85,6 +44,12 @@ nsISO88597ToUnicode::~nsISO88597ToUnicode()
|
|||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsresult nsISO88597ToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsISO88597ToUnicode();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
uMappingTable* nsISO88597ToUnicode::GetMappingTable()
|
||||
{
|
||||
return (uMappingTable*) &gMappingTable;
|
||||
|
@ -104,96 +69,3 @@ void nsISO88597ToUnicode::SetFastTableInit()
|
|||
{
|
||||
gFastTableInit = PR_TRUE;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsISO88597ToUnicodeFactory [implementation]
|
||||
|
||||
nsISO88597ToUnicodeFactory::nsISO88597ToUnicodeFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsISO88597ToUnicodeFactory::~nsISO88597ToUnicodeFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsISO88597ToUnicodeFactory);
|
||||
NS_IMPL_RELEASE(nsISO88597ToUnicodeFactory);
|
||||
|
||||
nsresult nsISO88597ToUnicodeFactory::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, kICharsetConverterInfoIID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
if (aIID.Equals(kClassIID)) {
|
||||
*aInstancePtr = (void*) ((nsICharsetConverterInfo*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*) ((nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIFactory [implementation]
|
||||
|
||||
NS_IMETHODIMP nsISO88597ToUnicodeFactory::CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsIUnicodeDecoder * t = new nsISO88597ToUnicode;
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsISO88597ToUnicodeFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsISO88597ToUnicodeFactory::GetCharsetSrc(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_SRC_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsISO88597ToUnicodeFactory::GetCharsetDest(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_DEST_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -20,18 +20,12 @@
|
|||
#ifndef nsISO88597ToUnicode_h___
|
||||
#define nsISO88597ToUnicode_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "ns1ByteToUnicodeBase.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsISO88597ToUnicodeFactory [declaration]
|
||||
// Class nsISO88597ToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* Factory class for the nsISO88597ToUnicode objects.
|
||||
*
|
||||
*/
|
||||
class nsISO88597ToUnicodeFactory : public nsIFactory,
|
||||
public nsICharsetConverterInfo
|
||||
class nsISO88597ToUnicode : public ns1ByteToUnicodeBase
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -40,28 +34,24 @@ public:
|
|||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsISO88597ToUnicodeFactory();
|
||||
nsISO88597ToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsISO88597ToUnicodeFactory();
|
||||
~nsISO88597ToUnicode();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIFactory [declaration]
|
||||
/**
|
||||
* Static class constructor.
|
||||
*/
|
||||
static nsresult CreateInstance(nsISupports **aResult);
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID,
|
||||
void **aResult);
|
||||
protected:
|
||||
virtual uMappingTable* GetMappingTable();
|
||||
virtual PRUnichar* GetFastTable();
|
||||
virtual PRBool GetFastTableInitState();
|
||||
virtual void SetFastTableInit();
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [declaration]
|
||||
|
||||
NS_IMETHOD GetCharsetSrc(char ** aCharset);
|
||||
NS_IMETHOD GetCharsetDest(char ** aCharset);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,64 +18,10 @@
|
|||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsLatin1ToUnicode.h"
|
||||
#include "nsUCvLatinCID.h"
|
||||
#include "nsUCvLatinDll.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define NS_SRC_CHARSET "ISO-8859-1"
|
||||
#define NS_DEST_CHARSET "Unicode"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsLatin1ToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from Latin1 to Unicode.
|
||||
*
|
||||
* This particular converter does not use the general single-byte converter
|
||||
* helper object. That is because someone may want to optimise this converter
|
||||
* to the fullest, as it is one of the most heavily used.
|
||||
*
|
||||
* Multithreading: not an issue, the object has one instance per user thread.
|
||||
* As a plus, it is also stateless!
|
||||
*
|
||||
* @created 23/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsLatin1ToUnicode : public nsIUnicodeDecoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsLatin1ToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsLatin1ToUnicode();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIUnicodeDecoder [declaration]
|
||||
|
||||
NS_IMETHOD Convert(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength,const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 * aSrcLength);
|
||||
NS_IMETHOD Finish(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Length(const char * aSrc, PRInt32 aSrcOffset, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Reset();
|
||||
NS_IMETHOD SetInputErrorBehavior(PRInt32 aBehavior);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsLatin1ToUnicode [implementation]
|
||||
|
||||
|
@ -92,6 +38,12 @@ nsLatin1ToUnicode::~nsLatin1ToUnicode()
|
|||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsresult nsLatin1ToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsLatin1ToUnicode();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverter [implementation]
|
||||
|
||||
|
@ -146,97 +98,3 @@ NS_IMETHODIMP nsLatin1ToUnicode::SetInputErrorBehavior(PRInt32 aBehavior)
|
|||
// no input error possible, this encoding is too simple
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsLatin1ToUnicodeFactory [implementation]
|
||||
|
||||
nsLatin1ToUnicodeFactory::nsLatin1ToUnicodeFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsLatin1ToUnicodeFactory::~nsLatin1ToUnicodeFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsLatin1ToUnicodeFactory);
|
||||
NS_IMPL_RELEASE(nsLatin1ToUnicodeFactory);
|
||||
|
||||
nsresult nsLatin1ToUnicodeFactory::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, kICharsetConverterInfoIID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
if (aIID.Equals(kClassIID)) {
|
||||
*aInstancePtr = (void*) ((nsICharsetConverterInfo*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*) ((nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIFactory [implementation]
|
||||
|
||||
NS_IMETHODIMP nsLatin1ToUnicodeFactory::CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsIUnicodeDecoder * t = new nsLatin1ToUnicode;
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLatin1ToUnicodeFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsLatin1ToUnicodeFactory::GetCharsetSrc(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_SRC_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLatin1ToUnicodeFactory::GetCharsetDest(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_DEST_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -20,20 +20,28 @@
|
|||
#ifndef nsLatin1ToUnicode_h___
|
||||
#define nsLatin1ToUnicode_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsLatin1ToUnicodeFactory [declaration]
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsLatin1ToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* Factory class for the nsLatin1ToUnicode objects.
|
||||
* A character set converter from Latin1 to Unicode.
|
||||
*
|
||||
* This particular converter does not use the general single-byte converter
|
||||
* helper object. That is because someone may want to optimise this converter
|
||||
* to the fullest, as it is one of the most heavily used.
|
||||
*
|
||||
* Multithreading: not an issue, the object has one instance per user thread.
|
||||
* As a plus, it is also stateless!
|
||||
*
|
||||
* @created 08/Dec/1998
|
||||
* @created 23/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsLatin1ToUnicodeFactory : public nsIFactory,
|
||||
public nsICharsetConverterInfo
|
||||
class nsLatin1ToUnicode : public nsIUnicodeDecoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -42,28 +50,30 @@ public:
|
|||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsLatin1ToUnicodeFactory();
|
||||
nsLatin1ToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsLatin1ToUnicodeFactory();
|
||||
~nsLatin1ToUnicode();
|
||||
|
||||
/**
|
||||
* Static class constructor.
|
||||
*/
|
||||
static nsresult CreateInstance(nsISupports **aResult);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIFactory [declaration]
|
||||
// Interface nsIUnicodeDecoder [declaration]
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [declaration]
|
||||
|
||||
NS_IMETHOD GetCharsetSrc(char ** aCharset);
|
||||
NS_IMETHOD GetCharsetDest(char ** aCharset);
|
||||
NS_IMETHOD Convert(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength,const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 * aSrcLength);
|
||||
NS_IMETHOD Finish(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Length(const char * aSrc, PRInt32 aSrcOffset, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Reset();
|
||||
NS_IMETHOD SetInputErrorBehavior(PRInt32 aBehavior);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsLatin1ToUnicode_h___ */
|
||||
|
|
|
@ -19,15 +19,19 @@
|
|||
|
||||
#define NS_IMPL_IDS
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "nsUCvLatinCID.h"
|
||||
#include "nsLatin1ToUnicode.h"
|
||||
#include "nsISO88597ToUnicode.h"
|
||||
#include "nsCP1253ToUnicode.h"
|
||||
#include "nsUnicodeToLatin1.h"
|
||||
#include "nsUCvLatinCID.h"
|
||||
// just for NS_IMPL_IDS
|
||||
|
||||
// just for NS_IMPL_IDS; this is a good, central place to implement GUIDs
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIUnicodeEncodeHelper.h"
|
||||
|
@ -38,6 +42,92 @@
|
|||
extern "C" PRInt32 g_InstanceCount = 0;
|
||||
extern "C" PRInt32 g_LockCount = 0;
|
||||
|
||||
typedef nsresult (* fpCreateInstance) (nsISupports **);
|
||||
|
||||
struct FactoryData
|
||||
{
|
||||
const nsCID * mCID;
|
||||
fpCreateInstance CreateInstance;
|
||||
char * mCharsetSrc;
|
||||
char * mCharsetDest;
|
||||
};
|
||||
|
||||
FactoryData g_FactoryData[] =
|
||||
{
|
||||
{
|
||||
&kLatin1ToUnicodeCID,
|
||||
nsLatin1ToUnicode::CreateInstance,
|
||||
"ISO-8859-1",
|
||||
"Unicode"
|
||||
},
|
||||
{
|
||||
&kISO88597ToUnicodeCID,
|
||||
nsISO88597ToUnicode::CreateInstance,
|
||||
"ISO-8859-7",
|
||||
"Unicode"
|
||||
},
|
||||
{
|
||||
&kCP1253ToUnicodeCID,
|
||||
nsCP1253ToUnicode::CreateInstance,
|
||||
"windows-1253",
|
||||
"Unicode"
|
||||
},
|
||||
{
|
||||
&kUnicodeToLatin1CID,
|
||||
nsUnicodeToLatin1::CreateInstance,
|
||||
"Unicode",
|
||||
"ISO-8859-1"
|
||||
}
|
||||
};
|
||||
|
||||
#define ARRAY_SIZE(_array) \
|
||||
(sizeof(_array) / sizeof(_array[0]))
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsConverterFactory [declaration]
|
||||
|
||||
/**
|
||||
* General factory class for converter objects.
|
||||
*
|
||||
* @created 24/Feb/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsConverterFactory : public nsIFactory,
|
||||
public nsICharsetConverterInfo
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
private:
|
||||
|
||||
FactoryData * mData;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsConverterFactory(FactoryData * aData);
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
virtual ~nsConverterFactory();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIFactory [declaration]
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [declaration]
|
||||
|
||||
NS_IMETHOD GetCharsetSrc(char ** aCharset);
|
||||
NS_IMETHOD GetCharsetDest(char ** aCharset);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [implementation]
|
||||
|
||||
|
@ -48,61 +138,28 @@ extern "C" NS_EXPORT PRBool NSCanUnload()
|
|||
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID, nsISupports* serviceMgr,
|
||||
extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID,
|
||||
nsISupports* serviceMgr,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
if (aFactory == NULL) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// the Latin1ToUnicode converter
|
||||
if (aCID.Equals(kLatin1ToUnicodeCID)) {
|
||||
nsLatin1ToUnicodeFactory *factory = new nsLatin1ToUnicodeFactory();
|
||||
nsresult res = factory->QueryInterface(kIFactoryIID, (void **) aFactory);
|
||||
nsresult res;
|
||||
nsConverterFactory * fac;
|
||||
FactoryData * data;
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete factory;
|
||||
for (PRInt32 i=0; i<ARRAY_SIZE(g_FactoryData); i++) {
|
||||
data = &(g_FactoryData[i]);
|
||||
if (aCID.Equals(*(data->mCID))) {
|
||||
fac = new nsConverterFactory(data);
|
||||
res = fac->QueryInterface(kIFactoryIID, (void **) aFactory);
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete fac;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// the ISO88597ToUnicode converter
|
||||
if (aCID.Equals(kISO88597ToUnicodeCID)) {
|
||||
nsISO88597ToUnicodeFactory *factory = new nsISO88597ToUnicodeFactory();
|
||||
nsresult res = factory->QueryInterface(kIFactoryIID, (void **) aFactory);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete factory;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// the CP1253ToUnicode converter
|
||||
if (aCID.Equals(kCP1253ToUnicodeCID)) {
|
||||
nsCP1253ToUnicodeFactory *factory = new nsCP1253ToUnicodeFactory();
|
||||
nsresult res = factory->QueryInterface(kIFactoryIID, (void **) aFactory);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete factory;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// the UnicodeToLatin1 converter
|
||||
if (aCID.Equals(kUnicodeToLatin1CID)) {
|
||||
nsUnicodeToLatin1Factory *factory = new nsUnicodeToLatin1Factory();
|
||||
nsresult res = factory->QueryInterface(kIFactoryIID, (void **) aFactory);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete factory;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
|
@ -112,20 +169,11 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(const char * path)
|
|||
{
|
||||
nsresult res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kLatin1ToUnicodeCID, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kCP1253ToUnicodeCID, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kISO88597ToUnicodeCID, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kUnicodeToLatin1CID, path,
|
||||
for (PRInt32 i=0; i<ARRAY_SIZE(g_FactoryData); i++) {
|
||||
res = nsRepository::RegisterFactory(*(g_FactoryData[i].mCID), path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -134,15 +182,107 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(const char * path)
|
|||
{
|
||||
nsresult res;
|
||||
|
||||
res = nsRepository::UnregisterFactory(kLatin1ToUnicodeCID, path);
|
||||
if(NS_FAILED(res)) return res;
|
||||
for (PRInt32 i=0; i<ARRAY_SIZE(g_FactoryData); i++) {
|
||||
res = nsRepository::UnregisterFactory(*(g_FactoryData[i].mCID), path);
|
||||
if(NS_FAILED(res)) return res;
|
||||
}
|
||||
|
||||
res = nsRepository::UnregisterFactory(kCP1253ToUnicodeCID, path);
|
||||
if(NS_FAILED(res)) return res;
|
||||
|
||||
res = nsRepository::UnregisterFactory(kISO88597ToUnicodeCID, path);
|
||||
if(NS_FAILED(res)) return res;
|
||||
|
||||
res = nsRepository::UnregisterFactory(kUnicodeToLatin1CID, path);
|
||||
return res;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsConverterFactory [implementation]
|
||||
|
||||
nsConverterFactory::nsConverterFactory(FactoryData * aData)
|
||||
{
|
||||
mData = aData;
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsConverterFactory::~nsConverterFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsConverterFactory);
|
||||
NS_IMPL_RELEASE(nsConverterFactory);
|
||||
|
||||
nsresult nsConverterFactory::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, kICharsetConverterInfoIID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
if (aIID.Equals(kClassIID)) {
|
||||
*aInstancePtr = (void*) ((nsICharsetConverterInfo*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*) ((nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIFactory [implementation]
|
||||
|
||||
NS_IMETHODIMP nsConverterFactory::CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsISupports * t;
|
||||
mData->CreateInstance(&t);
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsConverterFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsConverterFactory::GetCharsetSrc(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = mData->mCharsetSrc;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsConverterFactory::GetCharsetDest(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = mData->mCharsetDest;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -1,180 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsUCvLatinSupport.h"
|
||||
#include "nsUnicodeToLatin1.h"
|
||||
#include "nsUCvLatinCID.h"
|
||||
#include "nsUCvLatinDll.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define NS_SRC_CHARSET "Unicode"
|
||||
#define NS_DEST_CHARSET "ISO-8859-1"
|
||||
|
||||
static PRUint16 g_Latin1MappingTable[] = {
|
||||
#include "8859-1.uf"
|
||||
};
|
||||
|
||||
static PRInt16 g_Latin1ShiftTable[] = {
|
||||
1, u1ByteCharset ,
|
||||
ShiftCell(0,0,0,0,0,0,0,0)
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToLatin1 [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from Unicode to Latin1.
|
||||
*
|
||||
* @created 17/Feb/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsUnicodeToLatin1 : public nsTableEncoderSupport
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsUnicodeToLatin1();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToLatin1 [implementation]
|
||||
|
||||
nsUnicodeToLatin1::nsUnicodeToLatin1()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_Latin1ShiftTable,
|
||||
(uMappingTable*) &g_Latin1MappingTable)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToLatin1::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToLatin1Factory [implementation]
|
||||
|
||||
nsUnicodeToLatin1Factory::nsUnicodeToLatin1Factory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsUnicodeToLatin1Factory::~nsUnicodeToLatin1Factory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsUnicodeToLatin1Factory);
|
||||
NS_IMPL_RELEASE(nsUnicodeToLatin1Factory);
|
||||
|
||||
nsresult nsUnicodeToLatin1Factory::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, kICharsetConverterInfoIID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
if (aIID.Equals(kClassIID)) {
|
||||
*aInstancePtr = (void*) ((nsICharsetConverterInfo*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*) ((nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIFactory [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToLatin1Factory::CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsIUnicodeEncoder * t = new nsUnicodeToLatin1;
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToLatin1Factory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToLatin1Factory::GetCharsetSrc(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_SRC_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToLatin1Factory::GetCharsetDest(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_DEST_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
|
@ -1,69 +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 nsUnicodeToLatin1_h___
|
||||
#define nsUnicodeToLatin1_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToLatin1Factory [declaration]
|
||||
|
||||
/**
|
||||
* Factory class for the nsUnicodeToLatin1 objects.
|
||||
*
|
||||
* @created 17/Feb/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsUnicodeToLatin1Factory : public nsIFactory,
|
||||
public nsICharsetConverterInfo
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsUnicodeToLatin1Factory();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsUnicodeToLatin1Factory();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIFactory [declaration]
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [declaration]
|
||||
|
||||
NS_IMETHOD GetCharsetSrc(char ** aCharset);
|
||||
NS_IMETHOD GetCharsetDest(char ** aCharset);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsUnicodeToLatin1_h___ */
|
Загрузка…
Ссылка в новой задаче