mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
aef3149a23
--HG-- rename : intl/locale/src/Makefile.in => intl/locale/Makefile.in rename : intl/locale/src/PluralForm.jsm => intl/locale/PluralForm.jsm rename : intl/locale/src/langGroups.properties => intl/locale/langGroups.properties rename : intl/locale/src/language.properties => intl/locale/language.properties rename : intl/locale/src/mac/moz.build => intl/locale/mac/moz.build rename : intl/locale/src/mac/nsCollationMacUC.cpp => intl/locale/mac/nsCollationMacUC.cpp rename : intl/locale/src/mac/nsCollationMacUC.h => intl/locale/mac/nsCollationMacUC.h rename : intl/locale/src/mac/nsDateTimeFormatMac.cpp => intl/locale/mac/nsDateTimeFormatMac.cpp rename : intl/locale/src/mac/nsDateTimeFormatMac.h => intl/locale/mac/nsDateTimeFormatMac.h rename : intl/locale/src/mac/nsMacCharset.cpp => intl/locale/mac/nsMacCharset.cpp rename : intl/locale/src/nsCollation.cpp => intl/locale/nsCollation.cpp rename : intl/locale/src/nsCollation.h => intl/locale/nsCollation.h rename : intl/locale/src/nsLanguageAtomService.cpp => intl/locale/nsLanguageAtomService.cpp rename : intl/locale/src/nsLanguageAtomService.h => intl/locale/nsLanguageAtomService.h rename : intl/locale/src/nsLocale.cpp => intl/locale/nsLocale.cpp rename : intl/locale/src/nsLocale.h => intl/locale/nsLocale.h rename : intl/locale/src/nsLocaleConstructors.h => intl/locale/nsLocaleConstructors.h rename : intl/locale/src/nsLocaleService.cpp => intl/locale/nsLocaleService.cpp rename : intl/locale/src/nsPlatformCharset.h => intl/locale/nsPlatformCharset.h rename : intl/locale/src/nsScriptableDateFormat.cpp => intl/locale/nsScriptableDateFormat.cpp rename : intl/locale/src/nsUConvPropertySearch.cpp => intl/locale/nsUConvPropertySearch.cpp rename : intl/locale/src/nsUConvPropertySearch.h => intl/locale/nsUConvPropertySearch.h rename : intl/locale/src/props2arrays.py => intl/locale/props2arrays.py rename : intl/locale/src/unix/Makefile.in => intl/locale/unix/Makefile.in rename : intl/locale/src/unix/moz.build => intl/locale/unix/moz.build rename : intl/locale/src/unix/nsAndroidCharset.cpp => intl/locale/unix/nsAndroidCharset.cpp rename : intl/locale/src/unix/nsCollationUnix.cpp => intl/locale/unix/nsCollationUnix.cpp rename : intl/locale/src/unix/nsCollationUnix.h => intl/locale/unix/nsCollationUnix.h rename : intl/locale/src/unix/nsDateTimeFormatUnix.cpp => intl/locale/unix/nsDateTimeFormatUnix.cpp rename : intl/locale/src/unix/nsDateTimeFormatUnix.h => intl/locale/unix/nsDateTimeFormatUnix.h rename : intl/locale/src/unix/nsPosixLocale.cpp => intl/locale/unix/nsPosixLocale.cpp rename : intl/locale/src/unix/nsUNIXCharset.cpp => intl/locale/unix/nsUNIXCharset.cpp rename : intl/locale/src/unix/unixcharset.properties => intl/locale/unix/unixcharset.properties rename : intl/locale/src/windows/Makefile.in => intl/locale/windows/Makefile.in rename : intl/locale/src/windows/moz.build => intl/locale/windows/moz.build rename : intl/locale/src/windows/nsCollationWin.cpp => intl/locale/windows/nsCollationWin.cpp rename : intl/locale/src/windows/nsCollationWin.h => intl/locale/windows/nsCollationWin.h rename : intl/locale/src/windows/nsDateTimeFormatWin.cpp => intl/locale/windows/nsDateTimeFormatWin.cpp rename : intl/locale/src/windows/nsDateTimeFormatWin.h => intl/locale/windows/nsDateTimeFormatWin.h rename : intl/locale/src/windows/nsWin32Locale.cpp => intl/locale/windows/nsWin32Locale.cpp rename : intl/locale/src/windows/nsWinCharset.cpp => intl/locale/windows/nsWinCharset.cpp rename : intl/locale/src/windows/wincharset.properties => intl/locale/windows/wincharset.properties
102 lines
2.3 KiB
C++
102 lines
2.3 KiB
C++
|
|
/* 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 "mozilla/ArrayUtils.h"
|
|
|
|
#include "nsIPlatformCharset.h"
|
|
#include "nsUConvPropertySearch.h"
|
|
#include <windows.h>
|
|
#include "nsWin32Locale.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsReadableUtils.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "nsPlatformCharset.h"
|
|
#include "nsEncoderDecoderUtils.h"
|
|
|
|
using namespace mozilla;
|
|
|
|
static const char* kWinCharsets[][3] = {
|
|
#include "wincharset.properties.h"
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS(nsPlatformCharset, nsIPlatformCharset)
|
|
|
|
nsPlatformCharset::nsPlatformCharset()
|
|
{
|
|
nsAutoString acpKey(NS_LITERAL_STRING("acp."));
|
|
acpKey.AppendInt(int32_t(::GetACP() & 0x00FFFF), 10);
|
|
MapToCharset(acpKey, mCharset);
|
|
}
|
|
|
|
nsPlatformCharset::~nsPlatformCharset()
|
|
{
|
|
}
|
|
|
|
nsresult
|
|
nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
|
|
{
|
|
nsAutoCString key;
|
|
LossyCopyUTF16toASCII(inANSICodePage, key);
|
|
|
|
nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kWinCharsets,
|
|
ArrayLength(kWinCharsets), key, outCharset);
|
|
if (NS_FAILED(rv)) {
|
|
outCharset.AssignLiteral("windows-1252");
|
|
return NS_SUCCESS_USING_FALLBACK_LOCALE;
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
|
|
nsACString& oResult)
|
|
{
|
|
oResult = mCharset;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult)
|
|
{
|
|
LCID localeAsLCID;
|
|
|
|
//
|
|
// convert locale name to a code page (through the LCID)
|
|
//
|
|
nsresult rv;
|
|
oResult.Truncate();
|
|
|
|
rv = nsWin32Locale::GetPlatformLocale(localeName, &localeAsLCID);
|
|
if (NS_FAILED(rv)) { return rv; }
|
|
|
|
wchar_t acp_name[6];
|
|
if (GetLocaleInfoW(localeAsLCID, LOCALE_IDEFAULTANSICODEPAGE, acp_name,
|
|
ArrayLength(acp_name))==0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
nsAutoString acp_key(NS_LITERAL_STRING("acp."));
|
|
acp_key.Append(acp_name);
|
|
|
|
return MapToCharset(acp_key, oResult);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsPlatformCharset::Init()
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsPlatformCharset::InitGetCharset(nsACString &oString)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsPlatformCharset::VerifyCharset(nsCString &aCharset)
|
|
{
|
|
return NS_OK;
|
|
}
|