fix for bug 157993 - combine all unicode converters into a single library, and share GetMaxLength() implementation between all converters that can support it.
r=ftang, sr=blizzard git-svn-id: svn://10.0.0.236/trunk@127085 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
e7fe936876
commit
444f4eaea3
@ -1748,13 +1748,6 @@ sub BuildInternationalProjects()
|
||||
|
||||
BuildOneProject(":mozilla:intl:chardet:macbuild:chardet.xml", "chardet$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:uconv.xml", "uconv$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:ucvlatin.xml", "ucvlatin$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:ucvja.xml", "ucvja$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:ucvtw.xml", "ucvtw$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:ucvtw2.xml", "ucvtw2$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:ucvcn.xml", "ucvcn$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:ucvko.xml", "ucvko$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:ucvibm.xml", "ucvibm$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
if ($main::options{mathml})
|
||||
{
|
||||
BuildOneProject(":mozilla:intl:uconv:macbuild:ucvmath.xml", "ucvmath$D.$S", 1, $main::ALIAS_SYM_FILES, 1);
|
||||
|
||||
@ -209,19 +209,10 @@ Components:uconv.xpt
|
||||
Components:lwbrk.shlb
|
||||
Components:nslocale.shlb
|
||||
Components:nslocale.xpt
|
||||
Components:ucvlatin.shlb
|
||||
Components:chardet.shlb
|
||||
Components:chardet.xpt
|
||||
Components:Universalchardet.shlb
|
||||
|
||||
; optional - on english only systems
|
||||
; Components:ucvja.shlb for japanese
|
||||
; Components:ucvko.shlb for korean
|
||||
; Components:ucvcn.shlb for simplified chinese
|
||||
; Components:ucvtw.shlb for traditional chinese
|
||||
; Components:ucvtw2.shlb for traditional chinese
|
||||
; Components:ucvibm.shlb for ibm
|
||||
|
||||
|
||||
res:language.properties
|
||||
res:langGroups.properties
|
||||
|
||||
@ -209,19 +209,10 @@ Components:uconv.xpt
|
||||
Components:lwbrkDebug.shlb
|
||||
Components:nslocaleDebug.shlb
|
||||
Components:nslocale.xpt
|
||||
Components:ucvlatinDebug.shlb
|
||||
Components:chardetDebug.shlb
|
||||
Components:chardet.xpt
|
||||
Components:UniversalchardetDebug.shlb
|
||||
|
||||
; optional - on english only systems
|
||||
; Components:ucvjaDebug.shlb for japanese
|
||||
; Components:ucvkoDebug.shlb for korean
|
||||
; Components:ucvcnDebug.shlb for simplified chinese
|
||||
; Components:ucvtwDebug.shlb for traditional chinese
|
||||
; Components:ucvtw2Debug.shlb for traditional chinese
|
||||
; Components:ucvibmDebug.shlb for ibm
|
||||
|
||||
|
||||
res:language.properties
|
||||
res:langGroups.properties
|
||||
|
||||
@ -198,17 +198,8 @@ components/libuconv.dylib
|
||||
components/uconv.xpt
|
||||
components/liblwbrk.dylib
|
||||
components/libnslocale.dylib
|
||||
components/libucvlatin.dylib
|
||||
components/unicharutil.xpt
|
||||
components/libchardet.dylib
|
||||
; optional - on english only systems
|
||||
; components/libucvja.dylib for japanese
|
||||
; components/libucvko.dylib for korean
|
||||
; components/libucvcn.dylib for simplified chinese
|
||||
; components/libucvtw.dylib for traditional chinese
|
||||
; components/libucvtw2.dylib for traditional chinese
|
||||
; components/libucvibm.dylib for ibm
|
||||
|
||||
|
||||
res/language.properties
|
||||
res/langGroups.properties
|
||||
|
||||
@ -141,16 +141,8 @@ components/libuconv.so
|
||||
components/uconv.xpt
|
||||
components/liblwbrk.so
|
||||
components/libnslocale.so
|
||||
components/libucvlatin.so
|
||||
components/unicharutil.xpt
|
||||
components/libchardet.so
|
||||
; optional - on english only systems
|
||||
; components/libucvja.so for japanese
|
||||
; components/libucvko.so for korean
|
||||
; components/libucvcn.so for simplified chinese
|
||||
; components/libucvtw.so for traditional chinese
|
||||
; components/libucvtw2.so for traditional chinese
|
||||
; components/libucvibm.so for ibm
|
||||
|
||||
; required i18n libs
|
||||
components/libstrres.so
|
||||
|
||||
@ -149,16 +149,8 @@ components\uconv.dll
|
||||
components\uconv.xpt
|
||||
components\lwbrk.dll
|
||||
components\nslocale.dll
|
||||
components\ucvlatin.dll
|
||||
components\unicharutil.xpt
|
||||
components\chardet.dll
|
||||
; optional - on english only systems
|
||||
; components\ucvja.dll for japanese
|
||||
; components\ucvko.dll for korean
|
||||
; components\ucvcn.dll for simplified chinese
|
||||
; components\ucvtw.dll for traditional chinese
|
||||
; components\ucvtw2.dll for traditional chinese
|
||||
; components\ucvibm.dll for ibm
|
||||
|
||||
; required i18n libs
|
||||
components\strres.dll
|
||||
|
||||
@ -38,7 +38,7 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = idl public src ucvja ucvcn ucvlatin ucvtw ucvtw2 ucvko ucvibm
|
||||
DIRS = idl public util ucvja ucvcn ucvlatin ucvtw ucvtw2 ucvko ucvibm src
|
||||
|
||||
ifdef MOZ_MATHML
|
||||
DIRS += ucvmath
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -67,7 +67,6 @@ CPPSRCS = \
|
||||
nsUnicodeToCP1252.cpp \
|
||||
nsUnicodeToMacRoman.cpp \
|
||||
nsUnicodeToUTF8.cpp \
|
||||
nsUCvMinSupport.cpp \
|
||||
nsScriptableUConv.cpp \
|
||||
nsConverterInputStream.cpp \
|
||||
$(NULL)
|
||||
@ -120,6 +119,28 @@ ifneq (,$(filter cocoa mac, $(MOZ_WIDGET_TOOLKIT)))
|
||||
EXTRA_DSO_LDOPTS += $(TK_LIBS)
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDES = -I$(srcdir)/../util \
|
||||
-I$(srcdir)/../ucvlatin \
|
||||
-I$(srcdir)/../ucvibm \
|
||||
-I$(srcdir)/../ucvja \
|
||||
-I$(srcdir)/../ucvtw2 \
|
||||
-I$(srcdir)/../ucvtw \
|
||||
-I$(srcdir)/../ucvko \
|
||||
-I$(srcdir)/../ucvcn \
|
||||
$(NULL)
|
||||
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvutil_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvlatin_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvibm_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvutil_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvja_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvtw2_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvtw_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvko_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ucvcn_s.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# Reserved name __STDC__ cannot be defined as a macro name on AIX or OpenVMS.
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsCP1252ToUnicode.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsISO88591ToUnicode.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsMacRomanToUnicode.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -56,18 +56,7 @@ static const PRInt16 g_MacRomanShiftTable[] = {
|
||||
|
||||
nsMacRomanToUnicode::nsMacRomanToUnicode()
|
||||
: nsTableDecoderSupport((uShiftTable*) &g_MacRomanShiftTable,
|
||||
(uMappingTable*) &g_MacRomanMappingTable)
|
||||
(uMappingTable*) &g_MacRomanMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableDecoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsMacRomanToUnicode::GetMaxLength(const char * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// we are a single byte to Unicode converter, so...
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UDEC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -69,11 +69,6 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsDecoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsMacRomanToUnicode_h___ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,733 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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 the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsICharRepresentable.h"
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUConvDll.h"
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kUnicodeEncodeHelperCID, NS_UNICODEENCODEHELPER_CID);
|
||||
static NS_DEFINE_CID(kUnicodeDecodeHelperCID, NS_UNICODEDECODEHELPER_CID);
|
||||
|
||||
#define DEFAULT_BUFFER_CAPACITY 16
|
||||
|
||||
// XXX review the buffer growth limitation code
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsBasicDecoderSupport [implementation]
|
||||
|
||||
nsBasicDecoderSupport::nsBasicDecoderSupport()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasicDecoderSupport::~nsBasicDecoderSupport()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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(NS_GET_IID(nsIUnicodeDecoder))) {
|
||||
*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]
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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;
|
||||
#if defined(DEBUG_yokoyama) || defined(DEBUG_ftang)
|
||||
NS_ASSERTION(0, "This should not happen. Internal buffer may be corrupted.");
|
||||
#endif
|
||||
break;
|
||||
} else {
|
||||
if (bcr < buffLen) {
|
||||
// we didn't convert that residual data - unfill the buffer
|
||||
src -= mBufferLength - buffLen;
|
||||
mBufferLength = buffLen;
|
||||
#if defined(DEBUG_yokoyama) || defined(DEBUG_ftang)
|
||||
NS_ASSERTION(0, "This should not happen. Internal buffer may be corrupted.");
|
||||
#endif
|
||||
} else {
|
||||
// the buffer and some extra data was converted - unget the rest
|
||||
src -= mBufferLength - bcr;
|
||||
mBufferLength = 0;
|
||||
res = NS_OK;
|
||||
}
|
||||
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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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 nsBasicEncoder [implementation]
|
||||
nsBasicEncoder::nsBasicEncoder()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasicEncoder::~nsBasicEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsBasicEncoder);
|
||||
NS_IMPL_RELEASE(nsBasicEncoder);
|
||||
|
||||
nsresult nsBasicEncoder::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(NS_GET_IID(nsICharRepresentable))) {
|
||||
*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;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEncoderSupport [implementation]
|
||||
|
||||
nsEncoderSupport::nsEncoderSupport()
|
||||
{
|
||||
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
|
||||
mBuffer = new char[mBufferCapacity];
|
||||
|
||||
mErrBehavior = kOnError_Signal;
|
||||
mErrChar = 0;
|
||||
mErrEncoder = NULL;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsEncoderSupport::~nsEncoderSupport()
|
||||
{
|
||||
delete [] mBuffer;
|
||||
NS_IF_RELEASE(mErrEncoder);
|
||||
}
|
||||
|
||||
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 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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (void**) & mHelper);
|
||||
|
||||
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
|
||||
}
|
||||
|
||||
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
|
||||
mTableCount, mShiftTable, mMappingTable);
|
||||
return res;
|
||||
}
|
||||
@ -1,433 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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 the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsUCvMinSupport_h___
|
||||
#define nsUCvMinSupport_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.
|
||||
*
|
||||
* 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]
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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 nsBasicEncoder [declaration]
|
||||
|
||||
class nsBasicEncoder : public nsIUnicodeEncoder, public nsICharRepresentable
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsBasicEncoder();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
virtual ~nsBasicEncoder();
|
||||
|
||||
};
|
||||
//----------------------------------------------------------------------
|
||||
// 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 nsBasicEncoder
|
||||
{
|
||||
|
||||
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 /* nsUCvMinSupport_h___ */
|
||||
@ -36,7 +36,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsUTF8ToUnicode.h"
|
||||
|
||||
NS_IMETHODIMP NS_NewUTF8ToUnicode(nsISupports* aOuter,
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsUnicodeToCP1252.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -56,17 +56,7 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
|
||||
nsUnicodeToCP1252::nsUnicodeToCP1252()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToCP1252::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -67,13 +67,6 @@ public:
|
||||
*/
|
||||
nsUnicodeToCP1252();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToCP1252_h___ */
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsUnicodeToISO88591.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -56,18 +56,7 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
|
||||
nsUnicodeToISO88591::nsUnicodeToISO88591()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToISO88591::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
|
||||
@ -67,13 +67,5 @@ public:
|
||||
*/
|
||||
nsUnicodeToISO88591();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToISO88591_h___ */
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsUnicodeToMacRoman.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -56,17 +56,7 @@ static const PRInt16 g_MacRomanShiftTable[] = {
|
||||
|
||||
nsUnicodeToMacRoman::nsUnicodeToMacRoman()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_MacRomanShiftTable,
|
||||
(uMappingTable*) &g_MacRomanMappingTable)
|
||||
(uMappingTable*) &g_MacRomanMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToMacRoman::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -64,13 +64,6 @@ public:
|
||||
*/
|
||||
nsUnicodeToMacRoman();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToMacRoman_h___ */
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
#include "nsUCvMinSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsUnicodeToUTF8.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ include $(topsrcdir)/config/rules.mk
|
||||
INCLUDES += \
|
||||
-I$(srcdir)/../ucvlatin \
|
||||
-I$(srcdir)/../ucvja \
|
||||
-I$(srcdir)/../util \
|
||||
$(NULL)
|
||||
|
||||
LIBS += \
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsICharsetConverterManager2.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsString.h"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@ -211,8 +212,18 @@ nsresult nsTestUConv::TestEncoders()
|
||||
mLog.AddTrace(trace);
|
||||
nsresult res = NS_OK;
|
||||
|
||||
// XXX write me
|
||||
nsCOMPtr<nsICharsetConverterManager2> ccMan =
|
||||
do_GetService(kCharsetConverterManagerCID, &res);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> encoders;
|
||||
res = ccMan->GetEncoderList(getter_AddRefs(encoders));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
PRUint32 encoderCount;
|
||||
encoders->Count(&encoderCount);
|
||||
printf("There are %d encoders\n", encoderCount);
|
||||
|
||||
mLog.DelTrace(trace);
|
||||
return res;
|
||||
}
|
||||
@ -385,6 +396,9 @@ nsresult nsTestUConv::DisplayCharsets()
|
||||
|
||||
printf("***** Character Sets [%d] *****\n", count);
|
||||
|
||||
PRUint32 encCount = 0, decCount = 0;
|
||||
PRUint32 basicEncCount = 0, basicDecCount = 0;
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIAtom> cs;
|
||||
nsAutoString str;
|
||||
@ -408,20 +422,47 @@ nsresult nsTestUConv::DisplayCharsets()
|
||||
printf("%s", buff.get());
|
||||
PrintSpaces(24 - buff.Length()); // align to hard coded column number
|
||||
|
||||
res = ccMan->GetCharsetTitle2(cs, &str);
|
||||
if (NS_FAILED(res)) str.SetLength(0);
|
||||
NS_LossyConvertUCS2toASCII buff2(str);
|
||||
|
||||
nsCOMPtr<nsIUnicodeDecoder> dec = NULL;
|
||||
res = ccMan->GetUnicodeDecoder(cs, getter_AddRefs(dec));
|
||||
if (NS_FAILED(res)) printf (" ");
|
||||
else printf("D");
|
||||
else {
|
||||
printf("D");
|
||||
decCount++;
|
||||
}
|
||||
#ifdef NS_DEBUG
|
||||
// show the "basic" decoder classes
|
||||
if (dec) {
|
||||
nsCOMPtr<nsIBasicDecoder> isBasic = do_QueryInterface(dec);
|
||||
if (isBasic) {
|
||||
basicDecCount++;
|
||||
printf("b");
|
||||
}
|
||||
else printf(" ");
|
||||
}
|
||||
else printf(" ");
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIUnicodeEncoder> enc = NULL;
|
||||
res = ccMan->GetUnicodeEncoder(cs, getter_AddRefs(enc));
|
||||
if (NS_FAILED(res)) printf (" ");
|
||||
else printf("E");
|
||||
else {
|
||||
printf("E");
|
||||
encCount++;
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
if (enc) {
|
||||
nsCOMPtr<nsIBasicEncoder> isBasic = do_QueryInterface(enc);
|
||||
if (isBasic) {
|
||||
basicEncCount++;
|
||||
printf("b");
|
||||
}
|
||||
else printf(" ");
|
||||
}
|
||||
else printf(" ");
|
||||
#endif
|
||||
|
||||
printf(" ");
|
||||
|
||||
prop.Assign(NS_LITERAL_STRING(".notForBrowser"));
|
||||
@ -444,9 +485,18 @@ nsresult nsTestUConv::DisplayCharsets()
|
||||
if ((enc != NULL) && (NS_FAILED(res))) printf ("E");
|
||||
else printf("X");
|
||||
|
||||
printf(" \"%s\"\n", buff2);
|
||||
printf("(%3d, %3d) ", encCount, decCount);
|
||||
res = ccMan->GetCharsetTitle2(cs, &str);
|
||||
if (NS_FAILED(res)) str.SetLength(0);
|
||||
NS_LossyConvertUCS2toASCII buff2(str);
|
||||
printf(" \"%s\"\n", buff2.get());
|
||||
}
|
||||
|
||||
printf("%u of %u decoders are basic (%d%%)\n",
|
||||
basicDecCount, decCount, (basicDecCount * 100) / decCount);
|
||||
|
||||
printf("%u of %u encoders are basic (%d%%)\n",
|
||||
basicEncCount, encCount, (basicEncCount * 100) / encCount);
|
||||
mLog.DelTrace(trace);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
nsUCvCnCID.h
|
||||
|
||||
@ -27,9 +27,8 @@ VPATH = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = ucvcn
|
||||
LIBRARY_NAME = ucvcn
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
LIBRARY_NAME = ucvcn_s
|
||||
FORCE_STATIC_LIB=1
|
||||
MODULE_NAME = nsUCvCnModule
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
@ -50,17 +49,17 @@ CPPSRCS = \
|
||||
nsUnicodeToHZ.cpp \
|
||||
nsCP936ToUnicode.cpp \
|
||||
nsUnicodeToCP936.cpp \
|
||||
nsUCvCnSupport.cpp \
|
||||
nsUCvCnModule.cpp \
|
||||
nsGBKConvUtil.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = nsUCvCnCID.h
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
LOCAL_INCLUDES = -I$(srcdir)/../util
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -D_IMPL_NS_INTL
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
DEFINES += -DWIN32_LEAN_AND_MEAN
|
||||
endif
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
#ifndef nsCP936ToUnicode_h___
|
||||
#define nsCP936ToUnicode_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP936ToUnicode [declaration]
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsGB2312ToUnicodeV2_h___
|
||||
#define nsGB2312ToUnicodeV2_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "gbku.h"
|
||||
#include "nsGBKToUnicode.h"
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
@ -62,12 +62,6 @@ public:
|
||||
virtual ~nsGBKUnique2BytesToUnicode()
|
||||
{ };
|
||||
protected:
|
||||
NS_IMETHOD GetMaxLength(const char* aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK;
|
||||
};
|
||||
};
|
||||
|
||||
static PRUint16 g_utGBKUnique2Bytes[] = {
|
||||
@ -75,7 +69,7 @@ static PRUint16 g_utGBKUnique2Bytes[] = {
|
||||
};
|
||||
nsGBKUnique2BytesToUnicode::nsGBKUnique2BytesToUnicode()
|
||||
: nsTableDecoderSupport((uShiftTable*) &g_2BytesShiftTable,
|
||||
(uMappingTable*) &g_utGBKUnique2Bytes)
|
||||
(uMappingTable*) &g_utGBKUnique2Bytes, 1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -89,12 +83,6 @@ public:
|
||||
virtual ~nsGB18030Unique2BytesToUnicode()
|
||||
{ };
|
||||
protected:
|
||||
NS_IMETHOD GetMaxLength(const char* aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK;
|
||||
};
|
||||
};
|
||||
|
||||
static PRUint16 g_utGB18030Unique2Bytes[] = {
|
||||
@ -102,7 +90,7 @@ static PRUint16 g_utGB18030Unique2Bytes[] = {
|
||||
};
|
||||
nsGB18030Unique2BytesToUnicode::nsGB18030Unique2BytesToUnicode()
|
||||
: nsTableDecoderSupport((uShiftTable*) &g_2BytesShiftTable,
|
||||
(uMappingTable*) &g_utGB18030Unique2Bytes)
|
||||
(uMappingTable*) &g_utGB18030Unique2Bytes, 1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -120,12 +108,6 @@ public:
|
||||
virtual ~nsGB18030Unique4BytesToUnicode()
|
||||
{ };
|
||||
protected:
|
||||
NS_IMETHOD GetMaxLength(const char* aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK;
|
||||
};
|
||||
};
|
||||
|
||||
static PRUint16 g_utGB18030Unique4Bytes[] = {
|
||||
@ -133,7 +115,7 @@ static PRUint16 g_utGB18030Unique4Bytes[] = {
|
||||
};
|
||||
nsGB18030Unique4BytesToUnicode::nsGB18030Unique4BytesToUnicode()
|
||||
: nsTableDecoderSupport((uShiftTable*) &g_GB18030_4BytesShiftTable,
|
||||
(uMappingTable*) &g_utGB18030Unique4Bytes)
|
||||
(uMappingTable*) &g_utGB18030Unique4Bytes, 1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -144,14 +126,6 @@ nsGB18030Unique4BytesToUnicode::nsGB18030Unique4BytesToUnicode()
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTablesDecoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsGBKToUnicode::GetMaxLength(const char * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#define LEGAL_GBK_MULTIBYTE_FIRST_BYTE(c) \
|
||||
(UINT8_IN_RANGE(0x81, (c), 0xFE))
|
||||
#define FIRST_BYTE_IS_SURROGATE(c) \
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "gbku.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -60,7 +60,7 @@ public:
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsGBKToUnicode()
|
||||
nsGBKToUnicode() : nsBufferDecoderSupport(1)
|
||||
{
|
||||
mExtensionDecoder = nsnull;
|
||||
m4BytesDecoder = nsnull;
|
||||
@ -72,9 +72,6 @@ protected:
|
||||
// Subclassing of nsDecoderSupport class [declaration]
|
||||
NS_IMETHOD ConvertNoBuff(const char* aSrc, PRInt32 * aSrcLength, PRUnichar *aDest, PRInt32 * aDestLength);
|
||||
|
||||
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
|
||||
protected:
|
||||
nsGBKConvUtil mUtil;
|
||||
nsCOMPtr<nsIUnicodeDecoder> mExtensionDecoder;
|
||||
|
||||
@ -69,13 +69,6 @@
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTablesDecoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsHZToUnicode::GetMaxLength(const char * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK;
|
||||
}
|
||||
#define HZ_STATE_GB 1
|
||||
#define HZ_STATE_ASCII 2
|
||||
#define HZ_STATE_TILD 3
|
||||
@ -84,7 +77,7 @@ NS_IMETHODIMP nsHZToUnicode::GetMaxLength(const char * aSrc,
|
||||
#define HZLEAD3 '}'
|
||||
#define HZLEAD4 '\n'
|
||||
|
||||
nsHZToUnicode::nsHZToUnicode()
|
||||
nsHZToUnicode::nsHZToUnicode() : nsBufferDecoderSupport(1)
|
||||
{
|
||||
mHZState = HZ_STATE_ASCII; // per HZ spec, default to ASCII state
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsHZToUnicode_h___
|
||||
#define nsHZToUnicode_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "gbku.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -67,8 +67,6 @@ protected:
|
||||
// Subclassing of nsDecoderSupport class [declaration]
|
||||
NS_IMETHOD ConvertNoBuff(const char* aSrc, PRInt32 * aSrcLength,
|
||||
PRUnichar *aDest, PRInt32 * aDestLength);
|
||||
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
nsGBKConvUtil mUtil;
|
||||
|
||||
private:
|
||||
|
||||
@ -41,5 +41,4 @@
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
#define g_AsciiMapping ucvcn_g_AsciiMapping
|
||||
#endif /* nsUCvCnDll_h___ */
|
||||
|
||||
@ -1,732 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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 the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsICharRepresentable.h"
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCvCnDll.h"
|
||||
|
||||
static NS_DEFINE_CID(kUnicodeDecodeHelperCID, NS_UNICODEDECODEHELPER_CID);
|
||||
static NS_DEFINE_CID(kUnicodeEncodeHelperCID, NS_UNICODEENCODEHELPER_CID);
|
||||
|
||||
#define DEFAULT_BUFFER_CAPACITY 16
|
||||
|
||||
// XXX review the buffer growth limitation code
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsBasicDecoderSupport [implementation]
|
||||
|
||||
nsBasicDecoderSupport::nsBasicDecoderSupport()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasicDecoderSupport::~nsBasicDecoderSupport()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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(NS_GET_IID(nsIUnicodeDecoder))) {
|
||||
*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]
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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;
|
||||
#if defined(DEBUG_yokoyama) || defined(DEBUG_ftang)
|
||||
NS_ASSERTION(0, "This should not happen. Internal buffer may be corrupted.");
|
||||
#endif
|
||||
break;
|
||||
} else {
|
||||
if (bcr < buffLen) {
|
||||
// we didn't convert that residual data - unfill the buffer
|
||||
src -= mBufferLength - buffLen;
|
||||
mBufferLength = buffLen;
|
||||
#if defined(DEBUG_yokoyama) || defined(DEBUG_ftang)
|
||||
NS_ASSERTION(0, "This should not happen. Internal buffer may be corrupted.");
|
||||
#endif
|
||||
} else {
|
||||
// the buffer and some extra data was converted - unget the rest
|
||||
src -= mBufferLength - bcr;
|
||||
mBufferLength = 0;
|
||||
res = NS_OK;
|
||||
}
|
||||
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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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 nsBasicEncoder [implementation]
|
||||
nsBasicEncoder::nsBasicEncoder()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasicEncoder::~nsBasicEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsBasicEncoder);
|
||||
NS_IMPL_RELEASE(nsBasicEncoder);
|
||||
|
||||
nsresult nsBasicEncoder::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(NS_GET_IID(nsIUnicodeEncoder))) {
|
||||
*aInstancePtr = (void*) ((nsIUnicodeEncoder*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsICharRepresentable))) {
|
||||
*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;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEncoderSupport [implementation]
|
||||
|
||||
nsEncoderSupport::nsEncoderSupport()
|
||||
{
|
||||
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
|
||||
mBuffer = new char[mBufferCapacity];
|
||||
|
||||
mErrBehavior = kOnError_Signal;
|
||||
mErrChar = 0;
|
||||
mErrEncoder = NULL;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsEncoderSupport::~nsEncoderSupport()
|
||||
{
|
||||
delete [] mBuffer;
|
||||
NS_IF_RELEASE(mErrEncoder);
|
||||
}
|
||||
|
||||
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 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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (void**) & mHelper);
|
||||
|
||||
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
|
||||
}
|
||||
|
||||
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
|
||||
mTableCount, mShiftTable, mMappingTable);
|
||||
return res;
|
||||
}
|
||||
@ -1,438 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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 the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsUCvCnSupport_h___
|
||||
#define nsUCvCnSupport_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/nsUCvCnSupport.
|
||||
* 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]
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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 nsBasicEncoder [declaration]
|
||||
|
||||
class nsBasicEncoder : public nsIUnicodeEncoder, public nsICharRepresentable
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsBasicEncoder();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
virtual ~nsBasicEncoder();
|
||||
|
||||
};
|
||||
//----------------------------------------------------------------------
|
||||
// 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 nsBasicEncoder
|
||||
{
|
||||
|
||||
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 /* nsUCvCnSupport_h___ */
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsUnicodeToCP936_h___
|
||||
#define nsUnicodeToCP936_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToCP936 [declaration]
|
||||
|
||||
@ -46,7 +46,8 @@
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToGB2312GL [implementation]
|
||||
|
||||
nsUnicodeToGB2312GL::nsUnicodeToGB2312GL()
|
||||
nsUnicodeToGB2312GL::nsUnicodeToGB2312GL() :
|
||||
nsEncoderSupport(2)
|
||||
{
|
||||
mUtil.InitToGBKTable();
|
||||
}
|
||||
@ -95,14 +96,6 @@ NS_IMETHODIMP nsUnicodeToGB2312GL::ConvertNoBuff(const PRUnichar * aSrc,
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToGB2312GL::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 2 * aSrcLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToGB2312GL::FillInfo(PRUint32 *aInfo)
|
||||
{
|
||||
mUtil.FillGB2312Info(aInfo);
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
#ifndef nsUnicodeToGB2312GL_h___
|
||||
#define nsUnicodeToGB2312GL_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "gbku.h"
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToGB2312GL [declaration]
|
||||
@ -70,9 +70,6 @@ protected:
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
|
||||
NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength,
|
||||
char * aDest, PRInt32 * aDestLength)
|
||||
{
|
||||
|
||||
@ -44,7 +44,8 @@
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToGB2312V2 [implementation]
|
||||
nsUnicodeToGB2312V2::nsUnicodeToGB2312V2()
|
||||
nsUnicodeToGB2312V2::nsUnicodeToGB2312V2() :
|
||||
nsEncoderSupport(2)
|
||||
{
|
||||
mUtil.InitToGBKTable();
|
||||
}
|
||||
@ -103,14 +104,6 @@ NS_IMETHODIMP nsUnicodeToGB2312V2::ConvertNoBuff(const PRUnichar * aSrc,
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToGB2312V2::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 2 * aSrcLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToGB2312V2::FillInfo(PRUint32 *aInfo)
|
||||
{
|
||||
mUtil.FillGB2312Info(aInfo);
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsUnicodeToGB2312V2_h___
|
||||
#define nsUnicodeToGB2312V2_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "gbku.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
@ -70,9 +70,6 @@ protected:
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
|
||||
NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength,
|
||||
char * aDest, PRInt32 * aDestLength)
|
||||
{
|
||||
|
||||
@ -78,15 +78,8 @@ class nsUnicodeToGB18030Uniq2Bytes : public nsTableEncoderSupport
|
||||
public:
|
||||
nsUnicodeToGB18030Uniq2Bytes()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_2BytesShiftTable,
|
||||
(uMappingTable*) &g_uf_gb18030_2bytes) {};
|
||||
(uMappingTable*) &g_uf_gb18030_2bytes, 2) {};
|
||||
protected:
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 2 * aSrcLength;
|
||||
return NS_OK;
|
||||
};
|
||||
};
|
||||
//-----------------------------------------------------------------------
|
||||
// Private class used by nsUnicodeToGB18030
|
||||
@ -100,15 +93,8 @@ class nsUnicodeTo4BytesGB18030 : public nsTableEncoderSupport
|
||||
public:
|
||||
nsUnicodeTo4BytesGB18030()
|
||||
: nsTableEncoderSupport( (uShiftTable*) &g_4BytesGB18030ShiftTable,
|
||||
(uMappingTable*) &g_uf_gb18030_4bytes) {};
|
||||
(uMappingTable*) &g_uf_gb18030_4bytes, 4) {};
|
||||
protected:
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 4 * aSrcLength;
|
||||
return NS_OK_UDEC_EXACTLENGTH;
|
||||
};
|
||||
};
|
||||
//-----------------------------------------------------------------------
|
||||
// Private class used by nsUnicodeToGBK
|
||||
@ -122,15 +108,8 @@ class nsUnicodeToGBKUniq2Bytes : public nsTableEncoderSupport
|
||||
public:
|
||||
nsUnicodeToGBKUniq2Bytes()
|
||||
: nsTableEncoderSupport( (uShiftTable*) &g_2BytesShiftTable,
|
||||
(uMappingTable*) &g_uf_gbk_2bytes) {};
|
||||
(uMappingTable*) &g_uf_gbk_2bytes, 2) {};
|
||||
protected:
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 2 * aSrcLength;
|
||||
return NS_OK_UDEC_EXACTLENGTH;
|
||||
};
|
||||
};
|
||||
//-----------------------------------------------------------------------
|
||||
// nsUnicodeToGB18030
|
||||
@ -143,13 +122,7 @@ void nsUnicodeToGB18030::Create4BytesEncoder()
|
||||
{
|
||||
m4BytesEncoder = new nsUnicodeTo4BytesGB18030();
|
||||
}
|
||||
NS_IMETHODIMP nsUnicodeToGB18030::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 4 * aSrcLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool nsUnicodeToGB18030::EncodeSurrogate(
|
||||
PRUnichar aSurrogateHigh,
|
||||
PRUnichar aSurrogateLow,
|
||||
@ -205,19 +178,11 @@ NS_IMETHODIMP nsUnicodeToGB18030Font0::FillInfo(PRUint32 *aInfo)
|
||||
//-----------------------------------------------------------------------
|
||||
nsUnicodeToGB18030Font1::nsUnicodeToGB18030Font1()
|
||||
: nsTableEncoderSupport( (uShiftTable*) &g_2BytesShiftTable,
|
||||
(uMappingTable*) &g_uf_gb18030_4bytes)
|
||||
(uMappingTable*) &g_uf_gb18030_4bytes, 4)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToGB18030Font1::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 4 * aSrcLength;
|
||||
return NS_OK_UDEC_EXACTLENGTH; // font encoding is exactly 4 bytes
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToGB18030Font1::FillInfo(PRUint32 *aInfo)
|
||||
{
|
||||
nsresult res = nsTableEncoderSupport::FillInfo(aInfo);
|
||||
@ -357,7 +322,8 @@ NS_IMETHODIMP nsUnicodeToGB18030Font1::FillInfo(PRUint32 *aInfo)
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToGBK [implementation]
|
||||
|
||||
nsUnicodeToGBK::nsUnicodeToGBK()
|
||||
nsUnicodeToGBK::nsUnicodeToGBK(PRUint32 aMaxLength) :
|
||||
nsEncoderSupport(aMaxLength)
|
||||
{
|
||||
mExtensionEncoder = nsnull;
|
||||
m4BytesEncoder = nsnull;
|
||||
@ -562,15 +528,6 @@ NS_IMETHODIMP nsUnicodeToGBK::ConvertNoBuff(
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToGBK::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 2 * aSrcLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToGBK::FillInfo(PRUint32 *aInfo)
|
||||
{
|
||||
mUtil.FillInfo(aInfo, 0x81, 0xFE, 0x40, 0xFE);
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
#ifndef nsUnicodeToGBK_h___
|
||||
#define nsUnicodeToGBK_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "gbku.h"
|
||||
@ -61,7 +61,7 @@ public:
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsUnicodeToGBK();
|
||||
nsUnicodeToGBK(PRUint32 aMaxLengthFactor = 2);
|
||||
virtual ~nsUnicodeToGBK() {};
|
||||
|
||||
protected:
|
||||
@ -73,9 +73,6 @@ protected:
|
||||
char * aDest,
|
||||
PRInt32 * aDestLength);
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
|
||||
NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength,
|
||||
char * aDest, PRInt32 * aDestLength)
|
||||
{
|
||||
@ -100,11 +97,9 @@ protected:
|
||||
class nsUnicodeToGB18030: public nsUnicodeToGBK
|
||||
{
|
||||
public:
|
||||
nsUnicodeToGB18030() {};
|
||||
nsUnicodeToGB18030() : nsUnicodeToGBK(4) {};
|
||||
virtual ~nsUnicodeToGB18030() {};
|
||||
protected:
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
virtual void CreateExtensionEncoder();
|
||||
virtual void Create4BytesEncoder();
|
||||
virtual PRBool EncodeSurrogate(PRUnichar aSurrogateHigh, PRUnichar aSurrogateLow, char* aDest);
|
||||
@ -127,9 +122,6 @@ public:
|
||||
nsUnicodeToGB18030Font1();
|
||||
virtual ~nsUnicodeToGB18030Font1() {};
|
||||
protected:
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD FillInfo(PRUint32 *aInfo);
|
||||
};
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@
|
||||
#define HZLEAD2 '{'
|
||||
#define HZLEAD3 '}'
|
||||
#define UNICODE_TILD 0x007E
|
||||
nsUnicodeToHZ::nsUnicodeToHZ()
|
||||
nsUnicodeToHZ::nsUnicodeToHZ() : nsEncoderSupport(6)
|
||||
{
|
||||
mUtil.InitToGBKTable();
|
||||
mHZState = HZ_STATE_ASCII; // per HZ spec, default to HZ mode
|
||||
@ -142,12 +142,3 @@ NS_IMETHODIMP nsUnicodeToHZ::FillInfo(PRUint32 *aInfo)
|
||||
SET_REPRESENTABLE(aInfo, u);
|
||||
return NS_OK;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
NS_IMETHODIMP nsUnicodeToHZ::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 6 * aSrcLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
#ifndef nsUnicodeToHZ_h___
|
||||
#define nsUnicodeToHZ_h___
|
||||
|
||||
#include "nsUCvCnSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
#include "gbku.h"
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToHZ [declaration]
|
||||
@ -78,9 +78,6 @@ protected:
|
||||
return NS_OK;
|
||||
}; // just make it not abstract;
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
|
||||
PRUint16 mHZState;
|
||||
protected:
|
||||
nsGBKConvUtil mUtil;
|
||||
|
||||
@ -1 +0,0 @@
|
||||
nsUCvIBMCID.h
|
||||
@ -38,9 +38,8 @@ VPATH = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = ucvibm
|
||||
LIBRARY_NAME = ucvibm
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
LIBRARY_NAME = ucvibm_s
|
||||
FORCE_STATIC_LIB = 1
|
||||
MODULE_NAME = nsUCvIBMModule
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
@ -62,13 +61,11 @@ CPPSRCS = \
|
||||
nsUnicodeToCP862.cpp \
|
||||
nsUnicodeToCP864.cpp \
|
||||
nsUnicodeToCP864i.cpp \
|
||||
nsUCvIBMSupport.cpp \
|
||||
nsUCvIBMModule.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = nsUCvIBMCID.h
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
LOCAL_INCLUDES = -I$(srcdir)/../util
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
ifeq ($(MOZ_OS2_TOOLS),VACPP)
|
||||
@ -80,6 +77,7 @@ endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -D_IMPL_NS_INTL
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
DEFINES += -DWIN32_LEAN_AND_MEAN
|
||||
endif
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsCP850ToUnicode_h___
|
||||
#define nsCP850ToUnicode_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP850ToUnicode [declaration]
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsCP852ToUnicode_h___
|
||||
#define nsCP852ToUnicode_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP852ToUnicode [declaration]
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsCP855ToUnicode_h___
|
||||
#define nsCP855ToUnicode_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP855ToUnicode [declaration]
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsCP857ToUnicode_h___
|
||||
#define nsCP857ToUnicode_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP857ToUnicode [declaration]
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsCP862ToUnicode_h___
|
||||
#define nsCP862ToUnicode_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP862ToUnicode [declaration]
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsCP864ToUnicode_h___
|
||||
#define nsCP864ToUnicode_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP864ToUnicode [declaration]
|
||||
|
||||
@ -74,7 +74,7 @@
|
||||
|
||||
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,729 +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.1 (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.
|
||||
*
|
||||
* Contributor(s):
|
||||
* IBM Corporation
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 1999
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 12/09/1999 IBM Corp. Support for IBM codepages - 850,852,855,857,862,864
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsICharRepresentable.h"
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCvIBMDll.h"
|
||||
|
||||
static NS_DEFINE_CID(kUnicodeDecodeHelperCID, NS_UNICODEDECODEHELPER_CID);
|
||||
static NS_DEFINE_CID(kUnicodeEncodeHelperCID, NS_UNICODEENCODEHELPER_CID);
|
||||
|
||||
#define DEFAULT_BUFFER_CAPACITY 16
|
||||
|
||||
// XXX review the buffer growth limitation code
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsBasicDecoderSupport [implementation]
|
||||
|
||||
nsBasicDecoderSupport::nsBasicDecoderSupport()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasicDecoderSupport::~nsBasicDecoderSupport()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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(NS_GET_IID(nsIUnicodeDecoder))) {
|
||||
*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]
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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;
|
||||
#if defined(DEBUG_yokoyama) || defined(DEBUG_ftang)
|
||||
NS_ASSERTION(0, "This should not happen. Internal buffer may be corrupted.");
|
||||
#endif
|
||||
break;
|
||||
} else {
|
||||
if (bcr < buffLen) {
|
||||
// we didn't convert that residual data - unfill the buffer
|
||||
src -= mBufferLength - buffLen;
|
||||
mBufferLength = buffLen;
|
||||
#if defined(DEBUG_yokoyama) || defined(DEBUG_ftang)
|
||||
NS_ASSERTION(0, "This should not happen. Internal buffer may be corrupted.");
|
||||
#endif
|
||||
} else {
|
||||
// the buffer and some extra data was converted - unget the rest
|
||||
src -= mBufferLength - bcr;
|
||||
mBufferLength = 0;
|
||||
res = NS_OK;
|
||||
}
|
||||
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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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 nsBasicEncoder [implementation]
|
||||
nsBasicEncoder::nsBasicEncoder()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasicEncoder::~nsBasicEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsBasicEncoder);
|
||||
NS_IMPL_RELEASE(nsBasicEncoder);
|
||||
|
||||
nsresult nsBasicEncoder::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(NS_GET_IID(nsIUnicodeEncoder))) {
|
||||
*aInstancePtr = (void*) ((nsIUnicodeEncoder*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsICharRepresentable))) {
|
||||
*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;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEncoderSupport [implementation]
|
||||
|
||||
nsEncoderSupport::nsEncoderSupport()
|
||||
{
|
||||
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
|
||||
mBuffer = new char[mBufferCapacity];
|
||||
|
||||
mErrBehavior = kOnError_Signal;
|
||||
mErrChar = 0;
|
||||
mErrEncoder = NULL;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsEncoderSupport::~nsEncoderSupport()
|
||||
{
|
||||
delete [] mBuffer;
|
||||
NS_IF_RELEASE(mErrEncoder);
|
||||
}
|
||||
|
||||
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 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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (void**) & mHelper);
|
||||
|
||||
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
|
||||
}
|
||||
|
||||
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
|
||||
mTableCount, mShiftTable, mMappingTable);
|
||||
return res;
|
||||
}
|
||||
@ -1,435 +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.1 (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.
|
||||
*
|
||||
* Contributor(s):
|
||||
* IBM Corporation
|
||||
*
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 1999
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 12/09/1999 IBM Corp. Support for IBM codepages - 850,852,855,857,862,864
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef nsUCvIBMSupport_h___
|
||||
#define nsUCvIBMSupport_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 /ucvibm/nsUCvIBMSupport.
|
||||
* 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]
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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 nsBasicEncoder [declaration]
|
||||
|
||||
class nsBasicEncoder : public nsIUnicodeEncoder, public nsICharRepresentable
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsBasicEncoder();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
virtual ~nsBasicEncoder();
|
||||
|
||||
};
|
||||
//----------------------------------------------------------------------
|
||||
// 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 nsBasicEncoder
|
||||
{
|
||||
|
||||
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 /* nsUCvIBMSupport_h___ */
|
||||
@ -52,17 +52,7 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
|
||||
nsUnicodeToCP850::nsUnicodeToCP850()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToCP850::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsUnicodeToCP850_h___
|
||||
#define nsUnicodeToCP850_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToCP850 [declaration]
|
||||
@ -52,14 +52,6 @@ public:
|
||||
* Class constructor.
|
||||
*/
|
||||
nsUnicodeToCP850();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToCP850_h___ */
|
||||
|
||||
@ -52,17 +52,7 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
|
||||
nsUnicodeToCP852::nsUnicodeToCP852()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToCP852::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsUnicodeToCP852_h___
|
||||
#define nsUnicodeToCP852_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToCP852 [declaration]
|
||||
@ -53,13 +53,6 @@ public:
|
||||
*/
|
||||
nsUnicodeToCP852();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToCP852_h___ */
|
||||
|
||||
@ -52,17 +52,7 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
|
||||
nsUnicodeToCP855::nsUnicodeToCP855()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToCP855::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsUnicodeToCP855_h___
|
||||
#define nsUnicodeToCP855_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToCP855 [declaration]
|
||||
@ -53,13 +53,6 @@ public:
|
||||
*/
|
||||
nsUnicodeToCP855();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToCP855_h___ */
|
||||
|
||||
@ -52,17 +52,7 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
|
||||
nsUnicodeToCP857::nsUnicodeToCP857()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToCP857::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsUnicodeToCP857_h___
|
||||
#define nsUnicodeToCP857_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToCP857 [declaration]
|
||||
@ -53,13 +53,6 @@ public:
|
||||
*/
|
||||
nsUnicodeToCP857();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToCP857_h___ */
|
||||
|
||||
@ -52,17 +52,7 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
|
||||
nsUnicodeToCP862::nsUnicodeToCP862()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToCP862::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsUnicodeToCP862_h___
|
||||
#define nsUnicodeToCP862_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToCP862 [declaration]
|
||||
@ -53,13 +53,6 @@ public:
|
||||
*/
|
||||
nsUnicodeToCP862();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToCP862_h___ */
|
||||
|
||||
@ -52,17 +52,7 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
|
||||
nsUnicodeToCP864::nsUnicodeToCP864()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToCP864::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#ifndef nsUnicodeToCP864_h___
|
||||
#define nsUnicodeToCP864_h___
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToCP864 [declaration]
|
||||
@ -53,13 +53,6 @@ public:
|
||||
*/
|
||||
nsUnicodeToCP864();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsUnicodeToCP864_h___ */
|
||||
|
||||
@ -1,79 +1,41 @@
|
||||
/* -*- 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.1 (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.
|
||||
|
||||
*
|
||||
|
||||
* Contributor(s):
|
||||
|
||||
* IBM Corporation
|
||||
|
||||
*
|
||||
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
|
||||
* Modifications made by IBM described herein are
|
||||
|
||||
* Copyright (c) International Business Machines
|
||||
|
||||
* Corporation, 1999
|
||||
|
||||
*
|
||||
|
||||
* Modifications to Mozilla code or documentation
|
||||
|
||||
* identified per MPL Section 3.3
|
||||
|
||||
*
|
||||
|
||||
* Date Modified by Description of modification
|
||||
|
||||
* 12/09/1999 IBM Corp. Support for IBM codepages - 864i
|
||||
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "nsUnicodeToCP864i.h"
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Global functions and data [declaration]
|
||||
static const PRUint16 g_ufMappingTable[] = {
|
||||
#include "864i.uf"
|
||||
@ -85,42 +47,12 @@ static const PRInt16 g_ufShiftTable[] = {
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Class nsUnicodeToCP864i [implementation]
|
||||
|
||||
|
||||
|
||||
nsUnicodeToCP864i::nsUnicodeToCP864i()
|
||||
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_ufShiftTable,
|
||||
|
||||
(uMappingTable*) &g_ufMappingTable)
|
||||
|
||||
(uMappingTable*) &g_ufMappingTable, 1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToCP864i::GetMaxLength(const PRUnichar * aSrc,
|
||||
|
||||
PRInt32 aSrcLength,
|
||||
|
||||
PRInt32 * aDestLength)
|
||||
|
||||
{
|
||||
|
||||
*aDestLength = aSrcLength;
|
||||
|
||||
return NS_OK_UENC_EXACTLENGTH;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,130 +1,58 @@
|
||||
/* -*- 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.1 (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.
|
||||
|
||||
*
|
||||
|
||||
* Contributor(s):
|
||||
|
||||
* IBM Corporation
|
||||
|
||||
*
|
||||
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
|
||||
* Modifications made by IBM described herein are
|
||||
|
||||
* Copyright (c) International Business Machines
|
||||
|
||||
* Corporation, 1999
|
||||
|
||||
*
|
||||
|
||||
* Modifications to Mozilla code or documentation
|
||||
|
||||
* identified per MPL Section 3.3
|
||||
|
||||
*
|
||||
|
||||
* Date Modified by Description of modification
|
||||
|
||||
* 12/09/1999 IBM Corp. Support for IBM codepages - 864i
|
||||
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef nsUnicodeToCP864i_h___
|
||||
|
||||
#define nsUnicodeToCP864i_h___
|
||||
|
||||
|
||||
|
||||
#include "nsUCvIBMSupport.h"
|
||||
|
||||
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Class nsUnicodeToCP864i [declaration]
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* A character set converter from Unicode to CP864i.
|
||||
|
||||
*/
|
||||
|
||||
class nsUnicodeToCP864i : public nsTableEncoderSupport
|
||||
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Class constructor.
|
||||
|
||||
*/
|
||||
|
||||
nsUnicodeToCP864i();
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
// Subclassing of nsEncoderSupport class [declaration]
|
||||
|
||||
|
||||
|
||||
NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength,
|
||||
|
||||
PRInt32 * aDestLength);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsUnicodeToCP864i_h___ */
|
||||
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
nsUCVJACID.h
|
||||
nsUCVJA2CID.h
|
||||
@ -27,9 +27,10 @@ VPATH = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = ucvja
|
||||
LIBRARY_NAME = ucvja
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
LIBRARY_NAME = ucvja_s
|
||||
#EXPORT_LIBRARY = 1
|
||||
#IS_COMPONENT = 1
|
||||
FORCE_STATIC_LIB = 1
|
||||
MODULE_NAME = nsUCvJAModule
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
@ -41,8 +42,6 @@ CPPSRCS = \
|
||||
nsUnicodeToSJIS.cpp \
|
||||
nsCP932ToUnicode.cpp \
|
||||
nsUnicodeToCP932.cpp \
|
||||
nsUCvJaSupport.cpp \
|
||||
nsUCvJaModule.cpp \
|
||||
nsUnicodeToEUCJP.cpp \
|
||||
nsUnicodeToISO2022JP.cpp \
|
||||
nsUnicodeToJISx0201.cpp \
|
||||
@ -55,6 +54,11 @@ EXPORTS = \
|
||||
nsUCVJA2CID.h \
|
||||
$(NULL)
|
||||
|
||||
#SHARED_LIBRARY_LIBS = $(DIST)/lib/$(LIB_PREFIX)ucvutil_s.$(LIB_SUFFIX)
|
||||
|
||||
LOCAL_INCLUDES = -I$(srcdir)/../util
|
||||
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsJapaneseToUnicode.h"
|
||||
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
static const PRUint16 gJis0208map[] = {
|
||||
#include "jis0208.ump"
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
#ifndef nsShiftJISToUnicode_h__
|
||||
#define nsShiftJISToUnicode_h__
|
||||
#include "nsISupports.h"
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
|
||||
class nsShiftJISToUnicode : public nsBasicDecoderSupport
|
||||
|
||||
@ -1,732 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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 the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsICharRepresentable.h"
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCVJADll.h"
|
||||
|
||||
static NS_DEFINE_CID(kUnicodeEncodeHelperCID, NS_UNICODEENCODEHELPER_CID);
|
||||
static NS_DEFINE_CID(kUnicodeDecodeHelperCID, NS_UNICODEDECODEHELPER_CID);
|
||||
|
||||
#define DEFAULT_BUFFER_CAPACITY 16
|
||||
|
||||
// XXX review the buffer growth limitation code
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsBasicDecoderSupport [implementation]
|
||||
|
||||
nsBasicDecoderSupport::nsBasicDecoderSupport()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasicDecoderSupport::~nsBasicDecoderSupport()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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(NS_GET_IID(nsIUnicodeDecoder))) {
|
||||
*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]
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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;
|
||||
#if defined(DEBUG_yokoyama) || defined(DEBUG_ftang)
|
||||
NS_ASSERTION(0, "This should not happen. Internal buffer may be corrupted.");
|
||||
#endif
|
||||
break;
|
||||
} else {
|
||||
if (bcr < buffLen) {
|
||||
// we didn't convert that residual data - unfill the buffer
|
||||
src -= mBufferLength - buffLen;
|
||||
mBufferLength = buffLen;
|
||||
#if defined(DEBUG_yokoyama) || defined(DEBUG_ftang)
|
||||
NS_ASSERTION(0, "This should not happen. Internal buffer may be corrupted.");
|
||||
#endif
|
||||
} else {
|
||||
// the buffer and some extra data was converted - unget the rest
|
||||
src -= mBufferLength - bcr;
|
||||
mBufferLength = 0;
|
||||
res = NS_OK;
|
||||
}
|
||||
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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeDecodeHelper), (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 nsBasicEncoder [implementation]
|
||||
nsBasicEncoder::nsBasicEncoder()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasicEncoder::~nsBasicEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsBasicEncoder);
|
||||
NS_IMPL_RELEASE(nsBasicEncoder);
|
||||
|
||||
nsresult nsBasicEncoder::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID2, NS_ISUPPORTS_IID);
|
||||
|
||||
if (aIID.Equals(NS_GET_IID(nsIUnicodeEncoder))) {
|
||||
*aInstancePtr = (void*) ((nsIUnicodeEncoder*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsICharRepresentable))) {
|
||||
*aInstancePtr = (void*) ((nsICharRepresentable*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID2)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)((nsIUnicodeEncoder*)this));
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsEncoderSupport [implementation]
|
||||
|
||||
nsEncoderSupport::nsEncoderSupport()
|
||||
{
|
||||
mBufferCapacity = DEFAULT_BUFFER_CAPACITY;
|
||||
mBuffer = new char[mBufferCapacity];
|
||||
|
||||
mErrBehavior = kOnError_Signal;
|
||||
mErrChar = 0;
|
||||
mErrEncoder = NULL;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsEncoderSupport::~nsEncoderSupport()
|
||||
{
|
||||
delete [] mBuffer;
|
||||
NS_IF_RELEASE(mErrEncoder);
|
||||
}
|
||||
|
||||
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 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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (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,
|
||||
NS_GET_IID(nsIUnicodeEncodeHelper), (void**) & mHelper);
|
||||
|
||||
if (NS_FAILED(res)) return NS_ERROR_UENC_NOHELPER;
|
||||
}
|
||||
|
||||
res = mHelper->ConvertByMultiTable(aSrc, aSrcLength, aDest, aDestLength,
|
||||
mTableCount, mShiftTable, mMappingTable);
|
||||
return res;
|
||||
}
|
||||
@ -1,438 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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 the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsUCvJaSupport_h___
|
||||
#define nsUCvJaSupport_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/nsUCvJaSupport.
|
||||
* 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]
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// 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 nsBasicEncoder [declaration]
|
||||
|
||||
class nsBasicEncoder : public nsIUnicodeEncoder, public nsICharRepresentable
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsBasicEncoder();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
virtual ~nsBasicEncoder();
|
||||
|
||||
};
|
||||
//----------------------------------------------------------------------
|
||||
// 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 nsBasicEncoder
|
||||
{
|
||||
|
||||
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 /* nsUCvJaSupport_h___ */
|
||||
@ -79,28 +79,9 @@ static const PRUint16 *gMappingTables[SIZE_OF_TABLES] = {
|
||||
|
||||
nsUnicodeToEUCJP::nsUnicodeToEUCJP()
|
||||
: nsMultiTableEncoderSupport(SIZE_OF_TABLES,
|
||||
(uShiftTable**) gShiftTables,
|
||||
(uMappingTable**) gMappingTables)
|
||||
(uShiftTable**) gShiftTables,
|
||||
(uMappingTable**) gMappingTables,
|
||||
3 /* max length = src * 3 */)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsUnicodeToEUCJP_h___
|
||||
#define nsUnicodeToEUCJP_h___
|
||||
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToEUCJP [declaration]
|
||||
@ -59,18 +59,8 @@ public:
|
||||
*/
|
||||
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___ */
|
||||
|
||||
@ -87,8 +87,11 @@ static const PRInt16 * g_ufShiftTables[SIZE_OF_TABLES] = {
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToISO2022JP [implementation]
|
||||
|
||||
// worst case max length:
|
||||
// 1 2 3 4 5 6 7 8
|
||||
// ESC $ B XX XX ESC ( B
|
||||
nsUnicodeToISO2022JP::nsUnicodeToISO2022JP()
|
||||
: nsEncoderSupport()
|
||||
: nsEncoderSupport(8)
|
||||
{
|
||||
mHelper = NULL;
|
||||
Reset();
|
||||
@ -99,16 +102,6 @@ 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)
|
||||
@ -249,17 +242,6 @@ NS_IMETHODIMP nsUnicodeToISO2022JP::FinishNoBuff(char * aDest,
|
||||
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;
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsUnicodeToISO2022JP_h___
|
||||
#define nsUnicodeToISO2022JP_h___
|
||||
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToISO2022JP [declaration]
|
||||
@ -64,11 +64,6 @@ public:
|
||||
*/
|
||||
virtual ~nsUnicodeToISO2022JP();
|
||||
|
||||
/**
|
||||
* Static class constructor.
|
||||
*/
|
||||
static nsresult CreateInstance(nsISupports **aResult);
|
||||
|
||||
protected:
|
||||
|
||||
PRInt32 mCharset; // current character set
|
||||
@ -83,8 +78,6 @@ protected:
|
||||
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);
|
||||
};
|
||||
|
||||
@ -50,27 +50,7 @@ static PRInt16 g0201ShiftTable[] = {
|
||||
|
||||
nsUnicodeToJISx0201::nsUnicodeToJISx0201()
|
||||
: nsTableEncoderSupport((uShiftTable*) g0201ShiftTable,
|
||||
(uMappingTable*) g_uf0201Mapping)
|
||||
(uMappingTable*) g_uf0201Mapping, 1)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsUnicodeToJISx0201_h___
|
||||
#define nsUnicodeToJISx0201_h___
|
||||
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToJISx0201 [declaration]
|
||||
@ -59,18 +59,8 @@ public:
|
||||
*/
|
||||
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___ */
|
||||
|
||||
@ -51,27 +51,8 @@ static PRInt16 g0208ShiftTable[] = {
|
||||
|
||||
nsUnicodeToJISx0208::nsUnicodeToJISx0208()
|
||||
: nsTableEncoderSupport( (uShiftTable*) g0208ShiftTable,
|
||||
(uMappingTable*) g_uf0208Mapping)
|
||||
(uMappingTable*) g_uf0208Mapping,
|
||||
2 /* max length = src * 2 */)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsUnicodeToJISx0208_h___
|
||||
#define nsUnicodeToJISx0208_h___
|
||||
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToJISx0208 [declaration]
|
||||
@ -59,18 +59,8 @@ public:
|
||||
*/
|
||||
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___ */
|
||||
|
||||
@ -51,27 +51,8 @@ static PRInt16 g0212ShiftTable[] = {
|
||||
|
||||
nsUnicodeToJISx0212::nsUnicodeToJISx0212()
|
||||
: nsTableEncoderSupport((uShiftTable*) g0212ShiftTable,
|
||||
(uMappingTable*) g_uf0212Mapping)
|
||||
(uMappingTable*) g_uf0212Mapping,
|
||||
2 /* max len = src * 2 */)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsUnicodeToJISx0212_h___
|
||||
#define nsUnicodeToJISx0212_h___
|
||||
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToJISx0212 [declaration]
|
||||
@ -59,18 +59,8 @@ public:
|
||||
*/
|
||||
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___ */
|
||||
|
||||
@ -58,27 +58,8 @@ static const PRInt16 g_SJISShiftTable[] = {
|
||||
|
||||
nsUnicodeToSJIS::nsUnicodeToSJIS()
|
||||
: nsTableEncoderSupport((uShiftTable*) &g_SJISShiftTable,
|
||||
(uMappingTable*) &g_SJISMappingTable)
|
||||
(uMappingTable*) &g_SJISMappingTable,
|
||||
2 /* max length = src * 2 */)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsUnicodeToSJIS::CreateInstance(nsISupports ** aResult)
|
||||
{
|
||||
nsIUnicodeEncoder *p = new nsUnicodeToSJIS();
|
||||
if(p) {
|
||||
*aResult = p;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTableEncoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsUnicodeToSJIS::GetMaxLength(const PRUnichar * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
*aDestLength = 2*aSrcLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsUnicodeToSJIS_h___
|
||||
#define nsUnicodeToSJIS_h___
|
||||
|
||||
#include "nsUCvJaSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsUnicodeToSJIS [declaration]
|
||||
@ -59,18 +59,8 @@ public:
|
||||
*/
|
||||
nsUnicodeToSJIS();
|
||||
|
||||
/**
|
||||
* 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 /* nsUnicodeToSJIS_h___ */
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
nsUCvKOCID.h
|
||||
|
||||
@ -27,9 +27,8 @@ VPATH = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = ucvko
|
||||
LIBRARY_NAME = ucvko
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
LIBRARY_NAME = ucvko_s
|
||||
FORCE_STATIC_LIB=1
|
||||
MODULE_NAME = nsUCvKoModule
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
@ -48,16 +47,15 @@ CPPSRCS = \
|
||||
nsUnicodeToJohab.cpp \
|
||||
nsJohabToUnicode.cpp \
|
||||
nsUnicodeToJohabNoAscii.cpp \
|
||||
nsUCvKOSupport.cpp \
|
||||
nsUCvKoModule.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = nsUCvKOCID.h
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
LOCAL_INCLUDES = -I$(srcdir)/../util
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -D_IMPL_NS_INTL
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
DEFINES += -DWIN32_LEAN_AND_MEAN
|
||||
endif
|
||||
|
||||
@ -95,7 +95,7 @@ static const PRUint16 *g_CP949ShiftTableSet [] = {
|
||||
};
|
||||
|
||||
static const PRUint16 *g_CP949MappingTableSet [] ={
|
||||
g_AsciiMapping,
|
||||
g_ucvko_AsciiMapping,
|
||||
g_HangulNullMapping,
|
||||
g_utKSC5601Mapping,
|
||||
g_utCP949NoKSCHangulMapping,
|
||||
@ -112,19 +112,7 @@ nsCP949ToUnicode::nsCP949ToUnicode()
|
||||
: nsMultiTableDecoderSupport(sizeof(g_CP949Ranges) / sizeof(g_CP949Ranges[0]),
|
||||
(uRange*) &g_CP949Ranges,
|
||||
(uShiftTable**) &g_CP949ShiftTableSet,
|
||||
(uMappingTable**) &g_CP949MappingTableSet)
|
||||
(uMappingTable**) &g_CP949MappingTableSet, 1)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Subclassing of nsTablesDecoderSupport class [implementation]
|
||||
|
||||
NS_IMETHODIMP nsCP949ToUnicode::GetMaxLength(const char * aSrc,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// we are a single byte to Unicode converter, so...
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_OK_UDEC_EXACTLENGTH;
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef nsCP949ToUnicode_h___
|
||||
#define nsCP949ToUnicode_h___
|
||||
|
||||
#include "nsUCvKOSupport.h"
|
||||
#include "nsUCSupport.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCP949ToUnicode [declaration]
|
||||
@ -60,12 +60,6 @@ public:
|
||||
nsCP949ToUnicode();
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Subclassing of nsDecoderSupport class [declaration]
|
||||
|
||||
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
};
|
||||
|
||||
#endif /* nsCP949ToUnicode_h___ */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user