remove these file. The converters are merged into ucvja

This commit is contained in:
ftang%netscape.com 1999-08-03 18:17:31 +00:00
Родитель e495f057da
Коммит 4a42fbe736
28 изменённых файлов: 0 добавлений и 21025 удалений

Просмотреть файл

@ -1 +0,0 @@
nsUCVJA2CID.h

Просмотреть файл

@ -1,51 +0,0 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = ucvja2
LIBRARY_NAME = ucvja2
IS_COMPONENT = 1
CSRCS = \
$(NULL)
CPPSRCS = \
nsEUCJPToUnicode.cpp \
nsISO2022JPToUnicode.cpp \
nsUnicodeToEUCJP.cpp \
nsUnicodeToISO2022JP.cpp \
nsUCvJa2Support.cpp \
nsUCVJA2Dll.cpp \
nsUnicodeToJISx0201.cpp \
nsUnicodeToJISx0208.cpp \
nsUnicodeToJISx0212.cpp \
$(NULL)
EXPORTS = \
nsUCVJA2CID.h \
$(NULL)
CFLAGS += -DUSE_NSREG -D__STDC__
REQUIRES = $(MODULE) libxpcom
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -1,90 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*========================================================
This is a Generated file. Please don't edit it.
The tool which used to generate this file is called fromu.
If you have any problem of this file. Please contact
Netscape Client International Team or
ftang@netscape <Frank Tang>
Table in Debug form
Begin of Item 0000
Format 0
srcBegin = 0000
srcEnd = 005B
destBegin = 0000
End of Item 0000
Begin of Item 0001
Format 0
srcBegin = 005D
srcEnd = 007D
destBegin = 005D
End of Item 0001
Begin of Item 0002
Format 0
srcBegin = FF61
srcEnd = FF9F
destBegin = 00A1
End of Item 0002
Begin of Item 0003
Format 2
srcBegin = 00A5
destBegin = 005C
End of Item 0003
Begin of Item 0004
Format 2
srcBegin = 203E
destBegin = 007E
End of Item 0004
========================================================*/
/* Offset=0x0000 ItemOfList */
0x0005,
/*-------------------------------------------------------*/
/* Offset=0x0001 offsetToFormatArray */
0x0004,
/*-------------------------------------------------------*/
/* Offset=0x0002 offsetToMapCellArray */
0x0006,
/*-------------------------------------------------------*/
/* Offset=0x0003 offsetToMappingTable */
0x0015,
/*-------------------------------------------------------*/
/* Offset=0x0004 Start of Format Array */
/* Total of Format 0 : 0x0003 */
/* Total of Format 1 : 0x0000 */
/* Total of Format 2 : 0x0002 */
/* Total of Format 3 : 0x0000 */
0x2000, 0x0002,
/*-------------------------------------------------------*/
/* Offset=0x0006 Start of MapCell Array */
/* 0000 */ 0x0000, 0x007E, 0x0000,
/* 0001 */ 0x005D, 0x007D, 0x005D,
/* 0002 */ 0xFF61, 0xFF9F, 0x00A1,
/* 0003 */ 0x00A5, 0x0000, 0x005C,
/* 0004 */ 0x203E, 0x0000, 0x007E,
/*-------------------------------------------------------*/
/* Offset=0x0015 Start of MappingTable */
/* End of table Total Length = 0x0015 * 2 */

Просмотреть файл

@ -1,90 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*========================================================
This is a Generated file. Please don't edit it.
The tool which used to generate this file is called fromu.
If you have any problem of this file. Please contact
Netscape Client International Team or
ftang@netscape <Frank Tang>
Table in Debug form
Begin of Item 0000
Format 0
srcBegin = 0000
srcEnd = 005B
destBegin = 0000
End of Item 0000
Begin of Item 0001
Format 0
srcBegin = 005D
srcEnd = 007D
destBegin = 005D
End of Item 0001
Begin of Item 0002
Format 0
srcBegin = 00A1
srcEnd = 00DF
destBegin = FF61
End of Item 0002
Begin of Item 0003
Format 2
srcBegin = 005C
destBegin = 00A5
End of Item 0003
Begin of Item 0004
Format 2
srcBegin = 007E
destBegin = 203E
End of Item 0004
========================================================*/
/* Offset=0x0000 ItemOfList */
0x0005,
/*-------------------------------------------------------*/
/* Offset=0x0001 offsetToFormatArray */
0x0004,
/*-------------------------------------------------------*/
/* Offset=0x0002 offsetToMapCellArray */
0x0006,
/*-------------------------------------------------------*/
/* Offset=0x0003 offsetToMappingTable */
0x0015,
/*-------------------------------------------------------*/
/* Offset=0x0004 Start of Format Array */
/* Total of Format 0 : 0x0003 */
/* Total of Format 1 : 0x0000 */
/* Total of Format 2 : 0x0002 */
/* Total of Format 3 : 0x0000 */
0x2000, 0x0002,
/*-------------------------------------------------------*/
/* Offset=0x0006 Start of MapCell Array */
/* 0000 */ 0x0000, 0x007E, 0x0000,
/* 0001 */ 0x005D, 0x007D, 0x005D,
/* 0002 */ 0x00A1, 0x00DF, 0xFF61,
/* 0003 */ 0x005C, 0x0000, 0x00A5,
/* 0004 */ 0x007E, 0x0000, 0x203E,
/*-------------------------------------------------------*/
/* Offset=0x0015 Start of MappingTable */
/* End of table Total Length = 0x0015 * 2 */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,85 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
DEFINES=-D_IMPL_NS_INTL -DWIN32_LEAN_AND_MEAN
MODULE=uconv
REQUIRES=xpcom uconv
MAKE_OBJ_TYPE = DLL
DLLNAME = ucvja2
DLL=.\$(OBJDIR)\$(DLLNAME).dll
CPPSRCS = \
nsEUCJPToUnicode.cpp \
nsISO2022JPToUnicode.cpp \
nsUnicodeToEUCJP.cpp \
nsUnicodeToJISx0201.cpp \
nsUnicodeToJISx0208.cpp \
nsUnicodeToJISx0212.cpp \
nsUnicodeToISO2022JP.cpp \
nsUCvJa2Support.cpp \
nsUCVJA2Dll.cpp \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsEUCJPToUnicode.obj \
.\$(OBJDIR)\nsISO2022JPToUnicode.obj \
.\$(OBJDIR)\nsUnicodeToEUCJP.obj \
.\$(OBJDIR)\nsUnicodeToJISx0201.obj \
.\$(OBJDIR)\nsUnicodeToJISx0208.obj \
.\$(OBJDIR)\nsUnicodeToJISx0212.obj \
.\$(OBJDIR)\nsUnicodeToISO2022JP.obj \
.\$(OBJDIR)\nsUCvJa2Support.obj \
.\$(OBJDIR)\nsUCVJA2Dll.obj \
$(NULL)
CSRCS = \
$(NULL)
OBJS = \
$(NULL)
LINCS= \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\uconv \
$(NULL)
EXPORTS= nsUCVJA2CID.h \
$(NULL)
LLIBS= \
$(DIST)\lib\xpcom.lib \
$(LIBNSPR)
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\bin\components\$(DLLNAME).dll
rm -f $(DIST)\lib\$(DLLNAME).lib

Просмотреть файл

@ -1,89 +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 "nsEUCJPToUnicode.h"
#include "nsUCVJA2Dll.h"
//----------------------------------------------------------------------
// Global functions and data [declaration]
// Shift Table
static PRInt16 g_0201ShiftTable[] = {
2, uMultibytesCharset,
ShiftCell(u1ByteChar, 1, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7F),
ShiftCell(u1BytePrefix8EChar, 2, 0x8E, 0x8E, 0x00, 0xA1, 0x00, 0xDF)
};
static PRInt16 g_0208ShiftTable[] = {
0, u2BytesGRCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 g_0212ShiftTable[] = {
0, u2BytesGRPrefix8FCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 *g_EUCJPShiftTable[4] = {
g_0208ShiftTable,
g_0201ShiftTable,
g_0201ShiftTable,
g_0212ShiftTable
};
static PRUint16 *g_EUCJPMappingTable[4] = {
g_ut0208Mapping,
g_ut0201Mapping,
g_ut0201Mapping,
g_ut0212Mapping
};
static uRange g_EUCJPRanges[] = {
{ 0xA1, 0xFE },
{ 0x00, 0x7F },
{ 0x8E, 0x8E },
{ 0x8F, 0x8F }
};
//----------------------------------------------------------------------
// Class nsEUCJPToUnicode [implementation]
nsEUCJPToUnicode::nsEUCJPToUnicode()
: nsMultiTableDecoderSupport(4,
(uRange *) &g_EUCJPRanges,
(uShiftTable**) &g_EUCJPShiftTable,
(uMappingTable**) &g_EUCJPMappingTable)
{
}
nsresult nsEUCJPToUnicode::CreateInstance(nsISupports ** aResult)
{
*aResult = new nsEUCJPToUnicode();
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
//----------------------------------------------------------------------
// Subclassing of nsTableDecoderSupport class [implementation]
NS_IMETHODIMP nsEUCJPToUnicode::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// worst case
*aDestLength = aSrcLength;
return NS_OK;
}

Просмотреть файл

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsEUCJPToUnicode_h___
#define nsEUCJPToUnicode_h___
#include "nsUCvJa2Support.h"
//----------------------------------------------------------------------
// Class nsEUCJPToUnicode [declaration]
/**
* A character set converter from EUCJP to Unicode.
*
* @created 24/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsEUCJPToUnicode : public nsMultiTableDecoderSupport
{
public:
/**
* Class constructor.
*/
nsEUCJPToUnicode();
/**
* Static class constructor.
*/
static nsresult CreateInstance(nsISupports **aResult);
protected:
//--------------------------------------------------------------------
// Subclassing of nsDecoderSupport class [declaration]
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
};
#endif /* nsEUCJPToUnicode_h___ */

Просмотреть файл

@ -1,258 +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 "nsIComponentManager.h"
#include "nsISO2022JPToUnicode.h"
#include "nsUCVJA2Dll.h"
//----------------------------------------------------------------------
// Global functions and data [declaration]
static PRInt16 cs1ByteShiftTable[] = {
0, u1ByteCharset ,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 cs1ByteGLShiftTable[] = {
0, u1ByteGLCharset ,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 cs2ByteShiftTable[] = {
0, u2BytesCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
//----------------------------------------------------------------------
// Class nsISO2022JPToUnicode [implementation]
nsISO2022JPToUnicode::nsISO2022JPToUnicode()
: nsBufferDecoderSupport()
{
mHelper = nsnull;
Reset();
}
nsISO2022JPToUnicode::~nsISO2022JPToUnicode()
{
NS_IF_RELEASE(mHelper);
}
nsresult nsISO2022JPToUnicode::CreateInstance(nsISupports ** aResult)
{
*aResult = new nsISO2022JPToUnicode();
return (*aResult == NULL)? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
nsresult nsISO2022JPToUnicode::ConvertBuffer(const char ** aSrc,
const char * aSrcEnd,
PRUnichar ** aDest,
PRUnichar * aDestEnd)
{
// XXX redo the logic here - are we using pointers or length ints?
const char * src = *aSrc;
PRUnichar * dest = *aDest;
PRUnichar val;
PRInt32 srcLen = aSrcEnd - src;
PRInt32 destLen = aDestEnd - dest;
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
if (mCharset == kASCII) {
// single byte
if (srcLen > destLen) {
aSrcEnd = src + destLen;
res = NS_PARTIAL_MORE_OUTPUT;
} else res = NS_OK;
// XXX use a table here too.
for (;src<aSrcEnd;) {
val = ((PRUint8)*src++);
*dest++ = (val < 0x80)?val:0xfffd;
}
} else if ((mCharset == kJISX0201_1976) || (mCharset == kJISX0201_1976Kana)){
// single byte
if (srcLen > destLen) {
aSrcEnd = src + destLen;
res = NS_PARTIAL_MORE_OUTPUT;
} else res = NS_OK;
res = mHelper->ConvertByTable(src, &srcLen, dest, &destLen,
( (mCharset == kJISX0201_1976) ?
(uShiftTable*) &cs1ByteShiftTable :
(uShiftTable*) &cs1ByteGLShiftTable),
(uMappingTable*)&g_ut0201Mapping);
*aSrc = src + srcLen;
*aDest = dest + destLen;
return res;
} else {
// XXX hello, use different tables for JIS X 0208-1978 and 1983 !!!
// double byte
if (srcLen > 2*destLen) {
aSrcEnd = src + 2*destLen;
res = NS_PARTIAL_MORE_OUTPUT;
} else if (srcLen%2) {
aSrcEnd--;
res = NS_PARTIAL_MORE_INPUT;
} else res = NS_OK;
res = mHelper->ConvertByTable(src, &srcLen, dest, &destLen,
(uShiftTable*) &cs2ByteShiftTable,
( (mCharset == kJISX0212_1990) ?
(uMappingTable*)&g_ut0212Mapping :
(uMappingTable*)&g_ut0208Mapping));
*aSrc = src + srcLen;
*aDest = dest + destLen;
return res;
}
*aSrc = src;
*aDest = dest;
return res;
}
//----------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [implementation]
NS_IMETHODIMP nsISO2022JPToUnicode::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
const char * srcEnd = aSrc + (*aSrcLength);
const char * src = aSrc;
PRUnichar * destEnd = aDest + (*aDestLength);
PRUnichar * dest = aDest;
const char * p;
nsresult res = NS_OK;
for (; ((src < srcEnd) && (res == NS_OK)); src++) {
switch (mState) {
case 0:
if (*src == 27) {
mState = 1;
} else if (dest >= destEnd) {
res = NS_PARTIAL_MORE_OUTPUT;
src--; // don't advance!
} else {
// here: src < srcEnd, dest < destEnd
// find the end of this run
for (p=src; ((p < srcEnd) && (*p != 27)); p++) {}
res = ConvertBuffer(&src, p, &dest, destEnd);
src--; // we did our own advance here
}
break;
case 1:
switch (*src) {
case '(':
mState = 2;
break;
case '$':
mState = 3;
break;
default:
res = NS_ERROR_ILLEGAL_INPUT;
}
break;
case 2:
switch (*src) {
case 'B':
mState = 0;
mCharset = kASCII;
break;
case 'J':
mState = 0;
mCharset = kJISX0201_1976;
break;
case 'I':
mState = 0;
mCharset = kJISX0201_1976Kana;
break;
default:
res = NS_ERROR_ILLEGAL_INPUT;
}
break;
case 3:
switch (*src) {
case '@':
mState = 0;
mCharset = kJISX0208_1978;
break;
case 'B':
mState = 0;
mCharset = kJISX0208_1983;
break;
case '(':
mState = 4;
break;
default:
res = NS_ERROR_ILLEGAL_INPUT;
}
break;
case 4:
switch (*src) {
case 'D':
mState = 0;
mCharset = kJISX0212_1990;
break;
default:
res = NS_ERROR_ILLEGAL_INPUT;
}
break;
default:
res = NS_ERROR_UNEXPECTED;
}
}
if ((res == NS_OK) && (mState != 0)) res = NS_PARTIAL_MORE_INPUT;
*aSrcLength = src - aSrc;
*aDestLength = dest - aDest;
return res;
}
NS_IMETHODIMP nsISO2022JPToUnicode::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// worst case
*aDestLength = aSrcLength;
return NS_OK;
}
NS_IMETHODIMP nsISO2022JPToUnicode::Reset()
{
mState = 0;
mCharset = kASCII;
return nsBufferDecoderSupport::Reset();
}

Просмотреть файл

@ -1,100 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsISO2022JPToUnicode_h___
#define nsISO2022JPToUnicode_h___
#include "nsUCvJa2Support.h"
//----------------------------------------------------------------------
// 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 + 'I' -> S0; mCharset = kJISX0201_1976Kana [Not Std ISO-2022-JP]
* S2 + * -> ERR
* S3 + '@' -> S0; mCharset = kJISX0208_1978
* S3 + 'B' -> S0; mCharset = kJISX0208_1983
* S3 + '(' -> S4; [Not Std ISO-2022-JP]
* S3 + * -> ERR
* S4 + 'D' -> S0; mCharset = kJISX0212_1990 [Not Std ISO-2022-JP]
* S4 + * -> ERR [Not Std ISO-2022-JP]
* ERR + * -> ERR
*
* @created 09/Feb/1998
* @author Catalin Rotaru [CATA]
*/
class nsISO2022JPToUnicode : public nsBufferDecoderSupport
{
public:
/**
* Class constructor.
*/
nsISO2022JPToUnicode();
/**
* Class destructor.
*/
virtual ~nsISO2022JPToUnicode();
/**
* Static class constructor.
*/
static nsresult CreateInstance(nsISupports ** aResult);
protected:
enum {
kASCII,
kJISX0201_1976,
kJISX0208_1978,
kJISX0208_1983,
kJISX0201_1976Kana, // [Not Std ISO-2022-JP]
kJISX0212_1990 // [Not Std ISO-2022-JP]
};
PRInt32 mState; // current state of the state machine
PRInt32 mCharset; // current character set
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
NS_IMETHOD ConvertBuffer(const char ** aSrc, const char * aSrcEnd,
PRUnichar ** aDest, PRUnichar * aDestEnd);
//--------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
NS_IMETHOD Reset();
};
#endif /* nsISO2022JPToUnicode_h___ */

Просмотреть файл

@ -1,61 +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 nsUCVJA2CID_h___
#define nsUCVJA2CID_h___
#include "nsISupports.h"
// Class ID for our EUCJPToUnicode charset converter
// {3F6FE6A1-AC0A-11d2-B3AE-00805F8A6670}
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);
// Class ID for our UnicodeToJISx0201 charset converter
// {BA615191-1DFA-11d3-B3BF-00805F8A6670}
NS_DECLARE_ID(kUnicodeToJISx0201CID,
0xba615191, 0x1dfa, 0x11d3, 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70);
// Class ID for our UnicodeToJISx0208 charset converter
// {BA615192-1DFA-11d3-B3BF-00805F8A6670}
NS_DECLARE_ID(kUnicodeToJISx0208CID,
0xba615192, 0x1dfa, 0x11d3, 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70);
// Class ID for our UnicodeToJISx0212 charset converter
// {BA615193-1DFA-11d3-B3BF-00805F8A6670}
NS_DECLARE_ID(kUnicodeToJISx0212CID,
0xba615193, 0x1dfa, 0x11d3, 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70);
#endif /* nsUCVJA2CID_h___ */

Просмотреть файл

@ -1,405 +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.
*/
#define NS_IMPL_IDS
#include "pratom.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIFactory.h"
#include "nsIRegistry.h"
#include "nsCOMPtr.h"
#include "nsICharsetConverterInfo.h"
#include "nsUCVJA2CID.h"
#include "nsUCVJA2Dll.h"
#include "nsEUCJPToUnicode.h"
#include "nsISO2022JPToUnicode.h"
#include "nsUnicodeToEUCJP.h"
#include "nsUnicodeToISO2022JP.h"
#include "nsUnicodeToJISx0201.h"
#include "nsUnicodeToJISx0208.h"
#include "nsUnicodeToJISx0212.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"
#define DECODER_NAME_BASE "Unicode Decoder-"
#define ENCODER_NAME_BASE "Unicode Encoder-"
//----------------------------------------------------------------------
// 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);
PRInt32 g_InstanceCount = 0;
PRInt32 g_LockCount = 0;
PRUint16 g_ut0201Mapping[] = {
#include "jis0201.ut"
};
PRUint16 g_ut0208Mapping[] = {
#include "jis0208.ut"
};
PRUint16 g_ut0212Mapping[] = {
#include "jis0212.ut"
};
PRUint16 g_uf0201Mapping[] = {
#include "jis0201.uf"
};
PRUint16 g_uf0208Mapping[] = {
#include "jis0208.uf"
};
PRUint16 g_uf0212Mapping[] = {
#include "jis0212.uf"
};
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"
},
{
&kUnicodeToEUCJPCID,
nsUnicodeToEUCJP::CreateInstance,
"Unicode",
"EUC-JP"
},
{
&kUnicodeToJISx0201CID,
nsUnicodeToJISx0201::CreateInstance,
"Unicode",
"jis_0201"
},
{
&kUnicodeToJISx0208CID,
nsUnicodeToJISx0208::CreateInstance,
"Unicode",
"jis_0208-1983"
},
{
&kUnicodeToJISx0212CID,
nsUnicodeToJISx0212::CreateInstance,
"Unicode",
"jis_0212-1990"
},
{
&kUnicodeToISO2022JPCID,
nsUnicodeToISO2022JP::CreateInstance,
"Unicode",
"ISO-2022-JP"
}
};
#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]
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr)
{
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
}
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if (aFactory == NULL) return NS_ERROR_NULL_POINTER;
nsresult res;
nsConverterFactory * fac;
FactoryData * data;
for (PRUint32 i=0; i<ARRAY_SIZE(g_FactoryData); i++) {
data = &(g_FactoryData[i]);
if (aClass.Equals(*(data->mCID))) {
fac = new nsConverterFactory(data);
res = fac->QueryInterface(kIFactoryIID, (void **) aFactory);
if (NS_FAILED(res)) {
*aFactory = NULL;
delete fac;
}
return res;
}
}
return NS_NOINTERFACE;
}
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports * aServMgr,
const char * path)
{
nsresult res;
PRUint32 i;
nsIComponentManager * compMgr = NULL;
nsIRegistry * registry = NULL;
nsIRegistry::Key key;
char buff[1024];
// get the service manager
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &res));
// get the component manager
res = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(res)) goto done;
// get the registry
res = servMgr->GetService(NS_REGISTRY_PROGID,
nsIRegistry::GetIID(),
(nsISupports**)&registry);
if (NS_FAILED(res)) goto done;
// open the registry
res = registry->OpenWellKnownRegistry(
nsIRegistry::ApplicationComponentRegistry);
if (NS_FAILED(res)) goto done;
char name[128];
char progid[128];
for (i=0; i<ARRAY_SIZE(g_FactoryData); i++) {
if(0==PL_strcmp(g_FactoryData[i].mCharsetSrc,"Unicode"))
{
PL_strcpy(name, DECODER_NAME_BASE);
PL_strcat(name, g_FactoryData[i].mCharsetDest);
PL_strcpy(progid, NS_UNICODEDECODER_PROGID_BASE);
PL_strcat(progid, g_FactoryData[i].mCharsetDest);
} else {
PL_strcpy(name, ENCODER_NAME_BASE);
PL_strcat(name, g_FactoryData[i].mCharsetSrc);
PL_strcpy(progid, NS_UNICODEENCODER_PROGID_BASE);
PL_strcat(progid, g_FactoryData[i].mCharsetSrc);
}
// register component
res = compMgr->RegisterComponent(*(g_FactoryData[i].mCID), name, progid,
path, PR_TRUE, PR_TRUE);
if(NS_FAILED(res) && (NS_ERROR_FACTORY_EXISTS != res)) goto done;
// register component info
// XXX take these KONSTANTS out of here
// XXX free the string from "ToString()"
sprintf(buff, "%s/%s", "software/netscape/intl/uconv", (g_FactoryData[i].mCID -> ToString()));
res = registry -> AddSubtree(nsIRegistry::Common, buff, &key);
if (NS_FAILED(res)) goto done;
res = registry -> SetString(key, "source", g_FactoryData[i].mCharsetSrc);
if (NS_FAILED(res)) goto done;
res = registry -> SetString(key, "destination", g_FactoryData[i].mCharsetDest);
if (NS_FAILED(res)) goto done;
}
done:
if (compMgr != NULL)
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
if (registry != NULL) {
registry -> Close();
(void)servMgr->ReleaseService(NS_REGISTRY_PROGID, registry);
}
return res;
}
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char * path)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
for (PRUint32 i=0; i<ARRAY_SIZE(g_FactoryData); i++) {
rv = compMgr->UnregisterComponent(*(g_FactoryData[i].mCID), path);
if(NS_FAILED(rv)) goto done;
}
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
//----------------------------------------------------------------------
// 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;
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);
} else {
return NS_NOINTERFACE;
}
NS_ADDREF_THIS();
return NS_OK;
}
//----------------------------------------------------------------------
// 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,36 +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 nsUCVJA2Dll_h___
#define nsUCVJA2Dll_h___
#include "prtypes.h"
extern PRInt32 g_InstanceCount;
extern PRInt32 g_LockCount;
extern PRUint16 g_ut0201Mapping[];
extern PRUint16 g_ut0208Mapping[];
extern PRUint16 g_ut0212Mapping[];
extern PRUint16 g_uf0201Mapping[];
extern PRUint16 g_uf0208Mapping[];
extern PRUint16 g_uf0212Mapping[];
#endif /* nsUCVJA2Dll_h___ */

Просмотреть файл

@ -1,731 +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 "nsIComponentManager.h"
#include "nsICharRepresentable.h"
#include "nsUCvJa2Support.h"
#include "nsUCVJA2Dll.h"
#define DEFAULT_BUFFER_CAPACITY 16
// XXX review the buffer growth limitation code
//----------------------------------------------------------------------
// Class nsBasicDecoderSupport [implementation]
nsBasicDecoderSupport::nsBasicDecoderSupport()
{
NS_INIT_REFCNT();
PR_AtomicIncrement(&g_InstanceCount);
}
nsBasicDecoderSupport::~nsBasicDecoderSupport()
{
PR_AtomicDecrement(&g_InstanceCount);
}
//----------------------------------------------------------------------
// Interface nsISupports [implementation]
NS_IMPL_ADDREF(nsBasicDecoderSupport);
NS_IMPL_RELEASE(nsBasicDecoderSupport);
nsresult nsBasicDecoderSupport::QueryInterface(REFNSIID aIID,
void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kIUnicodeDecoderIID)) {
*aInstancePtr = (void*) ((nsIUnicodeDecoder*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
//----------------------------------------------------------------------
// Interface nsIUnicodeDecoder [implementation]
NS_IMETHODIMP nsBasicDecoderSupport::Convert(PRUnichar * aDest,
PRInt32 aDestOffset,
PRInt32 * aDestLength,
const char * aSrc,
PRInt32 aSrcOffset,
PRInt32 * aSrcLength)
{
// XXX deprecated
return Convert(aSrc + aSrcOffset, aSrcLength, aDest + aDestOffset,
aDestLength);
}
NS_IMETHODIMP nsBasicDecoderSupport::Finish(PRUnichar * aDest,
PRInt32 aDestOffset,
PRInt32 * aDestLength)
{
// XXX deprecated
return NS_OK;
}
NS_IMETHODIMP nsBasicDecoderSupport::Length(const char * aSrc,
PRInt32 aSrcOffset,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// XXX deprecated
return GetMaxLength(aSrc + aSrcOffset, aSrcLength, aDestLength);
}
NS_IMETHODIMP nsBasicDecoderSupport::SetInputErrorBehavior(PRInt32 aBehavior)
{
// XXX deprecated
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [implementation]
nsBufferDecoderSupport::nsBufferDecoderSupport()
: nsBasicDecoderSupport()
{
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
mBuffer = new char[mBufferCapacity];
Reset();
}
nsBufferDecoderSupport::~nsBufferDecoderSupport()
{
delete [] mBuffer;
}
void nsBufferDecoderSupport::FillBuffer(const char ** aSrc, PRInt32 aSrcLength)
{
PRInt32 bcr = PR_MIN(mBufferCapacity - mBufferLength, aSrcLength);
memcpy(mBuffer + mBufferLength, *aSrc, bcr);
mBufferLength += bcr;
(*aSrc) += bcr;
}
void nsBufferDecoderSupport::DoubleBuffer()
{
mBufferCapacity *= 2;
char * newBuffer = new char [mBufferCapacity];
if (mBufferLength > 0) memcpy(newBuffer, mBuffer, mBufferLength);
delete [] mBuffer;
mBuffer = newBuffer;
}
//----------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [implementation]
NS_IMETHODIMP nsBufferDecoderSupport::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
// we do all operations using pointers internally
const char * src = aSrc;
const char * srcEnd = aSrc + *aSrcLength;
PRUnichar * dest = aDest;
PRUnichar * destEnd = aDest + *aDestLength;
PRInt32 bcr, bcw; // byte counts for read & write;
nsresult res = NS_OK;
// do we have some residual data from the last conversion?
if (mBufferLength > 0) if (dest == destEnd) {
res = NS_OK_UDEC_MOREOUTPUT;
} else for (;;) {
// we need new data to add to the buffer
if (src == srcEnd) {
res = NS_OK_UDEC_MOREINPUT;
break;
}
// fill that buffer
PRInt32 buffLen = mBufferLength; // initial buffer length
FillBuffer(&src, srcEnd - src);
// convert that buffer
bcr = mBufferLength;
bcw = destEnd - dest;
res = ConvertNoBuff(mBuffer, &bcr, dest, &bcw);
dest += bcw;
if ((res == NS_OK_UDEC_MOREINPUT) && (bcw == 0)) {
res = NS_ERROR_UNEXPECTED;
break;
} else {
if (bcr < buffLen) {
// we didn't convert that residual data - unfill the buffer
src -= mBufferLength - buffLen;
mBufferLength = buffLen;
} else {
// the buffer and some extra data was converted - unget the rest
src -= mBufferLength - bcr;
mBufferLength = 0;
}
break;
}
}
if (res == NS_OK) {
bcr = srcEnd - src;
bcw = destEnd - dest;
res = ConvertNoBuff(src, &bcr, dest, &bcw);
src += bcr;
dest += bcw;
// if we have partial input, store it in our internal buffer.
if (res == NS_OK_UDEC_MOREINPUT) {
bcr = srcEnd - src;
// make sure buffer is large enough
if (bcr > mBufferCapacity) {
// somehow we got into an error state and the buffer is growing out of control
res = NS_ERROR_UNEXPECTED;
} else {
FillBuffer(&src, bcr);
}
}
}
*aSrcLength -= srcEnd - src;
*aDestLength -= destEnd - dest;
return res;
}
NS_IMETHODIMP nsBufferDecoderSupport::Reset()
{
mBufferLength = 0;
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [implementation]
nsTableDecoderSupport::nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable)
: nsBufferDecoderSupport()
{
mHelper = NULL;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsTableDecoderSupport::~nsTableDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [implementation]
NS_IMETHODIMP nsTableDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByTable(aSrc, aSrcLength, aDest, aDestLength,
mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsMultiTableDecoderSupport [implementation]
nsMultiTableDecoderSupport::nsMultiTableDecoderSupport(
PRInt32 aTableCount,
uRange * aRangeArray,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
: nsBufferDecoderSupport()
{
mHelper = NULL;
mTableCount = aTableCount;
mRangeArray = aRangeArray;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsMultiTableDecoderSupport::~nsMultiTableDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [implementation]
NS_IMETHODIMP nsMultiTableDecoderSupport::ConvertNoBuff(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) &mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
}
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
mTableCount, mRangeArray, mShiftTable, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Class nsOneByteDecoderSupport [implementation]
nsOneByteDecoderSupport::nsOneByteDecoderSupport(
uShiftTable * aShiftTable,
uMappingTable * aMappingTable)
: nsBasicDecoderSupport()
{
mHelper = NULL;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsOneByteDecoderSupport::~nsOneByteDecoderSupport()
{
NS_IF_RELEASE(mHelper);
}
//----------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [implementation]
NS_IMETHODIMP nsOneByteDecoderSupport::Convert(const char * aSrc,
PRInt32 * aSrcLength,
PRUnichar * aDest,
PRInt32 * aDestLength)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeDecodeHelperCID, NULL,
kIUnicodeDecodeHelperIID, (void**) &mHelper);
if (NS_FAILED(res)) return NS_ERROR_UDEC_NOHELPER;
res = mHelper -> CreateFastTable(mShiftTable, mMappingTable, mFastTable,
ONE_BYTE_TABLE_SIZE);
if (NS_FAILED(res)) return res;
}
res = mHelper->ConvertByFastTable(aSrc, aSrcLength, aDest, aDestLength,
mFastTable, ONE_BYTE_TABLE_SIZE);
return res;
}
NS_IMETHODIMP nsOneByteDecoderSupport::GetMaxLength(const char * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// single byte to Unicode converter
*aDestLength = aSrcLength;
return NS_OK_UDEC_EXACTLENGTH;
}
NS_IMETHODIMP nsOneByteDecoderSupport::Reset()
{
// nothing to reset, no internal state in this case
return NS_OK;
}
//----------------------------------------------------------------------
// Class nsEncoderSupport [implementation]
nsEncoderSupport::nsEncoderSupport()
{
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
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;
}
nsresult 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(nsICharRepresentable::GetIID())) {
*aInstancePtr = (void*) ((nsICharRepresentable*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)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 = mBuffer;
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);
}
NS_IMETHODIMP nsTableEncoderSupport::FillInfo(PRUint32 *aInfo)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL,
kIUnicodeEncodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
}
res = mHelper->FillInfo(aInfo, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// 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;
}
//----------------------------------------------------------------------
// Class nsMultiTableEncoderSupport [implementation]
nsMultiTableEncoderSupport::nsMultiTableEncoderSupport(
PRInt32 aTableCount,
uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable)
: nsEncoderSupport()
{
mHelper = NULL;
mTableCount = aTableCount;
mShiftTable = aShiftTable;
mMappingTable = aMappingTable;
}
nsMultiTableEncoderSupport::~nsMultiTableEncoderSupport()
{
NS_IF_RELEASE(mHelper);
}
NS_IMETHODIMP nsMultiTableEncoderSupport::FillInfo(PRUint32 *aInfo)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL,
kIUnicodeEncodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
}
res = mHelper->FillInfo(aInfo,mTableCount, mMappingTable);
return res;
}
//----------------------------------------------------------------------
// Subclassing of nsEncoderSupport class [implementation]
NS_IMETHODIMP nsMultiTableEncoderSupport::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->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
mTableCount, mShiftTable, mMappingTable);
return res;
}

Просмотреть файл

@ -1,417 +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 nsUCvJa2Support_h___
#define nsUCvJa2Support_h___
#include "nsIUnicodeEncoder.h"
#include "nsIUnicodeDecoder.h"
#include "nsIUnicodeEncodeHelper.h"
#include "nsIUnicodeDecodeHelper.h"
#include "nsICharRepresentable.h"
#define ONE_BYTE_TABLE_SIZE 256
//----------------------------------------------------------------------
// Class nsBasicDecoderSupport [declaration]
/**
* Support class for the Unicode decoders.
*
* The class source files for this class are in /ucvlatin/nsUCvLatinSupport.
* However, because these objects requires non-xpcom subclassing, local copies
* 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
* - nsIUnicodeDecoder
*
* @created 19/Apr/1999
* @author Catalin Rotaru [CATA]
*/
class nsBasicDecoderSupport : public nsIUnicodeDecoder
{
NS_DECL_ISUPPORTS
public:
/**
* Class constructor.
*/
nsBasicDecoderSupport();
/**
* Class destructor.
*/
virtual ~nsBasicDecoderSupport();
//--------------------------------------------------------------------
// Interface nsIUnicodeDecoder [declaration]
// XXX delete when interface change, this is already declared in the new one
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength) = 0;
// XXX deprecated methods - to go away when interface change.
NS_IMETHOD Convert(PRUnichar * aDest, PRInt32 aDestOffset,
PRInt32 * aDestLength, const char * aSrc, PRInt32 aSrcOffset,
PRInt32 * aSrcLength);
NS_IMETHOD Finish(PRUnichar * aDest, PRInt32 aDestOffset,
PRInt32 * aDestLength);
NS_IMETHOD Length(const char * aSrc, PRInt32 aSrcOffset,
PRInt32 aSrcLength, PRInt32 * aDestLength);
NS_IMETHOD SetInputErrorBehavior(PRInt32 aBehavior);
};
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [declaration]
/**
* Support class for the Unicode decoders.
*
* This class implements:
* - the buffer management
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsBufferDecoderSupport : public nsBasicDecoderSupport
{
protected:
/**
* Internal buffer for partial conversions.
*/
char * mBuffer;
PRInt32 mBufferCapacity;
PRInt32 mBufferLength;
/**
* Convert method but *without* the buffer management stuff.
*/
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
void FillBuffer(const char ** aSrc, PRInt32 aSrcLength);
void DoubleBuffer();
public:
/**
* Class constructor.
*/
nsBufferDecoderSupport();
/**
* Class destructor.
*/
virtual ~nsBufferDecoderSupport();
//--------------------------------------------------------------------
// Interface nsIUnicodeDecoder [declaration]
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD Reset();
};
//----------------------------------------------------------------------
// Class nsTableDecoderSupport [declaration]
/**
* Support class for a single-table-driven Unicode decoder.
*
* @created 15/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsTableDecoderSupport : public nsBufferDecoderSupport
{
public:
/**
* Class constructor.
*/
nsTableDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
/**
* Class destructor.
*/
virtual ~nsTableDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
uShiftTable * mShiftTable;
uMappingTable * mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsMultiTableDecoderSupport [declaration]
/**
* Support class for a multi-table-driven Unicode decoder.
*
* @created 24/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsMultiTableDecoderSupport : public nsBufferDecoderSupport
{
public:
/**
* Class constructor.
*/
nsMultiTableDecoderSupport(PRInt32 aTableCount, uRange * aRangeArray,
uShiftTable ** aShiftTable, uMappingTable ** aMappingTable);
/**
* Class destructor.
*/
virtual ~nsMultiTableDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
PRInt32 mTableCount;
uRange * mRangeArray;
uShiftTable ** mShiftTable;
uMappingTable ** mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsBufferDecoderSupport class [declaration]
NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
};
//----------------------------------------------------------------------
// Class nsBufferDecoderSupport [declaration]
/**
* Support class for a single-byte Unicode decoder.
*
* @created 19/Apr/1999
* @author Catalin Rotaru [CATA]
*/
class nsOneByteDecoderSupport : public nsBasicDecoderSupport
{
public:
/**
* Class constructor.
*/
nsOneByteDecoderSupport(uShiftTable * aShiftTable,
uMappingTable * aMappingTable);
/**
* Class destructor.
*/
virtual ~nsOneByteDecoderSupport();
protected:
nsIUnicodeDecodeHelper * mHelper; // decoder helper object
uShiftTable * mShiftTable;
uMappingTable * mMappingTable;
PRUnichar mFastTable[ONE_BYTE_TABLE_SIZE];
//--------------------------------------------------------------------
// Subclassing of nsBasicDecoderSupport class [declaration]
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
NS_IMETHOD Reset();
};
//----------------------------------------------------------------------
// Class nsEncoderSupport [declaration]
/**
* Support class for the Unicode encoders.
*
* This class implements:
* - nsISupports
* - the buffer management
* - error handling procedure(s)
*
* @created 17/Feb/1999
* @author Catalin Rotaru [CATA]
*/
class nsEncoderSupport : public nsIUnicodeEncoder, public nsICharRepresentable
{
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.
*/
nsresult 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);
//--------------------------------------------------------------------
// Interface nsICharRepresentable [declaration]
NS_IMETHOD FillInfo(PRUint32 *aInfo) = 0;
};
//----------------------------------------------------------------------
// 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();
NS_IMETHOD FillInfo( PRUint32 *aInfo);
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);
};
//----------------------------------------------------------------------
// Class nsMultiTableEncoderSupport [declaration]
/**
* Support class for a multi-table-driven Unicode encoder.
*
* @created 11/Mar/1999
* @author Catalin Rotaru [CATA]
*/
class nsMultiTableEncoderSupport : public nsEncoderSupport
{
public:
/**
* Class constructor.
*/
nsMultiTableEncoderSupport(PRInt32 aTableCount, uShiftTable ** aShiftTable,
uMappingTable ** aMappingTable);
/**
* Class destructor.
*/
virtual ~nsMultiTableEncoderSupport();
NS_IMETHOD FillInfo( PRUint32 *aInfo);
protected:
nsIUnicodeEncodeHelper * mHelper; // encoder helper object
PRInt32 mTableCount;
uShiftTable ** mShiftTable;
uMappingTable ** mMappingTable;
//--------------------------------------------------------------------
// Subclassing of nsEncoderSupport class [declaration]
NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength,
char * aDest, PRInt32 * aDestLength);
};
#endif /* nsUCvJa2Support_h___ */

Просмотреть файл

@ -1,84 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsUnicodeToEUCJP.h"
#include "nsUCVJA2Dll.h"
//----------------------------------------------------------------------
// Global functions and data [declaration]
// Shift Table
static PRInt16 g0201ShiftTable[] = {
2, uMultibytesCharset,
ShiftCell(u1ByteChar, 1, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7F),
ShiftCell(u1BytePrefix8EChar, 2, 0x8E, 0x8E, 0x00, 0xA1, 0x00, 0xDF)
};
static PRInt16 g0208ShiftTable[] = {
0, u2BytesGRCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 g0212ShiftTable[] = {
0, u2BytesGRPrefix8FCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 *gShiftTables[4] = {
g0208ShiftTable,
g0201ShiftTable,
g0201ShiftTable,
g0212ShiftTable
};
static PRUint16 *gMappingTables[4] = {
g_uf0208Mapping,
g_uf0201Mapping,
g_uf0201Mapping,
g_uf0212Mapping
};
//----------------------------------------------------------------------
// Class nsUnicodeToEUCJP [implementation]
nsUnicodeToEUCJP::nsUnicodeToEUCJP()
: nsMultiTableEncoderSupport(4,
(uShiftTable**) gShiftTables,
(uMappingTable**) gMappingTables)
{
}
nsresult nsUnicodeToEUCJP::CreateInstance(nsISupports ** aResult)
{
nsIUnicodeEncoder *p = new nsUnicodeToEUCJP();
if(p) {
*aResult = p;
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
//----------------------------------------------------------------------
// Subclassing of nsTableEncoderSupport class [implementation]
NS_IMETHODIMP nsUnicodeToEUCJP::GetMaxLength(const PRUnichar * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
*aDestLength = 3*aSrcLength;
return NS_OK;
}

Просмотреть файл

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef 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 nsMultiTableEncoderSupport
{
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___ */

Просмотреть файл

@ -1,223 +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 "nsUnicodeToISO2022JP.h"
#include "nsIComponentManager.h"
#include "nsUCVJA2Dll.h"
//----------------------------------------------------------------------
// Global functions and data [declaration]
static PRUint16 g_ufAsciiMapping [] = {
0x0001, 0x0004, 0x0005, 0x0008, 0x0000, 0x0000, 0x007F, 0x0000
};
static PRInt16 g_ufAsciiShift [] = {
0, u1ByteCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRInt16 g_uf0201Shift [] = {
2, u1ByteCharset ,
ShiftCell(u1ByteChar, 1, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7F),
ShiftCell(u1ByteChar, 1, 0xA1, 0xDF, 0x00, 0xA1, 0x00, 0xDF),
};
static PRInt16 g_uf0208Shift [] = {
0, u2BytesCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
static PRUint16 * g_ufMappingTables[4] = {
g_ufAsciiMapping,
g_uf0201Mapping,
g_uf0208Mapping,
g_uf0208Mapping,
};
static PRInt16 * g_ufShiftTables[4] = {
g_ufAsciiShift,
g_uf0201Shift,
g_uf0208Shift,
g_uf0208Shift,
};
//----------------------------------------------------------------------
// Class nsUnicodeToISO2022JP [implementation]
nsUnicodeToISO2022JP::nsUnicodeToISO2022JP()
: nsEncoderSupport()
{
mHelper = NULL;
Reset();
}
nsUnicodeToISO2022JP::~nsUnicodeToISO2022JP()
{
NS_IF_RELEASE(mHelper);
}
nsresult nsUnicodeToISO2022JP::CreateInstance(nsISupports ** aResult)
{
nsIUnicodeEncoder *p = new nsUnicodeToISO2022JP();
if(p) {
*aResult = p;
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult nsUnicodeToISO2022JP::ChangeCharset(PRInt32 aCharset,
char * aDest,
PRInt32 * aDestLength)
{
if (aCharset == mCharset) {
*aDestLength = 0;
return NS_OK;
}
if (*aDestLength < 3) {
*aDestLength = 0;
return NS_OK_UENC_MOREOUTPUT;
}
switch (aCharset) {
case 0:
aDest[0] = 0x1b;
aDest[1] = '(';
aDest[2] = 'B';
break;
case 1:
aDest[0] = 0x1b;
aDest[1] = '(';
aDest[2] = 'J';
break;
case 2:
aDest[0] = 0x1b;
aDest[1] = '$';
aDest[2] = 'B';
break;
case 3:
aDest[0] = 0x1b;
aDest[1] = '$';
aDest[2] = '@';
break;
}
mCharset = aCharset;
*aDestLength = 3;
return NS_OK;
}
//----------------------------------------------------------------------
// Subclassing of nsTableEncoderSupport class [implementation]
NS_IMETHODIMP nsUnicodeToISO2022JP::FillInfo(PRUint32* aInfo)
{
nsresult res;
if (mHelper == nsnull) {
res = nsComponentManager::CreateInstance(kUnicodeEncodeHelperCID, NULL,
kIUnicodeEncodeHelperIID, (void**) & mHelper);
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
}
return mHelper->FillInfo(aInfo, 4, (uMappingTable **) g_ufMappingTables);
}
NS_IMETHODIMP nsUnicodeToISO2022JP::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;
}
const PRUnichar * src = aSrc;
const PRUnichar * srcEnd = aSrc + *aSrcLength;
char * dest = aDest;
char * destEnd = aDest + *aDestLength;
PRInt32 bcr, bcw;
PRInt32 i;
while (src < srcEnd) {
for (i=0; i<4; i++) {
bcr = 1;
bcw = destEnd - dest;
res = mHelper->ConvertByTable(src, &bcr, dest, &bcw,
(uShiftTable *) g_ufShiftTables[i],
(uMappingTable *) g_ufMappingTables[i]);
if (res != NS_ERROR_UENC_NOMAPPING) break;
}
if (i>=4) res = NS_ERROR_UENC_NOMAPPING;
if (res != NS_OK) break;
bcw = destEnd - dest;
res = ChangeCharset(i, dest, &bcw);
dest += bcw;
if (res != NS_OK) break;
bcr = srcEnd - src;
bcw = destEnd - dest;
res = mHelper->ConvertByTable(src, &bcr, dest, &bcw,
(uShiftTable *) g_ufShiftTables[i],
(uMappingTable *) g_ufMappingTables[i]);
src += bcr;
dest += bcw;
if ((res != NS_OK) && (res != NS_ERROR_UENC_NOMAPPING)) break;
if (res == NS_ERROR_UENC_NOMAPPING) src--;
}
*aSrcLength = src - aSrc;
*aDestLength = dest - aDest;
return res;
}
NS_IMETHODIMP nsUnicodeToISO2022JP::FinishNoBuff(char * aDest,
PRInt32 * aDestLength)
{
ChangeCharset(0, aDest, aDestLength);
return NS_OK;
}
NS_IMETHODIMP nsUnicodeToISO2022JP::GetMaxLength(const PRUnichar * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
// worst case
// 1 2 3 4 5 6 7 8
// ESC $ B XX XX ESC ( B
*aDestLength = 8*aSrcLength;
return NS_OK;
}
NS_IMETHODIMP nsUnicodeToISO2022JP::Reset()
{
mCharset = 0;
return nsEncoderSupport::Reset();
}

Просмотреть файл

@ -1,73 +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 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 nsEncoderSupport
{
public:
/**
* Class constructor.
*/
nsUnicodeToISO2022JP();
/**
* Class destructor.
*/
virtual ~nsUnicodeToISO2022JP();
/**
* Static class constructor.
*/
static nsresult CreateInstance(nsISupports **aResult);
protected:
PRInt32 mCharset; // current character set
nsIUnicodeEncodeHelper * mHelper; // encoder helper object
nsresult ChangeCharset(PRInt32 aCharset, char * aDest,
PRInt32 * aDestLength);
//--------------------------------------------------------------------
// Subclassing of nsEncoderSupport class [declaration]
NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength,
char * aDest, PRInt32 * aDestLength);
NS_IMETHOD FinishNoBuff(char * aDest, PRInt32 * aDestLength);
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
PRInt32 * aDestLength);
NS_IMETHOD Reset();
NS_IMETHOD FillInfo(PRUint32 *aInfo);
};
#endif /* nsUnicodeToISO2022JP_h___ */

Просмотреть файл

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsUnicodeToJISx0201.h"
#include "nsUCVJA2Dll.h"
// Shift Table
static PRInt16 g0201ShiftTable[] = {
1, u1ByteCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
//----------------------------------------------------------------------
// Class nsUnicodeToJISx0201 [implementation]
nsUnicodeToJISx0201::nsUnicodeToJISx0201()
: nsTableEncoderSupport((uShiftTable*) g0201ShiftTable,
(uMappingTable*) g_uf0201Mapping)
{
}
nsresult nsUnicodeToJISx0201::CreateInstance(nsISupports ** aResult)
{
nsIUnicodeEncoder *p = new nsUnicodeToJISx0201();
if(p) {
*aResult = p;
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
//----------------------------------------------------------------------
// Subclassing of nsTableEncoderSupport class [implementation]
NS_IMETHODIMP nsUnicodeToJISx0201::GetMaxLength(const PRUnichar * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
*aDestLength = aSrcLength;
return NS_OK_UENC_EXACTLENGTH;
}

Просмотреть файл

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsUnicodeToJISx0201_h___
#define nsUnicodeToJISx0201_h___
#include "nsUCvJa2Support.h"
//----------------------------------------------------------------------
// Class nsUnicodeToJISx0201 [declaration]
/**
* A character set converter from Unicode to JISx0201.
*
* @created 17/Feb/1999
* @author Catalin Rotaru [CATA]
*/
class nsUnicodeToJISx0201 : public nsTableEncoderSupport
{
public:
/**
* Class constructor.
*/
nsUnicodeToJISx0201();
/**
* 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 /* nsUnicodeToJISx0201_h___ */

Просмотреть файл

@ -1,58 +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 "nsUnicodeToJISx0208.h"
#include "nsUCVJA2Dll.h"
//----------------------------------------------------------------------
// Global functions and data [declaration]
static PRInt16 g0208ShiftTable[] = {
0, u2BytesCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
//----------------------------------------------------------------------
// Class nsUnicodeToJISx0208 [implementation]
nsUnicodeToJISx0208::nsUnicodeToJISx0208()
: nsTableEncoderSupport( (uShiftTable*) g0208ShiftTable,
(uMappingTable*) g_uf0208Mapping)
{
}
nsresult nsUnicodeToJISx0208::CreateInstance(nsISupports ** aResult)
{
nsIUnicodeEncoder *p = new nsUnicodeToJISx0208();
if(p) {
*aResult = p;
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
//----------------------------------------------------------------------
// Subclassing of nsTableEncoderSupport class [implementation]
NS_IMETHODIMP nsUnicodeToJISx0208::GetMaxLength(const PRUnichar * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
*aDestLength = 2*aSrcLength;
return NS_OK_UENC_EXACTLENGTH;
}

Просмотреть файл

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsUnicodeToJISx0208_h___
#define nsUnicodeToJISx0208_h___
#include "nsUCvJa2Support.h"
//----------------------------------------------------------------------
// Class nsUnicodeToJISx0208 [declaration]
/**
* A character set converter from Unicode to JISx0208.
*
* @created 17/Feb/1999
* @author Catalin Rotaru [CATA]
*/
class nsUnicodeToJISx0208 : public nsTableEncoderSupport
{
public:
/**
* Class constructor.
*/
nsUnicodeToJISx0208();
/**
* 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 /* nsUnicodeToJISx0208_h___ */

Просмотреть файл

@ -1,58 +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 "nsUnicodeToJISx0212.h"
#include "nsUCVJA2Dll.h"
//----------------------------------------------------------------------
// Global functions and data [declaration]
static PRInt16 g0212ShiftTable[] = {
0, u2BytesCharset,
ShiftCell(0,0,0,0,0,0,0,0)
};
//----------------------------------------------------------------------
// Class nsUnicodeToJISx0212 [implementation]
nsUnicodeToJISx0212::nsUnicodeToJISx0212()
: nsTableEncoderSupport((uShiftTable*) g0212ShiftTable,
(uMappingTable*) g_uf0212Mapping)
{
}
nsresult nsUnicodeToJISx0212::CreateInstance(nsISupports ** aResult)
{
nsIUnicodeEncoder *p = new nsUnicodeToJISx0212();
if(p) {
*aResult = p;
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
//----------------------------------------------------------------------
// Subclassing of nsTableEncoderSupport class [implementation]
NS_IMETHODIMP nsUnicodeToJISx0212::GetMaxLength(const PRUnichar * aSrc,
PRInt32 aSrcLength,
PRInt32 * aDestLength)
{
*aDestLength = 2*aSrcLength;
return NS_OK_UENC_EXACTLENGTH;
}

Просмотреть файл

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsUnicodeToJISx0212_h___
#define nsUnicodeToJISx0212_h___
#include "nsUCvJa2Support.h"
//----------------------------------------------------------------------
// Class nsUnicodeToJISx0212 [declaration]
/**
* A character set converter from Unicode to JISx0212.
*
* @created 17/Feb/1999
* @author Catalin Rotaru [CATA]
*/
class nsUnicodeToJISx0212 : public nsTableEncoderSupport
{
public:
/**
* Class constructor.
*/
nsUnicodeToJISx0212();
/**
* 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 /* nsUnicodeToJISx0212_h___ */