first check in unicode converter. Didn't build on Mac/UNIX yet. Didn't hookup with main
build process yet. git-svn-id: svn://10.0.0.236/trunk@17285 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
d371d9c561
commit
f5e08862ab
22
mozilla/intl/makefile.win
Normal file
22
mozilla/intl/makefile.win
Normal file
@ -0,0 +1,22 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..
|
||||
|
||||
DIRS=uconv
|
||||
|
||||
include <$(DEPTH)\layout\config\rules.mak>
|
||||
22
mozilla/intl/uconv/makefile.win
Normal file
22
mozilla/intl/uconv/makefile.win
Normal file
@ -0,0 +1,22 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
DIRS=public src tests
|
||||
|
||||
include <$(DEPTH)\layout\config\rules.mak>
|
||||
31
mozilla/intl/uconv/public/makefile.win
Normal file
31
mozilla/intl/uconv/public/makefile.win
Normal file
@ -0,0 +1,31 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
EXPORTS = \
|
||||
nsICharsetConverterManager.h \
|
||||
nsICharsetConverterInfo.h \
|
||||
nsIUnicodeDecoder.h \
|
||||
nsIUnicodeEncoder.h \
|
||||
nsConverterCID.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE=intl
|
||||
|
||||
include <$(DEPTH)\layout\config\rules.mak>
|
||||
|
||||
30
mozilla/intl/uconv/public/nsConverterCID.h
Normal file
30
mozilla/intl/uconv/public/nsConverterCID.h
Normal file
@ -0,0 +1,30 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsConverterCID_h___
|
||||
#define nsConverterCID_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
// Class ID for our Ascii2Unicode charset converter
|
||||
// {A3254CB0-8E20-11d2-8A98-00600811A836}
|
||||
NS_DECLARE_ID(kAscii2UnicodeCID,
|
||||
0xa3254cb0, 0x8e20, 0x11d2, 0x8a, 0x98, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36);
|
||||
|
||||
#endif /* nsConverterCID_h___ */
|
||||
63
mozilla/intl/uconv/public/nsICharsetConverterInfo.h
Normal file
63
mozilla/intl/uconv/public/nsICharsetConverterInfo.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsICharsetConverterInfo_h___
|
||||
#define nsICharsetConverterInfo_h___
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
// Interface ID for our Converter Information interface
|
||||
// {6A7730E0-8ED3-11d2-8A98-00600811A836}
|
||||
NS_DECLARE_ID(kICharsetConverterInfoIID,
|
||||
0x6a7730e0, 0x8ed3, 0x11d2, 0x8a, 0x98, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36);
|
||||
|
||||
/**
|
||||
* Interface for getting the Charset Converter information.
|
||||
*
|
||||
* This info interface is a little more general, covering any conveter, not
|
||||
* only Unicode encoders/decoders. Now an interesting question is who is
|
||||
* supposed to implement it? For now: the Factory of the converter. That is
|
||||
* because of the way the converter info is gathered: a factory is a much
|
||||
* smaller and easier to instantiate than a whole Converter object. However,
|
||||
* this may change in future, as new moniker mechanisms are added to xp-com.
|
||||
*
|
||||
* @created 08/Dec/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsICharsetConverterInfo : public nsISupports
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns the character set this converter is converting from.
|
||||
*
|
||||
* @param aCharset [OUT] a name/alias for the source charset
|
||||
*/
|
||||
NS_IMETHOD GetCharsetSrc(nsString ** aCharset) = 0;
|
||||
|
||||
/**
|
||||
* Returns the character set this converter is converting into.
|
||||
*
|
||||
* @param aCharset [OUT] a name/alias for the destination charset
|
||||
*/
|
||||
NS_IMETHOD GetCharsetDest(nsString ** aCharset) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsICharsetConverterInfo_h___ */
|
||||
131
mozilla/intl/uconv/public/nsICharsetConverterManager.h
Normal file
131
mozilla/intl/uconv/public/nsICharsetConverterManager.h
Normal file
@ -0,0 +1,131 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsICharsetConverterManager_h___
|
||||
#define nsICharsetConverterManager_h___
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
|
||||
// Interface ID for our ConverterManager interface
|
||||
// {1E3F79F0-6B6B-11d2-8A86-00600811A836}
|
||||
NS_DECLARE_ID(kICharsetConverterManagerIID,
|
||||
0x1e3f79f0, 0x6b6b, 0x11d2, 0x8a, 0x86, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36);
|
||||
|
||||
// Class ID for our ConverterManager implementation
|
||||
// {1E3F79F1-6B6B-11d2-8A86-00600811A836}
|
||||
NS_DECLARE_ID(kCharsetConverterManagerCID,
|
||||
0x1e3f79f1, 0x6b6b, 0x11d2, 0x8a, 0x86, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36);
|
||||
|
||||
// XXX move this into xpcom/nsError.h
|
||||
#define NS_ERROR_MODULE_INTL 10
|
||||
|
||||
#define NS_CONVERTER_NOT_FOUND \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_INTL,1)
|
||||
|
||||
/**
|
||||
* Interface for a Manager of Charset Converters.
|
||||
*
|
||||
* Note: The term "Charset" used in the classes, interfaces and file names
|
||||
* should be read as "Coded Character Set". I am saying "charset" only for
|
||||
* length considerations: it is a much shorter word. This convention is for
|
||||
* source-code only, in the attached documents I will be either using the
|
||||
* full expression or I'll specify a different convetion.
|
||||
*
|
||||
* XXX Move the ICharsetManager methods (the last methods in the interface)
|
||||
* into a separate interface. They are conceptually independent. I left them
|
||||
* here only for easier implementation.
|
||||
*
|
||||
* XXX Add HasUnicodeEncoder() and HasUnicodeDecoder() methods.
|
||||
*
|
||||
* @created 17/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsICharsetConverterManager : public nsISupports
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Find and instantiate a Converter able to encode from Unicode into the
|
||||
* destination charset.
|
||||
*
|
||||
* @param aDest [IN] the known name/alias of the destination charset
|
||||
* @param aResult [OUT] the charset converter
|
||||
* @return NS_CONVERTER_NOT_FOUND if no converter was found for
|
||||
* this charset
|
||||
*/
|
||||
NS_IMETHOD GetUnicodeEncoder(const nsString * aDest,
|
||||
nsIUnicodeEncoder ** aResult) = 0;
|
||||
|
||||
/**
|
||||
* Find and instantiate a Converter able to decode from the source charset
|
||||
* into Unicode.
|
||||
*
|
||||
* @param aSrc [IN] the known name/alias of the source charset
|
||||
* @param aResult [OUT] the charset converter
|
||||
* @return NS_CONVERTER_NOT_FOUND if no converter was found for
|
||||
* this charset
|
||||
*/
|
||||
NS_IMETHOD GetUnicodeDecoder(const nsString * aSrc,
|
||||
nsIUnicodeDecoder ** aResult) = 0;
|
||||
|
||||
/**
|
||||
* Returns a list of charsets for which we have converters from Unicode.
|
||||
*
|
||||
* @param aResult [OUT] an array of pointers to Strings (charset names)
|
||||
* @param aCount [OUT] the size (number of elements) of that array
|
||||
*/
|
||||
NS_IMETHOD GetEncodableCharsets(nsString *** aResult, PRInt32 * aCount) = 0;
|
||||
|
||||
/**
|
||||
* Returns a list of charsets for which we have converters into Unicode.
|
||||
*
|
||||
* @param aResult [OUT] an array of pointers to Strings (charset names)
|
||||
* @param aCount [OUT] the size (number of elements) of that array
|
||||
*/
|
||||
NS_IMETHOD GetDecodableCharsets(nsString *** aResult, PRInt32 * aCount) = 0;
|
||||
|
||||
/**
|
||||
* Resolves the canonical name of a charset. If the given name is unknown
|
||||
* to the resolver, a new identical string will be returned! This way,
|
||||
* new & unknown charsets are not rejected and they are treated as any other
|
||||
* charset except they can't have aliases.
|
||||
*
|
||||
* @param aCharset [IN] the known name/alias of the character set
|
||||
* @param aResult [OUT] the canonical name of the character set
|
||||
*/
|
||||
NS_IMETHOD GetCharsetName(const nsString * aCharset,
|
||||
nsString ** aResult) = 0;
|
||||
|
||||
/**
|
||||
* Returns a list containing all the legal names for a given charset. The
|
||||
* list will allways have at least 1 element: the cannonical name for that
|
||||
* charset.
|
||||
*
|
||||
* @param aCharset [IN] a known name/alias of the character set
|
||||
* @param aResult [OUT] the list; in the first position is the
|
||||
* cannonical name, then the other aliases
|
||||
*/
|
||||
NS_IMETHOD GetCharsetNames(const nsString * aCharset,
|
||||
nsString *** aResult, PRInt32 * aCount) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsICharsetConverterManager_h___ */
|
||||
132
mozilla/intl/uconv/public/nsIUnicodeDecoder.h
Normal file
132
mozilla/intl/uconv/public/nsIUnicodeDecoder.h
Normal file
@ -0,0 +1,132 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIUnicodeDecoder_h___
|
||||
#define nsIUnicodeDecoder_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
// Interface ID for our Unicode Decoder interface
|
||||
// {B2F178E1-832A-11d2-8A8E-00600811A836}
|
||||
NS_DECLARE_ID(kIUnicodeDecoderIID,
|
||||
0xb2f178e1, 0x832a, 0x11d2, 0x8a, 0x8e, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36);
|
||||
|
||||
// XXX move this into xpcom/nsError.h
|
||||
#define NS_ERROR_MODULE_INTL 10
|
||||
|
||||
#define NS_EXACT_LENGTH \
|
||||
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_INTL,11)
|
||||
#define NS_PARTIAL_MORE_INPUT \
|
||||
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_INTL,12)
|
||||
#define NS_PARTIAL_MORE_OUTPUT \
|
||||
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_INTL,13)
|
||||
#define NS_ERROR_ILLEGAL_INPUT \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_INTL,14)
|
||||
|
||||
/**
|
||||
* Interface for a Converter from a Charset into Unicode.
|
||||
*
|
||||
* @created 23/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsIUnicodeDecoder : public nsISupports
|
||||
{
|
||||
public:
|
||||
|
||||
enum {
|
||||
kOnError_Recover, // on an error, recover and continue
|
||||
kOnError_Signal, // on an error, stop and signal
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts the data from one character set to Unicode.
|
||||
*
|
||||
* About the byte ordering issue.
|
||||
* - For input, if the converter cares (that depends of the charset, a
|
||||
* singlebyte can ignore the byte ordering) it should assume network order.
|
||||
* If necessary and requested, we can add a method SetInputByteOrder so
|
||||
* that the reverse order can be used, too. That method would have as
|
||||
* default the assumed order.
|
||||
* - The output stream is Unicode, having the byte order which is internal
|
||||
* for the machine the converter is running on.
|
||||
*
|
||||
* @param aDest [IN/OUT] the destination data buffer
|
||||
* @param aDestOffset [IN] the offset in the destination data buffer
|
||||
* @param aDestLength [IN/OUT] the length of destination data buffer; after
|
||||
* conversion will contain the number of bytes written
|
||||
* @param aSrc [IN] the source data buffer
|
||||
* @param aSrcOffset [IN] the offset in the source data buffer
|
||||
* @param aSrcLength [IN/OUT] the length of source data buffer; after
|
||||
* conversion will contain the number of bytes read
|
||||
* @return NS_PARTIAL_MORE_INPUT if only a partial conversion was
|
||||
* done; more input is needed to continue
|
||||
* NS_PARTIAL_MORE_OUTPUT if only a partial conversion
|
||||
* was done; more output space is needed to continue
|
||||
* NS_ERROR_ILLEGAL_INPUT if an illegal input sequence
|
||||
* was encountered and the behavior was set to "signal"
|
||||
*/
|
||||
NS_IMETHOD Convert(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength, const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 * aSrcLength) = 0;
|
||||
|
||||
/**
|
||||
* Finishes the conversion. The converter has the possibility to write some
|
||||
* extra data, flush its final state.
|
||||
*
|
||||
* @param aDest [IN/OUT] the destination data buffer
|
||||
* @param aDestOffset [IN] the offset in the destination data buffer
|
||||
* @param aDestLength [IN/OUT] the length of destination data buffer; after
|
||||
* converstion will contain the number of bytes written
|
||||
* @return NS_PARTIAL_MORE_OUTPUT if only a partial finish was
|
||||
* done; more output space is needed to continue
|
||||
*/
|
||||
NS_IMETHOD Finish(PRUnichar * aDest, PRInt32 aDestOffset, PRInt32 * aDestLength)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Returns a quick estimation of the size of the buffer needed to hold the
|
||||
* converted data. Remember: this is an estimation and not necessarily
|
||||
* correct.
|
||||
*
|
||||
* @param aSrc [IN] the source data buffer
|
||||
* @param aSrcOffset [IN] the offset in the source data buffer
|
||||
* @param aSrcLength [IN] the length of source data buffer
|
||||
* @param aDestLength [OUT] the needed size of the dest buffer
|
||||
* @return NS_EXACT_LENGTH if an exact length was computed
|
||||
*/
|
||||
NS_IMETHOD Length(const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 aSrcLength, PRInt32 * aDestLength) = 0;
|
||||
|
||||
/**
|
||||
* Resets the charset converter so it may be reused on a different buffer.
|
||||
*/
|
||||
NS_IMETHOD Reset() = 0;
|
||||
|
||||
/**
|
||||
* Specify what to do when an illegal input sequence is encountered.
|
||||
* - stop and signal error
|
||||
* - recover and continue (default)
|
||||
*
|
||||
* @param aOrder [IN] the behavior; taken from the enum
|
||||
*/
|
||||
NS_IMETHOD SetInputErrorBehavior(PRInt32 aBehavior) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIUnicodeDecoder_h___ */
|
||||
41
mozilla/intl/uconv/public/nsIUnicodeEncoder.h
Normal file
41
mozilla/intl/uconv/public/nsIUnicodeEncoder.h
Normal file
@ -0,0 +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.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIUnicodeEncoder_h___
|
||||
#define nsIUnicodeEncoder_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
// Interface ID for our Unicode Encoder interface
|
||||
// {2B2CA3D0-A4C9-11d2-8AA1-00600811A836}
|
||||
NS_DECLARE_ID(kIUnicodeEncoderIID,
|
||||
0x2b2ca3d0, 0xa4c9, 0x11d2, 0x8a, 0xa1, 0x0, 0x60, 0x8, 0x11, 0xa8, 0x36);
|
||||
|
||||
/**
|
||||
* Interface for a Converter from Unicode into a Charset.
|
||||
*
|
||||
* @created 23/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsIUnicodeEncoder : public nsISupports
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
#endif /* nsIUnicodeEncoder_h___ */
|
||||
69
mozilla/intl/uconv/src/makefile.win
Normal file
69
mozilla/intl/uconv/src/makefile.win
Normal file
@ -0,0 +1,69 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DEFINES=-D_IMPL_NS_INTL -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
MODULE=intl
|
||||
REQUIRES=xpcom
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = uconv
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
CPPSRCS = \
|
||||
nsCharsetConverterManager.cpp \
|
||||
nsAscii2Unicode.cpp \
|
||||
nsUConvDll.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsCharsetConverterManager.obj \
|
||||
.\$(OBJDIR)\nsAscii2Unicode.obj \
|
||||
.\$(OBJDIR)\nsUConvDll.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS= \
|
||||
$(NULL)
|
||||
|
||||
LINCS= \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\intl \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(LIBNSPR)
|
||||
|
||||
MISCDEP = $(LLIBS)
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\layout\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\$(DLLNAME).dll
|
||||
233
mozilla/intl/uconv/src/nsAscii2Unicode.cpp
Normal file
233
mozilla/intl/uconv/src/nsAscii2Unicode.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsAscii2Unicode.h"
|
||||
#include "nsConverterCID.h"
|
||||
#include "nsUConvDll.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
#define NS_SRC_CHARSET "Ascii"
|
||||
#define NS_DEST_CHARSET "Unicode"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsAscii2Unicode [declaration]
|
||||
|
||||
/**
|
||||
* A character set converter from Ascii to Unicode.
|
||||
*
|
||||
* This particular converter does not use the general single-byte converter
|
||||
* helper object. That is because someone may want to optimise this converter
|
||||
* to the fullest, as it is the most heavily used one.
|
||||
*
|
||||
* Multithreading: not an issue, the object has one instance per user thread.
|
||||
* As a plus, it is also stateless!
|
||||
*
|
||||
* @created 23/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsAscii2Unicode : public nsIUnicodeDecoder
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsAscii2Unicode();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsAscii2Unicode();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIUnicodeDecoder [declaration]
|
||||
|
||||
NS_IMETHOD Convert(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength,const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 * aSrcLength);
|
||||
NS_IMETHOD Finish(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Length(const char * aSrc, PRInt32 aSrcOffset, PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength);
|
||||
NS_IMETHOD Reset();
|
||||
NS_IMETHOD SetInputErrorBehavior(PRInt32 aBehavior);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsAscii2Unicode [implementation]
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAscii2Unicode, kIUnicodeDecoderIID);
|
||||
|
||||
nsAscii2Unicode::nsAscii2Unicode()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsAscii2Unicode::~nsAscii2Unicode()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverter [implementation]
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::Convert(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength,
|
||||
const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 * aSrcLength)
|
||||
{
|
||||
if (aDest == NULL) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRInt32 len = PR_MIN(*aSrcLength, *aDestLength);
|
||||
for (PRInt32 i=0; i<len; i++) *aDest++ = ((PRUint8)*aSrc++);
|
||||
|
||||
nsresult res = (*aSrcLength > len)? NS_PARTIAL_MORE_OUTPUT : NS_OK;
|
||||
*aSrcLength = *aDestLength = len;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::Finish(PRUnichar * aDest, PRInt32 aDestOffset,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// it is really only a stateless converter...
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::Length(const char * aSrc, PRInt32 aSrcOffset,
|
||||
PRInt32 aSrcLength,
|
||||
PRInt32 * aDestLength)
|
||||
{
|
||||
// we are a single byte to Unicode converter, so...
|
||||
*aDestLength = aSrcLength;
|
||||
return NS_EXACT_LENGTH;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::Reset()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2Unicode::SetInputErrorBehavior(PRInt32 aBehavior)
|
||||
{
|
||||
// no input error possible, this encoding is too simple
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsAscii2UnicodeFactory [implementation]
|
||||
|
||||
nsAscii2UnicodeFactory::nsAscii2UnicodeFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsAscii2UnicodeFactory::~nsAscii2UnicodeFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsISupports [implementation]
|
||||
|
||||
NS_IMPL_ADDREF(nsAscii2UnicodeFactory);
|
||||
NS_IMPL_RELEASE(nsAscii2UnicodeFactory);
|
||||
|
||||
nsresult nsAscii2UnicodeFactory::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, kICharsetConverterInfoIID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
if (aIID.Equals(kClassIID)) {
|
||||
*aInstancePtr = (void*) ((nsICharsetConverterInfo*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*) ((nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) ((nsISupports*)(nsIFactory*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIFactory [implementation]
|
||||
|
||||
NS_IMETHODIMP nsAscii2UnicodeFactory::CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsIUnicodeDecoder * t = new nsAscii2Unicode;
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2UnicodeFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [implementation]
|
||||
|
||||
NS_IMETHODIMP nsAscii2UnicodeFactory::GetCharsetSrc(nsString ** aCharset)
|
||||
{
|
||||
(*aCharset) = new nsString(NS_SRC_CHARSET);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAscii2UnicodeFactory::GetCharsetDest(nsString ** aCharset)
|
||||
{
|
||||
(*aCharset) = new nsString(NS_DEST_CHARSET);
|
||||
return NS_OK;
|
||||
}
|
||||
68
mozilla/intl/uconv/src/nsAscii2Unicode.h
Normal file
68
mozilla/intl/uconv/src/nsAscii2Unicode.h
Normal file
@ -0,0 +1,68 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsAscii2Unicode_h___
|
||||
#define nsAscii2Unicode_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsAscii2UnicodeFactory [declaration]
|
||||
|
||||
/**
|
||||
* Factory class for the nsAscii2Unicode objects.
|
||||
*
|
||||
* @created 08/Dec/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsAscii2UnicodeFactory : public nsIFactory, nsICharsetConverterInfo
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsAscii2UnicodeFactory();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsAscii2UnicodeFactory();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIFactory [declaration]
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterInfo [declaration]
|
||||
|
||||
NS_IMETHOD GetCharsetSrc(nsString ** aCharset);
|
||||
NS_IMETHOD GetCharsetDest(nsString ** aCharset);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsAscii2Unicode_h___ */
|
||||
443
mozilla/intl/uconv/src/nsCharsetConverterManager.cpp
Normal file
443
mozilla/intl/uconv/src/nsCharsetConverterManager.cpp
Normal file
@ -0,0 +1,443 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsICharsetConverterInfo.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsCharsetConverterManager.h"
|
||||
#include "nsConverterCID.h"
|
||||
#include "nsUConvDll.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
struct ConverterInfo
|
||||
{
|
||||
nsString * mCharset;
|
||||
const nsCID * mCID;
|
||||
|
||||
~ConverterInfo ()
|
||||
{
|
||||
if (mCharset != NULL) delete mCharset;
|
||||
}
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCharsetConverterManager [declaration]
|
||||
|
||||
/**
|
||||
* The actual implementation of the nsICharsetConverterManager interface.
|
||||
*
|
||||
* Requirements for a Manager:
|
||||
* - singleton
|
||||
* - special lifetime (survive even if it's not used, die only under memory
|
||||
* pressure conditions or app termination)
|
||||
*
|
||||
* Ways of implementing it & fulfill those requirements:
|
||||
* + simple xpcom object (current implementation model)
|
||||
* - xpcom service (best, but no support available yet)
|
||||
* - global class with static methods (ie part of the platform)
|
||||
*
|
||||
* Interesting observation: the NS_IMPL_IDS macros suck! In a given file, one
|
||||
* can only declare OR define IDs, not both. Considering the unique-per-dll
|
||||
* implementation, the headers inclusion and IDs declaration vs. definition
|
||||
* becomes quite tricky.
|
||||
*
|
||||
* XXX What happens in a multithreaded environment?!
|
||||
* XXX Make this a service; use the service manager; etc.
|
||||
* XXX Have a clear and consistent extensibility model.
|
||||
*
|
||||
* @created 17/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsCharsetConverterManager : public nsICharsetConverterManager
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Pointer to the unique instance of this class.
|
||||
*/
|
||||
static nsICharsetConverterManager * mInstance;
|
||||
|
||||
/**
|
||||
* The Mapping data structures.
|
||||
*/
|
||||
ConverterInfo * mEncArray;
|
||||
PRInt32 mEncSize;
|
||||
ConverterInfo * mDecArray;
|
||||
PRInt32 mDecSize;
|
||||
|
||||
PRBool mMappingDone;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsCharsetConverterManager();
|
||||
|
||||
/**
|
||||
* Creates some sort of mapping (Charset, Charset) -> Converter.
|
||||
*/
|
||||
nsresult CreateMapping();
|
||||
|
||||
/**
|
||||
* Creates the Converters list.
|
||||
*/
|
||||
nsresult CreateConvertersList();
|
||||
|
||||
/**
|
||||
* Gathers the necessary informations about each Converter.
|
||||
*/
|
||||
nsresult GatherConvertersInfo();
|
||||
|
||||
/**
|
||||
* Attempts to return a ICharsetConverterInfo reference for the given charset
|
||||
* in the array. If errors, the converter will be eliminated from the array.
|
||||
*/
|
||||
nsICharsetConverterInfo * GetICharsetConverterInfo(ConverterInfo * ci,
|
||||
PRInt32 aIndex, PRInt32 * aSize);
|
||||
|
||||
/**
|
||||
* General method for finding and instantiating a Converter.
|
||||
*/
|
||||
nsresult GetCharsetConverter(const nsString * aSrc, void ** aResult,
|
||||
const nsCID * aCID, const ConverterInfo * aArray, PRInt32 aSize);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsCharsetConverterManager();
|
||||
|
||||
/**
|
||||
* Unique factory method for this class (the constructor is private).
|
||||
*
|
||||
* @return a singleton object, instance of this class
|
||||
*/
|
||||
static nsICharsetConverterManager * GetInstance();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterManager [declaration]
|
||||
|
||||
NS_IMETHOD GetUnicodeEncoder(const nsString * aDest,
|
||||
nsIUnicodeEncoder ** aResult);
|
||||
NS_IMETHOD GetUnicodeDecoder(const nsString * aSrc,
|
||||
nsIUnicodeDecoder ** aResult);
|
||||
NS_IMETHOD GetEncodableCharsets(nsString *** aResult, PRInt32 * aCount);
|
||||
NS_IMETHOD GetDecodableCharsets(nsString *** aResult, PRInt32 * aCount);
|
||||
NS_IMETHOD GetCharsetName(const nsString * aCharset, nsString ** aResult);
|
||||
NS_IMETHOD GetCharsetNames(const nsString * aCharset, nsString *** aResult,
|
||||
PRInt32 * aCount);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsCharsetConverterManager [implementation]
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCharsetConverterManager, kICharsetConverterManagerIID);
|
||||
|
||||
nsICharsetConverterManager * nsCharsetConverterManager::mInstance = NULL;
|
||||
|
||||
nsCharsetConverterManager::nsCharsetConverterManager()
|
||||
{
|
||||
mEncArray = NULL;
|
||||
mEncSize = 0;
|
||||
mDecArray = NULL;
|
||||
mDecSize = 0;
|
||||
|
||||
mMappingDone = PR_FALSE;
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsCharsetConverterManager::~nsCharsetConverterManager()
|
||||
{
|
||||
mInstance = NULL;
|
||||
if (mEncArray != NULL) delete [] mEncArray;
|
||||
if (mDecArray != NULL) delete [] mDecArray;
|
||||
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsICharsetConverterManager * nsCharsetConverterManager::GetInstance()
|
||||
{
|
||||
if (mInstance == NULL) mInstance = new nsCharsetConverterManager();
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
nsresult nsCharsetConverterManager::CreateMapping()
|
||||
{
|
||||
mMappingDone = PR_TRUE;
|
||||
|
||||
nsresult res = CreateConvertersList();
|
||||
if NS_FAILED(res) return res;
|
||||
|
||||
return GatherConvertersInfo();
|
||||
}
|
||||
|
||||
// XXX Hack! These lists should be obtained from the Repository, in a Component
|
||||
// Category fashion. Hoever, for now this is the place where you should add
|
||||
// new converters. Just increase the array Sizes and place the CIDs in the
|
||||
// slots.
|
||||
nsresult nsCharsetConverterManager::CreateConvertersList()
|
||||
{
|
||||
mDecSize = 1;
|
||||
mDecArray = new ConverterInfo [mDecSize];
|
||||
|
||||
mDecArray[0].mCID = &kAscii2UnicodeCID;
|
||||
|
||||
mEncSize = 0;
|
||||
mEncArray = NULL;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCharsetConverterManager::GatherConvertersInfo()
|
||||
{
|
||||
nsICharsetConverterInfo * info;
|
||||
nsString * str;
|
||||
PRInt32 i;
|
||||
|
||||
for (i=0;i<mEncSize;i++) {
|
||||
info = GetICharsetConverterInfo(mEncArray, i, &mEncSize);
|
||||
if (info == NULL) continue;
|
||||
|
||||
info->GetCharsetDest(&str);
|
||||
GetCharsetName(str,&mEncArray[i].mCharset);
|
||||
delete str;
|
||||
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
|
||||
for (i=0;i<mDecSize;i++) {
|
||||
info = GetICharsetConverterInfo(mDecArray, i, &mDecSize);
|
||||
if (info == NULL) continue;
|
||||
|
||||
info->GetCharsetSrc(&str);
|
||||
GetCharsetName(str,&mDecArray[i].mCharset);
|
||||
delete str;
|
||||
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsICharsetConverterInfo *
|
||||
nsCharsetConverterManager::GetICharsetConverterInfo(ConverterInfo * aArray,
|
||||
PRInt32 aIndex,
|
||||
PRInt32 * aSize)
|
||||
{
|
||||
nsresult res;
|
||||
nsIFactory * factory;
|
||||
nsICharsetConverterInfo * info;
|
||||
|
||||
res=nsRepository::FindFactory(*(aArray[aIndex].mCID), &factory);
|
||||
if (NS_FAILED(res)) goto reduceArray;
|
||||
|
||||
res=factory->QueryInterface(kICharsetConverterInfoIID, (void ** )&info);
|
||||
NS_RELEASE(factory);
|
||||
if (NS_FAILED(res)) goto reduceArray;
|
||||
|
||||
return info;
|
||||
|
||||
reduceArray:
|
||||
|
||||
PRInt32 i;
|
||||
|
||||
(*aSize)--;
|
||||
for (i=aIndex; i<*aSize;) aArray[i] = aArray[i++];
|
||||
if (i>=0) {
|
||||
aArray[i].mCharset = NULL;
|
||||
aArray[i].mCID = NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nsresult nsCharsetConverterManager::GetCharsetConverter(
|
||||
const nsString * aSrc,
|
||||
void ** aResult,
|
||||
const nsCID * aCID,
|
||||
const ConverterInfo * aArray,
|
||||
PRInt32 aSize)
|
||||
{
|
||||
nsresult res;
|
||||
nsString * str;
|
||||
GetCharsetName(aSrc, &str);
|
||||
|
||||
*aResult = NULL;
|
||||
for (PRInt32 i=0; i<aSize; i++) if (str->Equals(*(aArray[i].mCharset))) {
|
||||
res = nsRepository::CreateInstance(*(aArray[i].mCID),NULL,*aCID,aResult);
|
||||
break;
|
||||
}
|
||||
|
||||
delete str;
|
||||
|
||||
// well, we didn't found any converter. Damn, life sucks!
|
||||
if ((*aResult == NULL) && (NS_SUCCEEDED(res)))
|
||||
res = NS_CONVERTER_NOT_FOUND;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsICharsetConverterManager [implementation]
|
||||
|
||||
NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder(
|
||||
const nsString * aDest,
|
||||
nsIUnicodeEncoder ** aResult)
|
||||
{
|
||||
nsresult res;
|
||||
if (!mMappingDone) {
|
||||
res = CreateMapping();
|
||||
if NS_FAILED(res) return res;
|
||||
}
|
||||
|
||||
return GetCharsetConverter(aDest, (void **) aResult, &kIUnicodeEncoderIID,
|
||||
mEncArray, mEncSize);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
|
||||
const nsString * aSrc,
|
||||
nsIUnicodeDecoder ** aResult)
|
||||
{
|
||||
nsresult res;
|
||||
if (!mMappingDone) {
|
||||
res = CreateMapping();
|
||||
if NS_FAILED(res) return res;
|
||||
}
|
||||
|
||||
return GetCharsetConverter(aSrc, (void **) aResult, &kIUnicodeDecoderIID,
|
||||
mDecArray, mDecSize);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCharsetConverterManager::GetEncodableCharsets(
|
||||
nsString *** aResult,
|
||||
PRInt32 * aCount)
|
||||
{
|
||||
nsresult res;
|
||||
if (!mMappingDone) {
|
||||
res = CreateMapping();
|
||||
if NS_FAILED(res) return res;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
*aCount = 0;
|
||||
if (mEncSize != 0) {
|
||||
*aResult = new nsString * [mEncSize];
|
||||
*aCount = mEncSize;
|
||||
for (PRInt32 i=0;i<mEncSize;i++) (*aResult)[i]=mEncArray[i].mCharset;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCharsetConverterManager::GetDecodableCharsets(
|
||||
nsString *** aResult,
|
||||
PRInt32 * aCount)
|
||||
{
|
||||
nsresult res;
|
||||
if (!mMappingDone) {
|
||||
res = CreateMapping();
|
||||
if NS_FAILED(res) return res;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
*aCount = 0;
|
||||
if (mDecSize != 0) {
|
||||
*aResult = new nsString * [mDecSize];
|
||||
*aCount = mDecSize;
|
||||
for (PRInt32 i=0;i<mDecSize;i++) (*aResult)[i]=mDecArray[i].mCharset;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetName(
|
||||
const nsString * aCharset,
|
||||
nsString ** aResult)
|
||||
{
|
||||
// XXX add aliases capability here
|
||||
|
||||
*aResult = new nsString(*aCharset);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetNames(
|
||||
const nsString * aCharset,
|
||||
nsString *** aResult,
|
||||
PRInt32 * aCount)
|
||||
{
|
||||
// XXX write me
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsManagerFactory [implementation]
|
||||
|
||||
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS(nsManagerFactory, kIFactoryIID);
|
||||
|
||||
nsManagerFactory::nsManagerFactory()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
nsManagerFactory::~nsManagerFactory()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Interface nsIFactory [implementation]
|
||||
|
||||
NS_IMETHODIMP nsManagerFactory::CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||
if (aDelegate != NULL) return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsICharsetConverterManager * t = nsCharsetConverterManager::GetInstance();
|
||||
if (t == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = t->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res)) delete t;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsManagerFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock) PR_AtomicIncrement(&g_LockCount);
|
||||
else PR_AtomicDecrement(&g_LockCount);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
61
mozilla/intl/uconv/src/nsCharsetConverterManager.h
Normal file
61
mozilla/intl/uconv/src/nsCharsetConverterManager.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsCharsetConverterManager_h___
|
||||
#define nsCharsetConverterManager_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Class nsManagerFactory [declaration]
|
||||
|
||||
/**
|
||||
* Factory class for the nsICharsetConverterManager objects.
|
||||
*
|
||||
* @created 18/Nov/1998
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
class nsManagerFactory : public nsIFactory
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
nsManagerFactory();
|
||||
|
||||
/**
|
||||
* Class destructor.
|
||||
*/
|
||||
~nsManagerFactory();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Interface nsIFactory [declaration]
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate, const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* nsCharsetConverterManager_h___ */
|
||||
101
mozilla/intl/uconv/src/nsUConvDll.cpp
Normal file
101
mozilla/intl/uconv/src/nsUConvDll.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsCharsetConverterManager.h"
|
||||
#include "nsAscii2Unicode.h"
|
||||
#include "nsConverterCID.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [declaration]
|
||||
|
||||
extern "C" PRInt32 g_InstanceCount = 0;
|
||||
extern "C" PRInt32 g_LockCount = 0;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Global functions and data [implementation]
|
||||
|
||||
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
extern "C" NS_EXPORT PRBool NSCanUnload()
|
||||
{
|
||||
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
if (aFactory == NULL) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// the converter manager
|
||||
if (aCID.Equals(kCharsetConverterManagerCID)) {
|
||||
nsManagerFactory *factory = new nsManagerFactory();
|
||||
nsresult res = factory->QueryInterface(kIFactoryIID, (void **) aFactory);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete factory;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// the Ascii2Unicode converter
|
||||
if (aCID.Equals(kAscii2UnicodeCID)) {
|
||||
nsAscii2UnicodeFactory *factory = new nsAscii2UnicodeFactory();
|
||||
nsresult res = factory->QueryInterface(kIFactoryIID, (void **) aFactory);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
*aFactory = NULL;
|
||||
delete factory;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSRegisterSelf(const char * path)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kAscii2UnicodeCID, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kCharsetConverterManagerCID, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
return res;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSUnregisterSelf(const char * path)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
res = nsRepository::UnregisterFactory(kAscii2UnicodeCID, path);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = nsRepository::UnregisterFactory(kCharsetConverterManagerCID, path);
|
||||
return res;
|
||||
}
|
||||
28
mozilla/intl/uconv/src/nsUConvDll.h
Normal file
28
mozilla/intl/uconv/src/nsUConvDll.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsUConvDll_h___
|
||||
#define nsUConvDll_h___
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
extern "C" PRInt32 g_InstanceCount;
|
||||
extern "C" PRInt32 g_LockCount;
|
||||
|
||||
#endif /* nsUConvDll_h___ */
|
||||
61
mozilla/intl/uconv/tests/makefile.win
Normal file
61
mozilla/intl/uconv/tests/makefile.win
Normal file
@ -0,0 +1,61 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
MAKE_OBJ_TYPE = EXE
|
||||
PROGRAM = .\$(OBJDIR)\TestUConv.exe
|
||||
|
||||
!ifdef MOZ_DEBUG
|
||||
RCFLAGS=/d_DEBUG
|
||||
!endif
|
||||
|
||||
MISCDEP= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\uconv.lib \
|
||||
$(LIBNSPR) \
|
||||
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsTestUConv.obj \
|
||||
$(NULL)
|
||||
|
||||
LINCS= \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\intl \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\uconv.lib \
|
||||
-SUBSYSTEM:CONSOLE
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
!ifdef MOZ_NO_DEBUG_RTL
|
||||
OS_CFLAGS = $(OS_CFLAGS) -DMOZ_NO_DEBUG_RTL
|
||||
!endif
|
||||
|
||||
install:: $(PROGRAM)
|
||||
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\TestUConv.exe
|
||||
182
mozilla/intl/uconv/tests/nsTestUConv.cpp
Normal file
182
mozilla/intl/uconv/tests/nsTestUConv.cpp
Normal file
@ -0,0 +1,182 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nsRepository.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsConverterCID.h"
|
||||
|
||||
#define UCONV_DLL "uconv.dll"
|
||||
#define TABLE_SIZE1 5
|
||||
|
||||
nsICharsetConverterManager * ccMan = NULL;
|
||||
|
||||
nsresult setupRegistry()
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kCharsetConverterManagerCID, UCONV_DLL, PR_FALSE, PR_FALSE);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = nsRepository::RegisterFactory(kAscii2UnicodeCID, UCONV_DLL, PR_FALSE, PR_FALSE);
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult init()
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
res = setupRegistry();
|
||||
if (NS_FAILED(res)) {
|
||||
printf("Error setting up registry: 0x%x",res);
|
||||
return res;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult done()
|
||||
{
|
||||
if (ccMan != NULL) NS_RELEASE(ccMan);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult testCharsetConverterManager()
|
||||
{
|
||||
printf("\n[T1] CharsetConverterManager\n");
|
||||
|
||||
nsresult res = nsRepository::CreateInstance(kCharsetConverterManagerCID,
|
||||
NULL, kICharsetConverterManagerIID, (void **)&ccMan);
|
||||
if (NS_FAILED(res)) {
|
||||
printf("ERROR 0x%x: Cannot instantiate.\n",res);
|
||||
return res;
|
||||
} else {
|
||||
printf("Instantiated.\n");
|
||||
}
|
||||
|
||||
nsString ** cs;
|
||||
PRInt32 ct;
|
||||
|
||||
res = ccMan->GetEncodableCharsets(&cs, &ct);
|
||||
if (NS_FAILED(res)) {
|
||||
printf("ERROR 0x%x: GetEncodableCharsets()\n",res);
|
||||
} else {
|
||||
printf("Unicode encoders (%d): ", ct);
|
||||
for (int i=0;i<ct;i++) {
|
||||
char * cstr = cs[i]->ToNewCString();
|
||||
printf("%s ",cstr);
|
||||
delete [] cstr;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
delete [] cs;
|
||||
|
||||
res = ccMan->GetDecodableCharsets(&cs, &ct);
|
||||
if (NS_FAILED(res)) {
|
||||
printf("ERROR 0x%x: GetDecodableCharsets()\n",res);
|
||||
} else {
|
||||
printf("Unicode decoders (%d): ", ct);
|
||||
for (int i=0;i<ct;i++) {
|
||||
char * cstr = cs[i]->ToNewCString();
|
||||
printf("%s ",cstr);
|
||||
delete [] cstr;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
delete [] cs;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult testAsciiDecoder()
|
||||
{
|
||||
printf("\n[T2] Ascii2Unicode\n");
|
||||
|
||||
// create converter
|
||||
nsIUnicodeDecoder * dec;
|
||||
nsAutoString str("Ascii");
|
||||
nsresult res = ccMan->GetUnicodeDecoder(&str,&dec);
|
||||
if (NS_FAILED(res)) {
|
||||
printf("ERROR 0x%x: Cannot instantiate.\n",res);
|
||||
return res;
|
||||
} else {
|
||||
printf("Instantiated.\n");
|
||||
}
|
||||
|
||||
//test converter
|
||||
|
||||
PRInt32 srcL = TABLE_SIZE1;
|
||||
PRInt32 destL = TABLE_SIZE1;
|
||||
char src [TABLE_SIZE1] = {(char)0,(char)255,(char)13,(char)127,(char)128,};
|
||||
PRUnichar dest [TABLE_SIZE1];
|
||||
|
||||
res=dec->Convert(dest, 0, &destL, src, 0, &srcL);
|
||||
if (NS_FAILED(res)) {
|
||||
printf("ERROR 0x%x: Convert().\n",res);
|
||||
} else {
|
||||
printf("Read %d, write %d.\n",srcL,destL);
|
||||
printf("Converted:");
|
||||
|
||||
PRBool failed = PR_FALSE;
|
||||
for (int i=0;i<TABLE_SIZE1;i++) {
|
||||
printf(" %d->%x", src[i], dest[i]);
|
||||
if (dest[i] != ((PRUint8)src[i])) failed = PR_TRUE;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (failed) {
|
||||
printf("Test FAILED!!!\n");
|
||||
} else {
|
||||
printf("Test Passed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
NS_RELEASE(dec);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult run()
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
res = testCharsetConverterManager();
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = testAsciiDecoder();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
printf("*** Unicode Converters Test ***\n");
|
||||
|
||||
res = init();
|
||||
if (NS_FAILED(res)) return -1;
|
||||
run();
|
||||
done();
|
||||
|
||||
printf("\n***--------- Done --------***\n");
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user