2003-07-22 23:46:38 +00:00
|
|
|
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
1999-02-23 09:48:43 +00:00
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
1999-02-23 09:52:48 +00:00
|
|
|
#include "nsIPlatformCharset.h"
|
2010-05-10 14:09:13 +00:00
|
|
|
#include "nsUConvPropertySearch.h"
|
1999-02-25 01:28:04 +00:00
|
|
|
#include <windows.h>
|
2011-05-02 08:49:11 +00:00
|
|
|
#include "nsWin32Locale.h"
|
1999-08-25 22:05:28 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2004-11-24 22:48:45 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2001-12-08 00:25:28 +00:00
|
|
|
#include "nsPlatformCharset.h"
|
2011-07-11 15:53:55 +00:00
|
|
|
#include "nsEncoderDecoderUtils.h"
|
1999-02-23 09:48:43 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-05-10 14:09:13 +00:00
|
|
|
static const char* kWinCharsets[][3] = {
|
|
|
|
#include "wincharset.properties.h"
|
|
|
|
};
|
2000-03-17 21:46:02 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsPlatformCharset, nsIPlatformCharset)
|
2001-10-22 21:52:16 +00:00
|
|
|
|
2001-12-08 00:25:28 +00:00
|
|
|
nsPlatformCharset::nsPlatformCharset()
|
1999-02-23 09:48:43 +00:00
|
|
|
{
|
2003-06-11 18:16:03 +00:00
|
|
|
nsAutoString acpKey(NS_LITERAL_STRING("acp."));
|
2012-08-22 15:56:38 +00:00
|
|
|
acpKey.AppendInt(int32_t(::GetACP() & 0x00FFFF), 10);
|
2004-05-27 09:00:16 +00:00
|
|
|
MapToCharset(acpKey, mCharset);
|
|
|
|
}
|
|
|
|
|
2001-12-08 00:25:28 +00:00
|
|
|
nsPlatformCharset::~nsPlatformCharset()
|
1999-02-23 09:48:43 +00:00
|
|
|
{
|
2001-10-22 21:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2003-06-11 18:16:03 +00:00
|
|
|
nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
|
2001-10-22 21:52:16 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString key;
|
2010-05-10 14:09:13 +00:00
|
|
|
LossyCopyUTF16toASCII(inANSICodePage, key);
|
2001-10-22 21:52:16 +00:00
|
|
|
|
2010-05-10 14:09:13 +00:00
|
|
|
nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kWinCharsets,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(kWinCharsets), key, outCharset);
|
2001-10-22 21:52:16 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2004-06-17 00:13:25 +00:00
|
|
|
outCharset.AssignLiteral("windows-1252");
|
2011-07-11 15:53:55 +00:00
|
|
|
return NS_SUCCESS_USING_FALLBACK_LOCALE;
|
2001-10-22 21:52:16 +00:00
|
|
|
}
|
2010-05-10 14:09:13 +00:00
|
|
|
return rv;
|
2001-10-22 21:52:16 +00:00
|
|
|
}
|
|
|
|
|
1999-02-23 09:48:43 +00:00
|
|
|
NS_IMETHODIMP
|
2003-06-11 18:16:03 +00:00
|
|
|
nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
|
|
|
|
nsACString& oResult)
|
1999-02-23 09:48:43 +00:00
|
|
|
{
|
2001-12-08 00:25:28 +00:00
|
|
|
oResult = mCharset;
|
|
|
|
return NS_OK;
|
1999-02-23 09:48:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-25 22:05:28 +00:00
|
|
|
NS_IMETHODIMP
|
2003-10-30 05:04:45 +00:00
|
|
|
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult)
|
1999-08-25 22:05:28 +00:00
|
|
|
{
|
2008-08-11 22:11:48 +00:00
|
|
|
LCID localeAsLCID;
|
2001-12-08 00:25:28 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// convert locale name to a code page (through the LCID)
|
|
|
|
//
|
2003-07-22 23:46:38 +00:00
|
|
|
nsresult rv;
|
|
|
|
oResult.Truncate();
|
|
|
|
|
2011-05-02 08:49:11 +00:00
|
|
|
rv = nsWin32Locale::GetPlatformLocale(localeName, &localeAsLCID);
|
2003-07-22 23:46:38 +00:00
|
|
|
if (NS_FAILED(rv)) { return rv; }
|
1999-08-25 22:05:28 +00:00
|
|
|
|
2013-12-03 15:09:50 +00:00
|
|
|
wchar_t acp_name[6];
|
2008-08-11 22:11:48 +00:00
|
|
|
if (GetLocaleInfoW(localeAsLCID, LOCALE_IDEFAULTANSICODEPAGE, acp_name,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(acp_name))==0) {
|
2001-12-08 00:25:28 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-10-30 05:04:45 +00:00
|
|
|
nsAutoString acp_key(NS_LITERAL_STRING("acp."));
|
2008-08-11 22:11:48 +00:00
|
|
|
acp_key.Append(acp_name);
|
2001-12-08 00:25:28 +00:00
|
|
|
|
2003-07-22 23:46:38 +00:00
|
|
|
return MapToCharset(acp_key, oResult);
|
1999-08-25 22:05:28 +00:00
|
|
|
}
|
|
|
|
|
2001-12-08 00:25:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPlatformCharset::Init()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-23 09:48:43 +00:00
|
|
|
|
2001-12-08 00:25:28 +00:00
|
|
|
nsresult
|
2003-06-11 18:16:03 +00:00
|
|
|
nsPlatformCharset::InitGetCharset(nsACString &oString)
|
2001-12-08 00:25:28 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2003-06-11 18:16:03 +00:00
|
|
|
nsPlatformCharset::VerifyCharset(nsCString &aCharset)
|
2001-12-08 00:25:28 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
1999-02-23 09:48:43 +00:00
|
|
|
}
|