Landing optional and experimental native uconv support. r=darin, sr=alecf, b=20049.

This commit is contained in:
dougt%netscape.com 2003-04-02 04:39:23 +00:00
Родитель 3eda9ed635
Коммит 538ab3ed7e
6 изменённых файлов: 134 добавлений и 53 удалений

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

@ -38,7 +38,7 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = idl public util ucvja ucvcn ucvlatin ucvtw ucvtw2 ucvko ucvibm src
DIRS = idl public util ucvja ucvcn ucvlatin ucvtw ucvtw2 ucvko ucvibm native src
ifdef MOZ_MATHML
DIRS += ucvmath

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

@ -26,7 +26,8 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = uconv
MODULE = ucnative
LIBRARY_NAME = ucnative_s
FORCE_STATIC_LIB=1

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

@ -38,12 +38,14 @@ ifneq ($(OS_ARCH),WINNT)
SHORT_LIBNAME = mozuconv
endif
REQUIRES = xpcom \
xpcom_obsolete \
mozreg \
xpcom_obsolete \
string \
intl \
locale \
unicharutil \
chardet \
ucnative \
$(NULL)
CSRCS = \
@ -54,12 +56,18 @@ CSRCS = \
CPPSRCS = \
nsUConvModule.cpp \
nsCharsetConverterManager.cpp \
nsCharsetAliasImp.cpp \
nsConverterInputStream.cpp \
nsTextToSubURI.cpp \
nsURLProperties.cpp \
$(NULL)
ifndef MOZ_USE_NATIVE_UCONV
CPPSRCS += \
nsCharsetConverterManager.cpp \
nsScriptableUConv.cpp \
nsUnicodeDecodeHelper.cpp \
nsUnicodeEncodeHelper.cpp \
nsCharsetAliasImp.cpp \
nsURLProperties.cpp \
nsMappingCache.cpp \
nsISO88591ToUnicode.cpp \
nsCP1252ToUnicode.cpp \
@ -69,9 +77,8 @@ CPPSRCS = \
nsUnicodeToCP1252.cpp \
nsUnicodeToMacRoman.cpp \
nsUnicodeToUTF8.cpp \
nsScriptableUConv.cpp \
nsConverterInputStream.cpp \
$(NULL)
endif
EXPORT_RESOURCE = \
charsetalias.properties \
@ -125,17 +132,22 @@ 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)
-I$(srcdir)/../ucvlatin \
-I$(srcdir)/../ucvibm \
-I$(srcdir)/../ucvja \
-I$(srcdir)/../ucvtw2 \
-I$(srcdir)/../ucvtw \
-I$(srcdir)/../ucvko \
-I$(srcdir)/../ucvcn \
-I$(srcdir)/../native \
$(NULL)
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/$(LIB_PREFIX)ucvutil_s.$(LIB_SUFFIX) \
$(NULL)
ifndef MOZ_USE_NATIVE_UCONV
SHARED_LIBRARY_LIBS += \
$(DIST)/lib/$(LIB_PREFIX)ucvlatin_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)ucvibm_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)ucvja_s.$(LIB_SUFFIX) \
@ -144,6 +156,11 @@ SHARED_LIBRARY_LIBS = \
$(DIST)/lib/$(LIB_PREFIX)ucvko_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)ucvcn_s.$(LIB_SUFFIX) \
$(NULL)
else
SHARED_LIBRARY_LIBS += \
$(DIST)/lib/$(LIB_PREFIX)ucnative_s.$(LIB_SUFFIX) \
$(NULL)
endif
include $(topsrcdir)/config/rules.mk

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

@ -60,6 +60,7 @@
#include "nsIUnicodeDecodeHelper.h"
#include "nsIUnicodeEncodeHelper.h"
#include "nsCharsetConverterManager.h"
#include "nsNativeUConvService.h"
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
@ -77,8 +78,11 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsCharsetConverterManager,
nsICharsetConverterManager2);
nsCharsetConverterManager::nsCharsetConverterManager()
:mDataBundle(NULL), mTitleBundle(NULL)
:mDataBundle(NULL), mTitleBundle(NULL)
{
#ifdef MOZ_USE_NATIVE_UCONV
mNativeUC = do_GetService(NS_NATIVE_UCONV_SERVICE_CONTRACT_ID);
#endif
}
nsCharsetConverterManager::~nsCharsetConverterManager()
@ -170,14 +174,28 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder(
const nsString * aDest,
nsIUnicodeEncoder ** aResult)
{
*aResult= nsnull;
nsCOMPtr<nsIUnicodeEncoder> encoder;
#ifdef MOZ_USE_NATIVE_UCONV
if (mNativeUC) {
mNativeUC->GetNativeConverter("UCS-2",
NS_LossyConvertUCS2toASCII(*aDest).get(),
getter_AddRefs(encoder));
if (encoder) {
NS_ADDREF(*aResult = encoder);
return NS_OK;
}
}
#endif
nsresult res = NS_OK;
nsCAutoString contractid(
NS_LITERAL_CSTRING(NS_UNICODEENCODER_CONTRACTID_BASE) +
NS_LossyConvertUCS2toASCII(*aDest));
nsCOMPtr<nsIUnicodeEncoder> encoder;
// Always create an instance since encoders hold state.
encoder = do_CreateInstance(contractid.get(), &res);
@ -196,6 +214,20 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
nsIUnicodeDecoder ** aResult)
{
*aResult= nsnull;
nsCOMPtr<nsIUnicodeDecoder> decoder;
#ifdef MOZ_USE_NATIVE_UCONV
if (mNativeUC) {
mNativeUC->GetNativeConverter(NS_LossyConvertUCS2toASCII(*aSrc).get(),
"UCS-2",
getter_AddRefs(decoder));
if (decoder) {
NS_ADDREF(*aResult = decoder);
return NS_OK;
}
}
#endif
nsresult res = NS_OK;;
NS_NAMED_LITERAL_CSTRING(kUnicodeDecoderContractIDBase,
@ -204,7 +236,6 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
nsCAutoString contractid(kUnicodeDecoderContractIDBase +
NS_LossyConvertUCS2toASCII(*aSrc));
nsCOMPtr<nsIUnicodeDecoder> decoder;
if (!strncmp(contractid.get()+kUnicodeDecoderContractIDBase.Length(),
NS_1BYTE_CODER_PATTERN,
NS_1BYTE_CODER_PATTERN_LEN))

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

@ -43,6 +43,8 @@
#include "nsIStringBundle.h"
#include "nsISupportsArray.h"
#include "nsINativeUConvService.h"
class nsCharsetConverterManager : public nsICharsetConverterManager,
public nsICharsetConverterManager2
{
@ -65,6 +67,10 @@ private:
nsIStringBundle * mDataBundle;
nsIStringBundle * mTitleBundle;
#ifdef MOZ_USE_NATIVE_UCONV
nsCOMPtr<nsINativeUConvService> mNativeUC;
#endif
nsresult LoadExtensibleBundle(const char * aRegistryKey,
nsIStringBundle ** aResult);

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

@ -44,27 +44,33 @@
#include "nsICategoryManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsIUnicodeDecodeHelper.h"
#include "nsIUnicodeEncodeHelper.h"
#include "nsIUnicodeDecoder.h"
#include "nsIUnicodeEncoder.h"
#include "nsICharsetConverterManager.h"
#include "nsIPlatformCharset.h"
#include "nsICharsetAlias.h"
#include "nsITextToSubURI.h"
#include "nsIServiceManager.h"
#include "nsCharsetConverterManager.h"
#include "nsCharsetAlias.h"
#include "nsTextToSubURI.h"
#include "nsConverterInputStream.h"
#include "nsPlatformCharset.h"
#ifndef MOZ_USE_NATIVE_UCONV
#include "nsIUnicodeDecodeHelper.h"
#include "nsIUnicodeEncodeHelper.h"
#include "nsIPlatformCharset.h"
#include "nsITextToSubURI.h"
#include "nsUConvDll.h"
#include "nsIFile.h"
#include "nsIScriptableUConv.h"
#include "nsConverterInputStream.h"
#include "nsCRT.h"
#include "nsUCSupport.h"
#include "nsCharsetConverterManager.h"
#include "nsUnicodeDecodeHelper.h"
#include "nsUnicodeEncodeHelper.h"
#include "nsPlatformCharset.h"
#include "nsCharsetAlias.h"
#include "nsTextToSubURI.h"
#include "nsISO88591ToUnicode.h"
#include "nsCP1252ToUnicode.h"
#include "nsMacRomanToUnicode.h"
@ -441,14 +447,9 @@ NS_CONVERTER_REGISTRY_END
NS_IMPL_NSUCONVERTERREGSELF
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCharsetConverterManager)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeDecodeHelper)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeEncodeHelper)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPlatformCharset, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCharsetAlias2)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextToSubURI)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableUnicodeConverter)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsConverterInputStream)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToUTF8)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUTF8ToUnicode)
@ -646,6 +647,16 @@ const PRUint16 g_ufJohabJamoMapping[] ={
#include "johabjamo.uf"
};
#else // MOZ_USE_NATIVE_UCONV
#include "nsINativeUConvService.h"
#include "nsNativeUConvService.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(NativeUConvService)
#endif // #ifndef MOZ_USE_NATIVE_UCONV
NS_IMETHODIMP
nsConverterManagerDataRegister(nsIComponentManager* aCompMgr,
nsIFile* aPath,
@ -656,6 +667,12 @@ nsConverterManagerDataRegister(nsIComponentManager* aCompMgr,
return nsCharsetConverterManager::RegisterConverterManagerData();
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCharsetConverterManager)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextToSubURI)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCharsetAlias2)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsConverterInputStream)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPlatformCharset, Init)
static const nsModuleComponentInfo components[] =
{
{
@ -664,21 +681,6 @@ static const nsModuleComponentInfo components[] =
nsCharsetConverterManagerConstructor,
nsConverterManagerDataRegister,
},
{
"Unicode Decode Helper", NS_UNICODEDECODEHELPER_CID,
NS_UNICODEDECODEHELPER_CONTRACTID,
nsUnicodeDecodeHelperConstructor
},
{
"Unicode Encode Helper", NS_UNICODEENCODEHELPER_CID,
NS_UNICODEENCODEHELPER_CONTRACTID,
nsUnicodeEncodeHelperConstructor
},
{
"Platform Charset Information", NS_PLATFORMCHARSET_CID,
NS_PLATFORMCHARSET_CONTRACTID,
nsPlatformCharsetConstructor
},
{
"Charset Alias Information", NS_CHARSETALIAS_CID,
NS_CHARSETALIAS_CONTRACTID,
@ -690,14 +692,37 @@ static const nsModuleComponentInfo components[] =
nsTextToSubURIConstructor
},
{
"Unicode Encoder / Decoder for Script", NS_ISCRIPTABLEUNICODECONVERTER_CID,
NS_ISCRIPTABLEUNICODECONVERTER_CONTRACTID,
nsScriptableUnicodeConverterConstructor
"Platform Charset Information", NS_PLATFORMCHARSET_CID,
NS_PLATFORMCHARSET_CONTRACTID,
nsPlatformCharsetConstructor
},
{ "Unicode converter input stream", NS_CONVERTERINPUTSTREAM_CID,
NS_CONVERTERINPUTSTREAM_CONTRACTID,
nsConverterInputStreamConstructor
},
},
#ifdef MOZ_USE_NATIVE_UCONV
{
"Native UConv Service",
NS_NATIVE_UCONV_SERVICE_CID,
NS_NATIVE_UCONV_SERVICE_CONTRACT_ID,
NativeUConvServiceConstructor,
},
#else
{
"Unicode Decode Helper", NS_UNICODEDECODEHELPER_CID,
NS_UNICODEDECODEHELPER_CONTRACTID,
nsUnicodeDecodeHelperConstructor
},
{
"Unicode Encode Helper", NS_UNICODEENCODEHELPER_CID,
NS_UNICODEENCODEHELPER_CONTRACTID,
nsUnicodeEncodeHelperConstructor
},
{
"Unicode Encoder / Decoder for Script", NS_ISCRIPTABLEUNICODECONVERTER_CID,
NS_ISCRIPTABLEUNICODECONVERTER_CONTRACTID,
nsScriptableUnicodeConverterConstructor
},
{
"ISO-8859-1 To Unicode Converter", NS_ISO88591TOUNICODE_CID,
NS_ISO88591TOUNICODE_CONTRACTID,
@ -1696,6 +1721,7 @@ static const nsModuleComponentInfo components[] =
NS_UNICODEDECODER_CONTRACTID_BASE "ISO-2022-CN",
nsISO2022CNToUnicodeConstructor,
},
#endif // MOZ_USE_NATIVE_UCONV
};
NS_IMPL_NSGETMODULE(nsUConvModule, components);