зеркало из https://github.com/mozilla/pjs.git
Generic factory used.
This commit is contained in:
Родитель
b8bb05f365
Коммит
1f4dc56663
|
@ -18,59 +18,13 @@
|
|||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
#include "nsEUCJPToUnicode.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsUCVJA2Dll.h"
|
||||
#include "nsUCVJA2CID.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define NS_SRC_CHARSET "EUC-JP"
|
||||
#define NS_DEST_CHARSET "Unicode"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEUCJPToUnicode [declaration]
|
||||
|
||||
class nsEUCJPToUnicode : public nsIUnicodeDecoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsEUCJPToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsEUCJPToUnicode();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// 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);
|
||||
|
||||
private:
|
||||
PRInt32 mBehavior;
|
||||
nsIUnicodeDecodeUtil *mUtil;
|
||||
|
||||
};
|
||||
|
||||
// Shift Table
|
||||
static PRInt16 g0201ShiftTable[] = {
|
||||
2, uMultibytesCharset,
|
||||
|
@ -107,7 +61,6 @@ static uRange gRanges[] = {
|
|||
{ 0x8F, 0x8F }
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEUCJPToUnicode [implementation]
|
||||
|
||||
|
@ -127,10 +80,18 @@ nsEUCJPToUnicode::~nsEUCJPToUnicode()
|
|||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsresult nsEUCJPToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsEUCJPToUnicode();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverter [implementation]
|
||||
|
||||
// XXX quick hack so I don't have to include nsICharsetConverterManager
|
||||
extern "C" const nsID kCharsetConverterManagerCID;
|
||||
|
||||
NS_IMETHODIMP nsEUCJPToUnicode::Convert(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength,
|
||||
const char * aSrc, PRInt32 aSrcOffset,
|
||||
|
@ -188,97 +149,3 @@ NS_IMETHODIMP nsEUCJPToUnicode::SetInputErrorBehavior(PRInt32 aBehavior)
|
|||
mBehavior = aBehavior;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEUCJPToUnicodeFactory [implementation]
|
||||
|
||||
nsEUCJPToUnicodeFactory::nsEUCJPToUnicodeFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsEUCJPToUnicodeFactory::~nsEUCJPToUnicodeFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsEUCJPToUnicodeFactory);
|
||||
NS_IMPL_RELEASE(nsEUCJPToUnicodeFactory);
|
||||
|
||||
nsresult nsEUCJPToUnicodeFactory::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 nsEUCJPToUnicodeFactory::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 nsEUCJPToUnicode;
|
||||
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 nsEUCJPToUnicodeFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsEUCJPToUnicodeFactory::GetCharsetSrc(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_SRC_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEUCJPToUnicodeFactory::GetCharsetDest(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_DEST_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -20,18 +20,13 @@
|
|||
#ifndef nsEUCJPToUnicode_h___
|
||||
#define nsEUCJPToUnicode_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEUCJPToUnicodeFactory [declaration]
|
||||
// Class nsEUCJPToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* Factory class for the nsEUCJPToUnicode objects.
|
||||
*
|
||||
*/
|
||||
class nsEUCJPToUnicodeFactory : public nsIFactory,
|
||||
public nsICharsetConverterInfo
|
||||
class nsEUCJPToUnicode : public nsIUnicodeDecoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -40,28 +35,35 @@ public:
|
|||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsEUCJPToUnicodeFactory();
|
||||
nsEUCJPToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsEUCJPToUnicodeFactory();
|
||||
~nsEUCJPToUnicode();
|
||||
|
||||
/**
|
||||
* 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 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);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
private:
|
||||
PRInt32 mBehavior;
|
||||
nsIUnicodeDecodeUtil *mUtil;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [declaration]
|
||||
|
||||
NS_IMETHOD GetCharsetSrc(char ** aCharset);
|
||||
NS_IMETHOD GetCharsetDest(char ** aCharset);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsEUCJPToUnicode_h___ */
|
||||
|
|
|
@ -18,95 +18,10 @@
|
|||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsISO2022JPToUnicode.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
#include "nsUCVJA2CID.h"
|
||||
#include "nsUCVJA2Dll.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define NS_SRC_CHARSET "ISO-2022-JP"
|
||||
#define NS_DEST_CHARSET "Unicode"
|
||||
|
||||
#define BUFFSIZE 2 // the size of the buffer for partial conversions
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsISO2022JPToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from ISO-2022-JP to Unicode.
|
||||
*
|
||||
* The state machine is:
|
||||
* S0 + ESC -> S1
|
||||
* S0 + * -> S0; convert using the current mCharset
|
||||
* S1 + '(' -> S2
|
||||
* S1 + '$' -> S3
|
||||
* S1 + * -> ERR
|
||||
* S2 + 'B' -> S0; mCharset = kASCII
|
||||
* S2 + 'J' -> S0; mCharset = kJISX0201_1976
|
||||
* S2 + * -> ERR
|
||||
* S3 + '@' -> S0; mCharset = kJISX0208_1978
|
||||
* S3 + 'B' -> S0; mCharset = kJISX0208_1983
|
||||
* S3 + * -> ERR
|
||||
* ERR + * -> ERR
|
||||
*
|
||||
* @created 09/Feb/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsISO2022JPToUnicode : public nsIUnicodeDecoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsISO2022JPToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsISO2022JPToUnicode();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// 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);
|
||||
|
||||
private:
|
||||
|
||||
enum {
|
||||
kASCII,
|
||||
kJISX0201_1976,
|
||||
kJISX0208_1978,
|
||||
kJISX0208_1983
|
||||
};
|
||||
|
||||
PRInt32 mState; // current state of the state machine
|
||||
PRInt32 mCharset; // current character set
|
||||
|
||||
char mBuff[BUFFSIZE]; // buffer for the partial conversions
|
||||
PRInt32 mBuffLen;
|
||||
|
||||
nsIUnicodeDecodeUtil * mHelper; // decoder helper object
|
||||
|
||||
nsresult ConvertBuffer(const char ** aSrc, const char * aSrcEnd,
|
||||
PRUnichar ** aDest, PRUnichar * aDestEnd);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsISO2022JPToUnicode [implementation]
|
||||
|
||||
|
@ -127,6 +42,12 @@ nsISO2022JPToUnicode::~nsISO2022JPToUnicode()
|
|||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsresult nsISO2022JPToUnicode::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsISO2022JPToUnicode();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
// XXX quick hack so I don't have to include nsICharsetConverterManager
|
||||
extern "C" const nsID kCharsetConverterManagerCID;
|
||||
|
||||
|
@ -354,97 +275,3 @@ NS_IMETHODIMP nsISO2022JPToUnicode::SetInputErrorBehavior(PRInt32 aBehavior)
|
|||
// we are supporting only the kOnError_Signal behavior in this implementation
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsISO2022JPToUnicodeFactory [implementation]
|
||||
|
||||
nsISO2022JPToUnicodeFactory::nsISO2022JPToUnicodeFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsISO2022JPToUnicodeFactory::~nsISO2022JPToUnicodeFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsISO2022JPToUnicodeFactory);
|
||||
NS_IMPL_RELEASE(nsISO2022JPToUnicodeFactory);
|
||||
|
||||
nsresult nsISO2022JPToUnicodeFactory::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 nsISO2022JPToUnicodeFactory::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 nsISO2022JPToUnicode;
|
||||
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 nsISO2022JPToUnicodeFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsISO2022JPToUnicodeFactory::GetCharsetSrc(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_SRC_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsISO2022JPToUnicodeFactory::GetCharsetDest(char ** aCharset)
|
||||
{
|
||||
(*aCharset) = NS_DEST_CHARSET;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -20,20 +20,38 @@
|
|||
#ifndef nsISO2022JPToUnicode_h___
|
||||
#define nsISO2022JPToUnicode_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsISO2022JPToUnicodeFactory [declaration]
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define BUFFSIZE 2 // the size of the buffer for partial conversions
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsISO2022JPToUnicode [declaration]
|
||||
|
||||
/**
|
||||
* Factory class for the nsISO2022JPToUnicode objects.
|
||||
*
|
||||
* A character set converter from ISO-2022-JP to Unicode.
|
||||
*
|
||||
* The state machine is:
|
||||
* S0 + ESC -> S1
|
||||
* S0 + * -> S0; convert using the current mCharset
|
||||
* S1 + '(' -> S2
|
||||
* S1 + '$' -> S3
|
||||
* S1 + * -> ERR
|
||||
* S2 + 'B' -> S0; mCharset = kASCII
|
||||
* S2 + 'J' -> S0; mCharset = kJISX0201_1976
|
||||
* S2 + * -> ERR
|
||||
* S3 + '@' -> S0; mCharset = kJISX0208_1978
|
||||
* S3 + 'B' -> S0; mCharset = kJISX0208_1983
|
||||
* S3 + * -> ERR
|
||||
* ERR + * -> ERR
|
||||
*
|
||||
* @created 09/Feb/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsISO2022JPToUnicodeFactory : public nsIFactory,
|
||||
public nsICharsetConverterInfo
|
||||
class nsISO2022JPToUnicode : public nsIUnicodeDecoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -42,28 +60,50 @@ public:
|
|||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsISO2022JPToUnicodeFactory();
|
||||
nsISO2022JPToUnicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsISO2022JPToUnicodeFactory();
|
||||
~nsISO2022JPToUnicode();
|
||||
|
||||
/**
|
||||
* 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 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);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
private:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [declaration]
|
||||
enum {
|
||||
kASCII,
|
||||
kJISX0201_1976,
|
||||
kJISX0208_1978,
|
||||
kJISX0208_1983
|
||||
};
|
||||
|
||||
NS_IMETHOD GetCharsetSrc(char ** aCharset);
|
||||
NS_IMETHOD GetCharsetDest(char ** aCharset);
|
||||
PRInt32 mState; // current state of the state machine
|
||||
PRInt32 mCharset; // current character set
|
||||
|
||||
char mBuff[BUFFSIZE]; // buffer for the partial conversions
|
||||
PRInt32 mBuffLen;
|
||||
|
||||
nsIUnicodeDecodeUtil * mHelper; // decoder helper object
|
||||
|
||||
nsresult ConvertBuffer(const char ** aSrc, const char * aSrcEnd,
|
||||
PRUnichar ** aDest, PRUnichar * aDestEnd);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsISO2022JPToUnicode_h___ */
|
||||
|
|
|
@ -19,10 +19,13 @@
|
|||
|
||||
#define NS_IMPL_IDS
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "nsUCVJA2CID.h"
|
||||
#include "nsEUCJPToUnicode.h"
|
||||
#include "nsISO2022JPToUnicode.h"
|
||||
#include "nsUCVJA2CID.h"
|
||||
|
||||
// just for NS_IMPL_IDS; this is a good, central place to implement GUIDs
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
|
@ -32,9 +35,6 @@
|
|||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
extern "C" PRInt32 g_InstanceCount = 0;
|
||||
extern "C" PRInt32 g_LockCount = 0;
|
||||
|
||||
extern "C" PRUint16 g_0201Mapping[] = {
|
||||
#include "jis0201.ut"
|
||||
};
|
||||
|
@ -47,6 +47,83 @@ extern "C" PRUint16 g_0212Mapping[] = {
|
|||
#include "jis0212.ut"
|
||||
};
|
||||
|
||||
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[] =
|
||||
{
|
||||
{
|
||||
&kISO2022JPToUnicodeCID,
|
||||
nsISO2022JPToUnicode::CreateInstance,
|
||||
"ISO-2022-JP",
|
||||
"Unicode"
|
||||
},
|
||||
{
|
||||
&kEUCJPToUnicodeCID,
|
||||
nsEUCJPToUnicode::CreateInstance,
|
||||
"EUC-JP"
|
||||
"Unicode"
|
||||
}
|
||||
};
|
||||
|
||||
#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]
|
||||
|
||||
|
@ -63,30 +140,22 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID,
|
|||
{
|
||||
if (aFactory == NULL) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// the EUCJPToUnicode converter
|
||||
if (aCID.Equals(kEUCJPToUnicodeCID)) {
|
||||
nsEUCJPToUnicodeFactory *factory = new nsEUCJPToUnicodeFactory();
|
||||
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 ISO2022JPToUnicode converter
|
||||
if (aCID.Equals(kISO2022JPToUnicodeCID)) {
|
||||
nsISO2022JPToUnicodeFactory *factory = new nsISO2022JPToUnicodeFactory();
|
||||
nsresult res = factory->QueryInterface(kIFactoryIID, (void **) aFactory);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete factory;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
|
@ -96,13 +165,11 @@ extern "C" NS_EXPORT nsresult NSRegisterSelf(const char * path)
|
|||
{
|
||||
nsresult res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kEUCJPToUnicodeCID, 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;
|
||||
|
||||
res = nsRepository::RegisterFactory(kISO2022JPToUnicodeCID, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res;
|
||||
if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -111,11 +178,107 @@ extern "C" NS_EXPORT nsresult NSUnregisterSelf(const char * path)
|
|||
{
|
||||
nsresult res;
|
||||
|
||||
res = nsRepository::UnregisterFactory(kEUCJPToUnicodeCID, path);
|
||||
if(NS_FAILED(res)) return res;
|
||||
|
||||
res = nsRepository::UnregisterFactory(kISO2022JPToUnicodeCID, 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче