зеркало из https://github.com/mozilla/gecko-dev.git
Bug 943287 - Part 2. Use ICU version of nsICollation on all platform. r=hsivonen
nsICollation for macOS version uses ICU, so we should use it on all platform since nightly and aurora can use ICU on all platform. MozReview-Commit-ID: 4nTzDCjOQXJ --HG-- rename : intl/locale/tests/unit/test_collation_mac_icu.js => intl/locale/tests/unit/test_collation.js extra : rebase_source : 3b47f9a521e79be929bb4c39d0c68b9438075e4c
This commit is contained in:
Родитель
aa97ad5859
Коммит
80c217bbec
|
@ -61,15 +61,7 @@ NS_DEFINE_NAMED_CID(NS_COLLATIONFACTORY_CID);
|
|||
NS_DEFINE_NAMED_CID(NS_SCRIPTABLEDATEFORMAT_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_LANGUAGEATOMSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_PLATFORMCHARSET_CID);
|
||||
#ifdef XP_WIN
|
||||
NS_DEFINE_NAMED_CID(NS_COLLATION_CID);
|
||||
#endif
|
||||
#ifdef USE_UNIX_LOCALE
|
||||
NS_DEFINE_NAMED_CID(NS_COLLATION_CID);
|
||||
#endif
|
||||
#ifdef USE_MAC_LOCALE
|
||||
NS_DEFINE_NAMED_CID(NS_COLLATION_CID);
|
||||
#endif
|
||||
|
||||
static const mozilla::Module::CIDEntry kIntlCIDs[] = {
|
||||
{ &kMOZ_LOCALESERVICE_CID, false, nullptr, mozilla::intl::LocaleServiceConstructor },
|
||||
|
@ -89,15 +81,7 @@ static const mozilla::Module::CIDEntry kIntlCIDs[] = {
|
|||
{ &kNS_SCRIPTABLEDATEFORMAT_CID, false, nullptr, NS_NewScriptableDateFormat },
|
||||
{ &kNS_LANGUAGEATOMSERVICE_CID, false, nullptr, nsLanguageAtomServiceConstructor },
|
||||
{ &kNS_PLATFORMCHARSET_CID, false, nullptr, nsPlatformCharsetConstructor },
|
||||
#ifdef XP_WIN
|
||||
{ &kNS_COLLATION_CID, false, nullptr, nsCollationWinConstructor },
|
||||
#endif
|
||||
#ifdef USE_UNIX_LOCALE
|
||||
{ &kNS_COLLATION_CID, false, nullptr, nsCollationUnixConstructor },
|
||||
#endif
|
||||
#ifdef USE_MAC_LOCALE
|
||||
{ &kNS_COLLATION_CID, false, nullptr, nsCollationMacUCConstructor },
|
||||
#endif
|
||||
{ &kNS_COLLATION_CID, false, nullptr, nsCollationConstructor },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
|
@ -119,15 +103,7 @@ static const mozilla::Module::ContractIDEntry kIntlContracts[] = {
|
|||
{ NS_SCRIPTABLEDATEFORMAT_CONTRACTID, &kNS_SCRIPTABLEDATEFORMAT_CID },
|
||||
{ NS_LANGUAGEATOMSERVICE_CONTRACTID, &kNS_LANGUAGEATOMSERVICE_CID },
|
||||
{ NS_PLATFORMCHARSET_CONTRACTID, &kNS_PLATFORMCHARSET_CID },
|
||||
#ifdef XP_WIN
|
||||
{ NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID },
|
||||
#endif
|
||||
#ifdef USE_UNIX_LOCALE
|
||||
{ NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID },
|
||||
#endif
|
||||
#ifdef USE_MAC_LOCALE
|
||||
{ NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID },
|
||||
#endif
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'nsCollationMacUC.cpp',
|
||||
'nsMacCharset.cpp',
|
||||
]
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ XPIDL_MODULE = 'locale'
|
|||
EXPORTS += [
|
||||
'DateTimeFormat.h',
|
||||
'nsCollationCID.h',
|
||||
'nsCollationFactory.h',
|
||||
'nsILanguageAtomService.h',
|
||||
'nsIPlatformCharset.h',
|
||||
'nsPosixLocale.h',
|
||||
|
@ -48,6 +47,7 @@ EXPORTS.mozilla.intl += [
|
|||
|
||||
UNIFIED_SOURCES += [
|
||||
'LocaleService.cpp',
|
||||
'nsCollation.cpp',
|
||||
'nsCollationFactory.cpp',
|
||||
'nsLanguageAtomService.cpp',
|
||||
'nsLocale.cpp',
|
||||
|
|
|
@ -3,23 +3,21 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsCollationMacUC.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsCollation.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "prmem.h"
|
||||
#include "nsString.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCollationMacUC, nsICollation)
|
||||
NS_IMPL_ISUPPORTS(nsCollation, nsICollation)
|
||||
|
||||
nsCollationMacUC::nsCollationMacUC()
|
||||
nsCollation::nsCollation()
|
||||
: mInit(false)
|
||||
, mHasCollator(false)
|
||||
, mLastStrength(-1)
|
||||
, mCollatorICU(nullptr)
|
||||
{ }
|
||||
|
||||
nsCollationMacUC::~nsCollationMacUC()
|
||||
nsCollation::~nsCollation()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
nsresult res =
|
||||
|
@ -28,9 +26,10 @@ nsCollationMacUC::~nsCollationMacUC()
|
|||
NS_ASSERTION(NS_SUCCEEDED(res), "CleanUpCollator failed");
|
||||
}
|
||||
|
||||
nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength,
|
||||
UCollationStrength* aICUStrength,
|
||||
UColAttributeValue* aCaseLevelOut)
|
||||
nsresult
|
||||
nsCollation::ConvertStrength(const int32_t aNSStrength,
|
||||
UCollationStrength* aICUStrength,
|
||||
UColAttributeValue* aCaseLevelOut)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aICUStrength);
|
||||
NS_ENSURE_TRUE((aNSStrength < 4), NS_ERROR_FAILURE);
|
||||
|
@ -62,7 +61,8 @@ nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCollationMacUC::EnsureCollator(const int32_t newStrength)
|
||||
nsresult
|
||||
nsCollation::EnsureCollator(const int32_t newStrength)
|
||||
{
|
||||
NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED);
|
||||
if (mHasCollator && (mLastStrength == newStrength))
|
||||
|
@ -102,7 +102,8 @@ nsresult nsCollationMacUC::EnsureCollator(const int32_t newStrength)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCollationMacUC::CleanUpCollator(void)
|
||||
nsresult
|
||||
nsCollation::CleanUpCollator(void)
|
||||
{
|
||||
if (mHasCollator) {
|
||||
ucol_close(mCollatorICU);
|
||||
|
@ -112,10 +113,10 @@ nsresult nsCollationMacUC::CleanUpCollator(void)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCollationMacUC::Initialize(const nsACString& locale)
|
||||
NS_IMETHODIMP
|
||||
nsCollation::Initialize(const nsACString& locale)
|
||||
{
|
||||
NS_ENSURE_TRUE((!mInit), NS_ERROR_ALREADY_INITIALIZED);
|
||||
nsCOMPtr<nsILocale> appLocale;
|
||||
|
||||
mLocale = locale;
|
||||
|
||||
|
@ -123,8 +124,9 @@ NS_IMETHODIMP nsCollationMacUC::Initialize(const nsACString& locale)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCollationMacUC::AllocateRawSortKey(int32_t strength, const nsAString& stringIn,
|
||||
uint8_t** key, uint32_t* outLen)
|
||||
NS_IMETHODIMP
|
||||
nsCollation::AllocateRawSortKey(int32_t strength, const nsAString& stringIn,
|
||||
uint8_t** key, uint32_t* outLen)
|
||||
{
|
||||
NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED);
|
||||
NS_ENSURE_ARG_POINTER(key);
|
||||
|
@ -155,8 +157,9 @@ NS_IMETHODIMP nsCollationMacUC::AllocateRawSortKey(int32_t strength, const nsASt
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCollationMacUC::CompareString(int32_t strength, const nsAString& string1,
|
||||
const nsAString& string2, int32_t* result)
|
||||
NS_IMETHODIMP
|
||||
nsCollation::CompareString(int32_t strength, const nsAString& string1,
|
||||
const nsAString& string2, int32_t* result)
|
||||
{
|
||||
NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED);
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
@ -189,9 +192,10 @@ NS_IMETHODIMP nsCollationMacUC::CompareString(int32_t strength, const nsAString&
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCollationMacUC::CompareRawSortKey(const uint8_t* key1, uint32_t len1,
|
||||
const uint8_t* key2, uint32_t len2,
|
||||
int32_t* result)
|
||||
NS_IMETHODIMP
|
||||
nsCollation::CompareRawSortKey(const uint8_t* key1, uint32_t len1,
|
||||
const uint8_t* key2, uint32_t len2,
|
||||
int32_t* result)
|
||||
{
|
||||
NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED);
|
||||
NS_ENSURE_ARG_POINTER(key1);
|
|
@ -3,8 +3,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsCollationMacUC_h_
|
||||
#define nsCollationMacUC_h_
|
||||
#ifndef nsCollation_h_
|
||||
#define nsCollation_h_
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsICollation.h"
|
||||
|
@ -13,10 +13,10 @@
|
|||
|
||||
#include "unicode/ucol.h"
|
||||
|
||||
class nsCollationMacUC final : public nsICollation {
|
||||
class nsCollation final : public nsICollation {
|
||||
|
||||
public:
|
||||
nsCollationMacUC();
|
||||
nsCollation();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -25,7 +25,7 @@ public:
|
|||
NS_DECL_NSICOLLATION
|
||||
|
||||
protected:
|
||||
~nsCollationMacUC();
|
||||
~nsCollation();
|
||||
|
||||
nsresult ConvertStrength(const int32_t aStrength,
|
||||
UCollationStrength* aStrengthOut,
|
||||
|
@ -41,4 +41,4 @@ private:
|
|||
UCollator* mCollatorICU;
|
||||
};
|
||||
|
||||
#endif /* nsCollationMacUC_h_ */
|
||||
#endif /* nsCollation_h_ */
|
|
@ -5,15 +5,9 @@
|
|||
|
||||
#include "nsCollationFactory.h"
|
||||
#include "nsCollationCID.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "prmem.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "mozilla/intl/LocaleService.h"
|
||||
|
||||
using mozilla::dom::EncodingUtils;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID);
|
||||
|
@ -47,99 +41,3 @@ nsCollationFactory::CreateCollationForLocale(const nsACString& locale, nsICollat
|
|||
|
||||
return res;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsCollation::nsCollation()
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsCollation);
|
||||
}
|
||||
|
||||
nsCollation::~nsCollation()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsCollation);
|
||||
}
|
||||
|
||||
nsresult nsCollation::NormalizeString(const nsAString& stringIn, nsAString& stringOut)
|
||||
{
|
||||
int32_t aLength = stringIn.Length();
|
||||
|
||||
if (aLength <= 64) {
|
||||
char16_t conversionBuffer[64];
|
||||
ToLowerCase(PromiseFlatString(stringIn).get(), conversionBuffer, aLength);
|
||||
stringOut.Assign(conversionBuffer, aLength);
|
||||
}
|
||||
else {
|
||||
char16_t* conversionBuffer;
|
||||
conversionBuffer = new char16_t[aLength];
|
||||
if (!conversionBuffer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
ToLowerCase(PromiseFlatString(stringIn).get(), conversionBuffer, aLength);
|
||||
stringOut.Assign(conversionBuffer, aLength);
|
||||
delete [] conversionBuffer;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCollation::SetCharset(const char* aCharset)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCharset);
|
||||
|
||||
nsDependentCString label(aCharset);
|
||||
nsAutoCString encoding;
|
||||
if (!EncodingUtils::FindEncodingForLabelNoReplacement(label, encoding)) {
|
||||
return NS_ERROR_UCONV_NOCONV;
|
||||
}
|
||||
mEncoder = EncodingUtils::EncoderForEncoding(encoding);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCollation::UnicodeToChar(const nsAString& aSrc, char** dst)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(dst);
|
||||
|
||||
nsresult res = NS_OK;
|
||||
if (!mEncoder)
|
||||
res = SetCharset("ISO-8859-1");
|
||||
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
const nsPromiseFlatString& src = PromiseFlatString(aSrc);
|
||||
const char16_t *unichars = src.get();
|
||||
int32_t unicharLength = src.Length();
|
||||
int32_t dstLength;
|
||||
res = mEncoder->GetMaxLength(unichars, unicharLength, &dstLength);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
int32_t bufLength = dstLength + 1 + 32; // extra 32 bytes for Finish() call
|
||||
*dst = (char *) PR_Malloc(bufLength);
|
||||
if (*dst) {
|
||||
**dst = '\0';
|
||||
res = mEncoder->Convert(unichars, &unicharLength, *dst, &dstLength);
|
||||
|
||||
if (NS_SUCCEEDED(res) || (NS_ERROR_UENC_NOMAPPING == res)) {
|
||||
// Finishes the conversion. The converter has the possibility to write some
|
||||
// extra data and flush its final state.
|
||||
int32_t finishLength = bufLength - dstLength; // remaining unused buffer length
|
||||
if (finishLength > 0) {
|
||||
res = mEncoder->Finish((*dst + dstLength), &finishLength);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
(*dst)[dstLength + finishLength] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(res)) {
|
||||
PR_Free(*dst);
|
||||
*dst = nullptr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
class nsIUnicodeEncoder;
|
||||
|
||||
// Create a collation interface for the current app's locale.
|
||||
//
|
||||
class nsCollationFactory final : public nsICollationFactory {
|
||||
|
@ -27,24 +25,4 @@ public:
|
|||
nsCollationFactory() {}
|
||||
};
|
||||
|
||||
|
||||
struct nsCollation {
|
||||
|
||||
public:
|
||||
|
||||
nsCollation();
|
||||
|
||||
~nsCollation();
|
||||
|
||||
// normalize string before collation key generation
|
||||
nsresult NormalizeString(const nsAString& stringIn, nsAString& stringOut);
|
||||
|
||||
// charset conversion util, C string buffer is allocate by PR_Malloc, caller should call PR_Free
|
||||
nsresult SetCharset(const char* aCharset);
|
||||
nsresult UnicodeToChar(const nsAString& aSrc, char** dst);
|
||||
|
||||
protected:
|
||||
nsCOMPtr <nsIUnicodeEncoder> mEncoder;
|
||||
};
|
||||
|
||||
#endif /* nsCollationFactory_h__ */
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#ifndef nsLocaleConstructors_h__
|
||||
#define nsLocaleConstructors_h__
|
||||
|
||||
#include "nsCollation.h"
|
||||
#include "nsCollationCID.h"
|
||||
#include "mozilla/ModuleUtils.h"
|
||||
#include "nsILocaleService.h"
|
||||
|
@ -16,26 +17,6 @@
|
|||
#include "LocaleService.h"
|
||||
#include "OSPreferences.h"
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
#define USE_MAC_LOCALE
|
||||
#endif
|
||||
|
||||
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
||||
#define USE_UNIX_LOCALE
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "windows/nsCollationWin.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_MAC_LOCALE
|
||||
#include "mac/nsCollationMacUC.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNIX_LOCALE
|
||||
#include "unix/nsCollationUnix.h"
|
||||
#endif
|
||||
|
||||
#define NSLOCALE_MAKE_CTOR(ctor_, iface_, func_) \
|
||||
static nsresult \
|
||||
ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
|
||||
|
@ -54,6 +35,7 @@ ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
|
|||
|
||||
|
||||
NSLOCALE_MAKE_CTOR(CreateLocaleService, nsILocaleService, NS_NewLocaleService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollation)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationFactory)
|
||||
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableDateTimeFormat)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLanguageAtomService)
|
||||
|
@ -68,16 +50,4 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(OSPreferences,
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationWin)
|
||||
#endif
|
||||
|
||||
#ifdef USE_UNIX_LOCALE
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationUnix)
|
||||
#endif
|
||||
|
||||
#ifdef USE_MAC_LOCALE
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationMacUC)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,9 +11,7 @@ skip-if = toolkit != "windows" && toolkit != "cocoa"
|
|||
[test_bug374040.js]
|
||||
skip-if = toolkit == "windows" || toolkit == "cocoa"
|
||||
|
||||
[test_collation_mac_icu.js]
|
||||
skip-if = toolkit != "cocoa"
|
||||
|
||||
[test_collation.js]
|
||||
[test_bug1086527.js]
|
||||
[test_intl_on_workers.js]
|
||||
skip-if = toolkit == "android" # bug 1309447
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
SOURCES += [
|
||||
'nsCollationUnix.cpp',
|
||||
'nsPosixLocale.cpp',
|
||||
]
|
||||
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#ifndef nsCollationUnix_h__
|
||||
#define nsCollationUnix_h__
|
||||
|
||||
|
||||
#include "nsICollation.h"
|
||||
#include "nsCollationFactory.h" // static library
|
||||
#include "plstr.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
||||
|
||||
class nsCollationUnix final : public nsICollation {
|
||||
|
||||
protected:
|
||||
nsCollation *mCollation;
|
||||
nsCString mLocale;
|
||||
nsCString mSavedLocale;
|
||||
bool mUseCodePointOrder;
|
||||
|
||||
void DoSetLocale();
|
||||
void DoRestoreLocale();
|
||||
|
||||
~nsCollationUnix();
|
||||
|
||||
public:
|
||||
nsCollationUnix();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsICollation interface
|
||||
NS_DECL_NSICOLLATION
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsCollationUnix_h__ */
|
|
@ -5,7 +5,6 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
SOURCES += [
|
||||
'nsCollationWin.cpp',
|
||||
'nsWin32Locale.cpp',
|
||||
'nsWinCharset.cpp',
|
||||
]
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
#include "nsCollationWin.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsWin32Locale.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include <windows.h>
|
||||
|
||||
#undef CompareString
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCollationWin, nsICollation)
|
||||
|
||||
|
||||
nsCollationWin::nsCollationWin() : mCollation(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
nsCollationWin::~nsCollationWin()
|
||||
{
|
||||
if (mCollation)
|
||||
delete mCollation;
|
||||
}
|
||||
|
||||
nsresult nsCollationWin::Initialize(const nsACString& locale)
|
||||
{
|
||||
NS_ASSERTION(!mCollation, "Should only be initialized once.");
|
||||
|
||||
nsresult res;
|
||||
|
||||
mCollation = new nsCollation;
|
||||
|
||||
NS_ConvertASCIItoUTF16 wideLocale(locale);
|
||||
|
||||
// default LCID (en-US)
|
||||
mLCID = 1033;
|
||||
|
||||
// Get LCID and charset name from locale, if available
|
||||
LCID lcid;
|
||||
res = nsWin32Locale::GetPlatformLocale(wideLocale, &lcid);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
mLCID = lcid;
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset =
|
||||
do_GetService(NS_PLATFORMCHARSET_CONTRACTID);
|
||||
if (platformCharset) {
|
||||
nsAutoCString mappedCharset;
|
||||
res = platformCharset->GetDefaultCharsetForLocale(wideLocale, mappedCharset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
mCollation->SetCharset(mappedCharset.get());
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCollationWin::CompareString(int32_t strength,
|
||||
const nsAString & string1,
|
||||
const nsAString & string2,
|
||||
int32_t *result)
|
||||
{
|
||||
int retval;
|
||||
nsresult res;
|
||||
DWORD dwMapFlags = 0;
|
||||
|
||||
if (strength == kCollationCaseInSensitive)
|
||||
dwMapFlags |= NORM_IGNORECASE;
|
||||
|
||||
retval = ::CompareStringW(mLCID,
|
||||
dwMapFlags,
|
||||
(LPCWSTR) PromiseFlatString(string1).get(),
|
||||
-1,
|
||||
(LPCWSTR) PromiseFlatString(string2).get(),
|
||||
-1);
|
||||
if (retval) {
|
||||
res = NS_OK;
|
||||
*result = retval - 2;
|
||||
} else {
|
||||
res = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsCollationWin::AllocateRawSortKey(int32_t strength,
|
||||
const nsAString& stringIn, uint8_t** key, uint32_t* outLen)
|
||||
{
|
||||
int byteLen;
|
||||
void *buffer;
|
||||
nsresult res = NS_OK;
|
||||
DWORD dwMapFlags = LCMAP_SORTKEY;
|
||||
|
||||
if (strength == kCollationCaseInSensitive)
|
||||
dwMapFlags |= NORM_IGNORECASE;
|
||||
|
||||
byteLen = LCMapStringW(mLCID, dwMapFlags,
|
||||
(LPCWSTR) PromiseFlatString(stringIn).get(),
|
||||
-1, nullptr, 0);
|
||||
buffer = PR_Malloc(byteLen);
|
||||
if (!buffer) {
|
||||
res = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
*key = (uint8_t *)buffer;
|
||||
*outLen = LCMapStringW(mLCID, dwMapFlags,
|
||||
(LPCWSTR) PromiseFlatString(stringIn).get(),
|
||||
-1, (LPWSTR) buffer, byteLen);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsCollationWin::CompareRawSortKey(const uint8_t* key1, uint32_t len1,
|
||||
const uint8_t* key2, uint32_t len2,
|
||||
int32_t* result)
|
||||
{
|
||||
*result = PL_strcmp((const char *)key1, (const char *)key2);
|
||||
return NS_OK;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#ifndef nsCollationWin_h__
|
||||
#define nsCollationWin_h__
|
||||
|
||||
|
||||
#include "nsICollation.h"
|
||||
#include "nsCollationFactory.h" // static library
|
||||
#include "plstr.h"
|
||||
|
||||
|
||||
|
||||
class nsCollationWin final : public nsICollation {
|
||||
~nsCollationWin();
|
||||
|
||||
protected:
|
||||
nsCollation *mCollation; // XP collation class
|
||||
uint32_t mLCID; // Windows platform locale ID
|
||||
|
||||
public:
|
||||
nsCollationWin();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsICollation interface
|
||||
NS_DECL_NSICOLLATION
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsCollationWin_h__ */
|
Загрузка…
Ссылка в новой задаче