mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-05-13 08:57:27 +00:00
Support class, EUCJP and ISO2022JP encoders added.
This commit is contained in:
parent
57638ea34c
commit
37bbd1fb9e
@ -29,8 +29,11 @@ CSRCS = \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsISO2022JPToUnicode.cpp \
|
||||
nsEUCJPToUnicode.cpp \
|
||||
nsISO2022JPToUnicode.cpp \
|
||||
nsUnicodeToEUCJP.cpp \
|
||||
nsUnicodeToISO2022JP.cpp \
|
||||
nsUCvJa2Support.cpp \
|
||||
nsUCVJA2Dll.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
@ -27,15 +27,21 @@ DLLNAME = ucvja2
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
CPPSRCS = \
|
||||
nsUCVJA2Dll.cpp \
|
||||
nsEUCJPToUnicode.cpp \
|
||||
nsISO2022JPToUnicode.cpp \
|
||||
nsUnicodeToEUCJP.cpp \
|
||||
nsUnicodeToISO2022JP.cpp \
|
||||
nsUCvJa2Support.cpp \
|
||||
nsUCVJA2Dll.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsUCVJA2Dll.obj \
|
||||
.\$(OBJDIR)\nsEUCJPToUnicode.obj \
|
||||
.\$(OBJDIR)\nsISO2022JPToUnicode.obj \
|
||||
.\$(OBJDIR)\nsUnicodeToEUCJP.obj \
|
||||
.\$(OBJDIR)\nsUnicodeToISO2022JP.obj \
|
||||
.\$(OBJDIR)\nsUCvJa2Support.obj \
|
||||
.\$(OBJDIR)\nsUCVJA2Dll.obj \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
|
@ -27,11 +27,19 @@
|
||||
NS_DECLARE_ID(kEUCJPToUnicodeCID,
|
||||
0x3f6fe6a1, 0xac0a, 0x11d2, 0xb3, 0xae, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70);
|
||||
|
||||
|
||||
// Class ID for our ISO2022JPToUnicode charset converter
|
||||
// {3F6FE6A2-AC0A-11d2-B3AE-00805F8A6670}
|
||||
NS_DECLARE_ID(kISO2022JPToUnicodeCID,
|
||||
0x3f6fe6a2, 0xac0a, 0x11d2, 0xb3, 0xae, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70);
|
||||
|
||||
// Class ID for our UnicodeToEUCJP charset converter
|
||||
// {45C23A20-D71C-11d2-8AAC-00600811A836}
|
||||
NS_DECLARE_ID(kUnicodeToEUCJPCID,
|
||||
0x45c23a20, 0xd71c, 0x11d2, 0x8a, 0xac, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36);
|
||||
|
||||
// Class ID for our UnicodeToISO2022JP charset converter
|
||||
// {4F76E100-D71C-11d2-8AAC-00600811A836}
|
||||
NS_DECLARE_ID(kUnicodeToISO2022JPCID,
|
||||
0x4f76e100, 0xd71c, 0x11d2, 0x8a, 0xac, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36);
|
||||
|
||||
#endif /* nsUCVJA2CID_h___ */
|
||||
|
@ -21,24 +21,34 @@
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "nsUCVJA2CID.h"
|
||||
#include "nsUCVJA2Dll.h"
|
||||
#include "nsEUCJPToUnicode.h"
|
||||
#include "nsISO2022JPToUnicode.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
#include "nsUnicodeToEUCJP.h"
|
||||
#include "nsUnicodeToISO2022JP.h"
|
||||
|
||||
// just for NS_IMPL_IDS; this is a good, central place to implement GUIDs
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeDecodeUtil.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeEncodeHelper.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
extern "C" PRInt32 g_InstanceCount = 0;
|
||||
extern "C" PRInt32 g_LockCount = 0;
|
||||
|
||||
extern "C" PRUint16 g_0201Mapping[] = {
|
||||
#include "jis0201.ut"
|
||||
};
|
||||
@ -51,9 +61,6 @@ 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
|
||||
@ -75,8 +82,20 @@ FactoryData g_FactoryData[] =
|
||||
{
|
||||
&kEUCJPToUnicodeCID,
|
||||
nsEUCJPToUnicode::CreateInstance,
|
||||
"EUC-JP"
|
||||
"EUC-JP",
|
||||
"Unicode"
|
||||
},
|
||||
{
|
||||
&kUnicodeToEUCJPCID,
|
||||
nsUnicodeToEUCJP::CreateInstance,
|
||||
"Unicode",
|
||||
"EUC-JP"
|
||||
},
|
||||
{
|
||||
&kUnicodeToISO2022JPCID,
|
||||
nsUnicodeToISO2022JP::CreateInstance,
|
||||
"Unicode",
|
||||
"ISO-2022-JP"
|
||||
}
|
||||
};
|
||||
|
||||
@ -131,8 +150,6 @@ public:
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [implementation]
|
||||
|
||||
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr)
|
||||
{
|
||||
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
|
||||
@ -244,28 +261,19 @@ nsresult nsConverterFactory::QueryInterface(REFNSIID aIID,
|
||||
}
|
||||
|
||||
*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)) {
|
||||
if (aIID.Equals(kICharsetConverterInfoIID)) {
|
||||
*aInstancePtr = (void*) ((nsICharsetConverterInfo*)this);
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*) ((nsIFactory*)this);
|
||||
} else if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
} else {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -22,11 +22,11 @@
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
extern "C" PRInt32 g_InstanceCount;
|
||||
extern "C" PRInt32 g_LockCount;
|
||||
extern PRInt32 g_InstanceCount;
|
||||
extern PRInt32 g_LockCount;
|
||||
|
||||
extern "C" PRUint16 g_0201Mapping[];
|
||||
extern "C" PRUint16 g_0208Mapping[];
|
||||
extern "C" PRUint16 g_0212Mapping[];
|
||||
extern PRUint16 g_0201Mapping[];
|
||||
extern PRUint16 g_0208Mapping[];
|
||||
extern PRUint16 g_0212Mapping[];
|
||||
|
||||
#endif /* nsUCVJA2Dll_h___ */
|
||||
|
308
intl/uconv/ucvja2/nsUCvJa2Support.cpp
Normal file
308
intl/uconv/ucvja2/nsUCvJa2Support.cpp
Normal file
@ -0,0 +1,308 @@
|
||||
/* -*- 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 "nsIComponentManager.h"
|
||||
#include "nsUCvJa2Support.h"
|
||||
#include "nsUCVJA2Dll.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEncoderSupport [implementation]
|
||||
|
||||
nsEncoderSupport::nsEncoderSupport()
|
||||
{
|
||||
mBufferCapacity = 16;
|
||||
mBuffer = new char[mBufferCapacity];
|
||||
|
||||
mErrBehavior = kOnError_Signal;
|
||||
mErrChar = 0;
|
||||
mErrEncoder = NULL;
|
||||
|
||||
Reset();
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsEncoderSupport::~nsEncoderSupport()
|
||||
{
|
||||
delete [] mBuffer;
|
||||
NS_IF_RELEASE(mErrEncoder);
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEncoderSupport::ConvertNoBuff(const PRUnichar * aSrc,
|
||||
PRInt32 * aSrcLength,
|
||||
char * aDest,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// we do all operations using pointers internally
|
||||
const PRUnichar * src = aSrc;
|
||||
const PRUnichar * srcEnd = aSrc + *aSrcLength;
|
||||
char * dest = aDest;
|
||||
char * destEnd = aDest + *aDestLength;
|
||||
|
||||
PRInt32 bcr, bcw; // byte counts for read & write;
|
||||
nsresult res;
|
||||
|
||||
for (;;) {
|
||||
bcr = srcEnd - src;
|
||||
bcw = destEnd - dest;
|
||||
res = ConvertNoBuffNoErr(src, &bcr, dest, &bcw);
|
||||
src += bcr;
|
||||
dest += bcw;
|
||||
|
||||
if (res == NS_ERROR_UENC_NOMAPPING) {
|
||||
if (mErrBehavior == kOnError_Replace) {
|
||||
const PRUnichar buff[] = {mErrChar};
|
||||
bcr = 1;
|
||||
bcw = destEnd - dest;
|
||||
src--; // back the input: maybe the guy won't consume consume anything.
|
||||
res = ConvertNoBuffNoErr(buff, &bcr, dest, &bcw);
|
||||
src += bcr;
|
||||
dest += bcw;
|
||||
if (res != NS_OK) break;
|
||||
} else if (mErrBehavior == kOnError_CallBack) {
|
||||
bcw = destEnd - dest;
|
||||
src--;
|
||||
res = mErrEncoder->Convert(*src, dest, &bcw);
|
||||
dest += bcw;
|
||||
// if enought output space then the last char was used
|
||||
if (res != NS_OK_UENC_MOREOUTPUT) src++;
|
||||
if (res != NS_OK) break;
|
||||
} else break;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
*aSrcLength -= srcEnd - src;
|
||||
*aDestLength -= destEnd - dest;
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEncoderSupport::FinishNoBuff(char * aDest,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEncoderSupport::FlushBuffer(char ** aDest,
|
||||
const char * aDestEnd)
|
||||
{
|
||||
PRInt32 bcr, bcw; // byte counts for read & write;
|
||||
nsresult res = NS_OK;
|
||||
char * dest = *aDest;
|
||||
|
||||
if (mBufferStart < mBufferEnd) {
|
||||
bcr = mBufferEnd - mBufferStart;
|
||||
bcw = aDestEnd - dest;
|
||||
if (bcw < bcr) bcr = bcw;
|
||||
memcpy(dest, mBufferStart, bcr);
|
||||
dest += bcr;
|
||||
mBufferStart += bcr;
|
||||
|
||||
if (mBufferStart < mBufferEnd) res = NS_OK_UENC_MOREOUTPUT;
|
||||
}
|
||||
|
||||
*aDest = dest;
|
||||
return res;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsEncoderSupport);
|
||||
NS_IMPL_RELEASE(nsEncoderSupport);
|
||||
|
||||
nsresult nsEncoderSupport::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(kIUnicodeEncoderIID)) {
|
||||
*aInstancePtr = (void*) ((nsIUnicodeEncoder*)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 nsIUnicodeEncoder [implementation]
|
||||
|
||||
NS_IMETHODIMP nsEncoderSupport::Convert(const PRUnichar * aSrc,
|
||||
PRInt32 * aSrcLength,
|
||||
char * aDest,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// we do all operations using pointers internally
|
||||
const PRUnichar * src = aSrc;
|
||||
const PRUnichar * srcEnd = aSrc + *aSrcLength;
|
||||
char * dest = aDest;
|
||||
char * destEnd = aDest + *aDestLength;
|
||||
|
||||
PRInt32 bcr, bcw; // byte counts for read & write;
|
||||
nsresult res;
|
||||
|
||||
res = FlushBuffer(&dest, destEnd);
|
||||
if (res == NS_OK_UENC_MOREOUTPUT) goto final;
|
||||
|
||||
bcr = srcEnd - src;
|
||||
bcw = destEnd - dest;
|
||||
res = ConvertNoBuff(src, &bcr, dest, &bcw);
|
||||
src += bcr;
|
||||
dest += bcw;
|
||||
if ((res == NS_OK_UENC_MOREOUTPUT) && (dest < destEnd)) {
|
||||
// convert exactly one character into the internal buffer
|
||||
// at this point, there should be at least a char in the input
|
||||
for (;;) {
|
||||
bcr = 1;
|
||||
bcw = mBufferCapacity;
|
||||
res = ConvertNoBuff(src, &bcr, mBuffer, &bcw);
|
||||
|
||||
if (res == NS_OK_UENC_MOREOUTPUT) {
|
||||
delete [] mBuffer;
|
||||
mBufferCapacity *= 2;
|
||||
mBuffer = new char [mBufferCapacity];
|
||||
} else {
|
||||
src += bcr;
|
||||
mBufferStart = mBufferEnd = mBuffer;
|
||||
mBufferEnd += bcw;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
res = FlushBuffer(&dest, destEnd);
|
||||
}
|
||||
|
||||
final:
|
||||
*aSrcLength -= srcEnd - src;
|
||||
*aDestLength -= destEnd - dest;
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEncoderSupport::Finish(char * aDest, PRInt32 * aDestLength)
|
||||
{
|
||||
// we do all operations using pointers internally
|
||||
char * dest = aDest;
|
||||
char * destEnd = aDest + *aDestLength;
|
||||
|
||||
PRInt32 bcw; // byte count for write;
|
||||
nsresult res;
|
||||
|
||||
res = FlushBuffer(&dest, destEnd);
|
||||
if (res == NS_OK_UENC_MOREOUTPUT) goto final;
|
||||
|
||||
// do the finish into the internal buffer.
|
||||
for (;;) {
|
||||
bcw = mBufferCapacity;
|
||||
res = FinishNoBuff(mBuffer, &bcw);
|
||||
|
||||
if (res == NS_OK_UENC_MOREOUTPUT) {
|
||||
delete [] mBuffer;
|
||||
mBufferCapacity *= 2;
|
||||
mBuffer = new char [mBufferCapacity];
|
||||
} else {
|
||||
mBufferStart = mBufferEnd = mBuffer;
|
||||
mBufferEnd += bcw;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
res = FlushBuffer(&dest, destEnd);
|
||||
|
||||
final:
|
||||
*aDestLength -= destEnd - dest;
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEncoderSupport::Reset()
|
||||
{
|
||||
mBufferStart = mBufferEnd;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEncoderSupport::SetOutputErrorBehavior(
|
||||
PRInt32 aBehavior,
|
||||
nsIUnicharEncoder * aEncoder,
|
||||
PRUnichar aChar)
|
||||
{
|
||||
if ((aBehavior == kOnError_CallBack) && (aEncoder == NULL))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_IF_RELEASE(aEncoder);
|
||||
mErrEncoder = aEncoder;
|
||||
NS_IF_ADDREF(aEncoder);
|
||||
|
||||
mErrBehavior = aBehavior;
|
||||
mErrChar = aChar;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsTableEncoderSupport [implementation]
|
||||
|
||||
nsTableEncoderSupport::nsTableEncoderSupport(uShiftTable * aShiftTable,
|
||||
uMappingTable * aMappingTable)
|
||||
: nsEncoderSupport()
|
||||
{
|
||||
mHelper = NULL;
|
||||
mShiftTable = aShiftTable;
|
||||
mMappingTable = aMappingTable;
|
||||
}
|
||||
|
||||
nsTableEncoderSupport::~nsTableEncoderSupport()
|
||||
{
|
||||
NS_IF_RELEASE(mHelper);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsTableEncoderSupport::ConvertNoBuffNoErr(
|
||||
const PRUnichar * aSrc,
|
||||
PRInt32 * aSrcLength,
|
||||
char * aDest,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
if (mHelper == nsnull) {
|
||||
res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL,
|
||||
kIUnicodeEncodeHelperIID, (void**) & mHelper);
|
||||
|
||||
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
|
||||
}
|
||||
|
||||
res = mHelper->ConvertByTable(aSrc, aSrcLength, aDest, aDestLength,
|
||||
mShiftTable, mMappingTable);
|
||||
return res;
|
||||
}
|
150
intl/uconv/ucvja2/nsUCvJa2Support.h
Normal file
150
intl/uconv/ucvja2/nsUCvJa2Support.h
Normal file
@ -0,0 +1,150 @@
|
||||
/* -*- 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 nsUCvJa2Support_h___
|
||||
#define nsUCvJa2Support_h___
|
||||
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeEncodeHelper.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEncoderSupport [declaration]
|
||||
|
||||
/**
|
||||
* Support class for the Unicode encoders.
|
||||
*
|
||||
* The class source files for this class are in /ucvlatin/nsUCvLatinSupport.
|
||||
* However, because these objects requires non-xpcom subclassing, local copies
|
||||
* will be made into the other directories using them. Just don't forget to
|
||||
* keep in sync with the master copy!
|
||||
*
|
||||
* This class implements:
|
||||
* - nsISupports
|
||||
* - the buffer management
|
||||
* - error handling procedure(s)
|
||||
*
|
||||
* @created 17/Feb/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsEncoderSupport : public nsIUnicodeEncoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Internal buffer for partial conversions.
|
||||
*/
|
||||
char * mBuffer;
|
||||
PRInt32 mBufferCapacity;
|
||||
char * mBufferStart;
|
||||
char * mBufferEnd;
|
||||
|
||||
/**
|
||||
* Error handling stuff
|
||||
*/
|
||||
PRInt32 mErrBehavior;
|
||||
nsIUnicharEncoder * mErrEncoder;
|
||||
PRUnichar mErrChar;
|
||||
|
||||
/**
|
||||
* Convert method but *without* the buffer management stuff and *with*
|
||||
* error handling stuff.
|
||||
*/
|
||||
NS_IMETHOD ConvertNoBuff(const PRUnichar * aSrc, PRInt32 * aSrcLength,
|
||||
char * aDest, PRInt32 * aDestLength);
|
||||
|
||||
/**
|
||||
* Convert method but *without* the buffer management stuff and *without*
|
||||
* error handling stuff.
|
||||
*/
|
||||
NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength,
|
||||
char * aDest, PRInt32 * aDestLength) = 0;
|
||||
|
||||
/**
|
||||
* Finish method but *without* the buffer management stuff.
|
||||
*/
|
||||
NS_IMETHOD FinishNoBuff(char * aDest, PRInt32 * aDestLength);
|
||||
|
||||
/**
|
||||
* Copy as much as possible from the internal buffer to the destination.
|
||||
*/
|
||||
NS_IMETHOD FlushBuffer(char ** aDest, const char * aDestEnd);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsEncoderSupport();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
virtual ~nsEncoderSupport();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIUnicodeEncoder [declaration]
|
||||
|
||||
NS_IMETHOD Convert(const PRUnichar * aSrc, PRInt32 * aSrcLength,
|
||||
char * aDest, PRInt32 * aDestLength);
|
||||
NS_IMETHOD Finish(char * aDest, PRInt32 * aDestLength);
|
||||
NS_IMETHOD Reset();
|
||||
NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior,
|
||||
nsIUnicharEncoder * aEncoder, PRUnichar aChar);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsTableEncoderSupport [declaration]
|
||||
|
||||
/**
|
||||
* Support class for a single-table-driven Unicode encoder.
|
||||
*
|
||||
* @created 17/Feb/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsTableEncoderSupport : public nsEncoderSupport
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsTableEncoderSupport(uShiftTable * aShiftTable,
|
||||
uMappingTable * aMappingTable);
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
virtual ~nsTableEncoderSupport();
|
||||
|
||||
protected:
|
||||
|
||||
nsIUnicodeEncodeHelper * mHelper; // encoder helper object
|
||||
uShiftTable * mShiftTable;
|
||||
uMappingTable * mMappingTable;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength,
|
||||
char * aDest, PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUCvJa2Support_h___ */
|
50
intl/uconv/ucvja2/nsUnicodeToEUCJP.cpp
Normal file
50
intl/uconv/ucvja2/nsUnicodeToEUCJP.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* -*- 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 "nsUnicodeToEUCJP.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToEUCJP [implementation]
|
||||
|
||||
nsUnicodeToEUCJP::nsUnicodeToEUCJP()
|
||||
: nsTableEncoderSupport((uShiftTable*) NULL,
|
||||
(uMappingTable*) NULL)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsUnicodeToEUCJP::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsUnicodeToEUCJP();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToEUCJP::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// XXX write me
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
57
intl/uconv/ucvja2/nsUnicodeToEUCJP.h
Normal file
57
intl/uconv/ucvja2/nsUnicodeToEUCJP.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsUnicodeToEUCJP_h___
|
||||
#define nsUnicodeToEUCJP_h___
|
||||
|
||||
#include "nsUCvJa2Support.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToEUCJP [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from Unicode to EUCJP.
|
||||
*
|
||||
* @created 17/Feb/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsUnicodeToEUCJP : public nsTableEncoderSupport
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsUnicodeToEUCJP();
|
||||
|
||||
/**
|
||||
* Static class constructor.
|
||||
*/
|
||||
static nsresult CreateInstance(nsISupports **aResult);
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToEUCJP_h___ */
|
51
intl/uconv/ucvja2/nsUnicodeToISO2022JP.cpp
Normal file
51
intl/uconv/ucvja2/nsUnicodeToISO2022JP.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- 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 "nsUnicodeToISO2022JP.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToISO2022JP [implementation]
|
||||
|
||||
nsUnicodeToISO2022JP::nsUnicodeToISO2022JP()
|
||||
: nsTableEncoderSupport((uShiftTable*) NULL,
|
||||
(uMappingTable*) NULL)
|
||||
{
|
||||
// XXX write me
|
||||
}
|
||||
|
||||
nsresult nsUnicodeToISO2022JP::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
*aResult = new nsUnicodeToISO2022JP();
|
||||
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToISO2022JP::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// XXX write me
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
57
intl/uconv/ucvja2/nsUnicodeToISO2022JP.h
Normal file
57
intl/uconv/ucvja2/nsUnicodeToISO2022JP.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* -*- 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 nsUnicodeToISO2022JP_h___
|
||||
#define nsUnicodeToISO2022JP_h___
|
||||
|
||||
#include "nsUCvJa2Support.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToISO2022JP [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from Unicode to ISO2022JP.
|
||||
*
|
||||
* @created 17/Feb/1999
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsUnicodeToISO2022JP : public nsTableEncoderSupport
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsUnicodeToISO2022JP();
|
||||
|
||||
/**
|
||||
* Static class constructor.
|
||||
*/
|
||||
static nsresult CreateInstance(nsISupports **aResult);
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToISO2022JP_h___ */
|
Loading…
x
Reference in New Issue
Block a user