зеркало из https://github.com/mozilla/pjs.git
Implement bug #5561 (Locale support: map locale name to default character set) on windows.
This commit is contained in:
Родитель
d3a330d9a0
Коммит
74448e55a6
|
@ -55,6 +55,8 @@ public:
|
|||
|
||||
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsString& oResult) = 0;
|
||||
|
||||
NS_IMETHOD GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsIPlatformCharset_h__ */
|
||||
|
|
|
@ -36,6 +36,8 @@ public:
|
|||
virtual ~nsMacCharset();
|
||||
|
||||
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsString& oResult);
|
||||
NS_IMETHOD GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue);
|
||||
|
||||
private:
|
||||
nsString mCharset;
|
||||
};
|
||||
|
@ -85,6 +87,12 @@ nsMacCharset::GetCharset(nsPlatformCharsetSel selector, nsString& oResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class nsMacCharsetFactory : public nsIFactory {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
virtual ~nsUNIXCharset();
|
||||
|
||||
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsString& oResult);
|
||||
NS_IMETHOD GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue);
|
||||
|
||||
private:
|
||||
nsString mCharset;
|
||||
|
@ -89,6 +90,12 @@ nsUNIXCharset::GetCharset(nsPlatformCharsetSel selector, nsString& oResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUNIXCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class nsUNIXCharsetFactory : public nsIFactory {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
|
|
@ -23,7 +23,13 @@
|
|||
#include <windows.h>
|
||||
#include "nsUConvDll.h"
|
||||
#include "nsPlatformCharsetFactory.h"
|
||||
#include "nsIWin32Locale.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
NS_DEFINE_IID(kIWin32LocaleIID, NS_IWIN32LOCALE_IID);
|
||||
NS_DEFINE_CID(kWin32LocaleFactoryCID, NS_WIN32LOCALEFACTORY_CID);
|
||||
|
||||
class nsWinCharset : public nsIPlatformCharset
|
||||
{
|
||||
|
@ -35,6 +41,7 @@ public:
|
|||
virtual ~nsWinCharset();
|
||||
|
||||
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsString& oResult);
|
||||
NS_IMETHOD GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue);
|
||||
private:
|
||||
nsString mCharset;
|
||||
};
|
||||
|
@ -78,6 +85,41 @@ nsWinCharset::GetCharset(nsPlatformCharsetSel selector, nsString& oResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWinCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue)
|
||||
{
|
||||
nsCOMPtr<nsIWin32Locale> winLocale;
|
||||
LCID localeAsLCID;
|
||||
char acp_name[6];
|
||||
nsString charset("windows-1252");
|
||||
nsString localeAsNSString(localeName);
|
||||
|
||||
//
|
||||
// convert locale name to a code page (through the LCID)
|
||||
//
|
||||
nsresult result = nsComponentManager::CreateInstance(kWin32LocaleFactoryCID,nsnull,kIWin32LocaleIID,
|
||||
getter_AddRefs(winLocale));
|
||||
result = winLocale->GetPlatformLocale(&localeAsNSString,&localeAsLCID);
|
||||
if (NS_FAILED(result)) { *_retValue = charset.ToNewUnicode(); return result; }
|
||||
|
||||
if (GetLocaleInfo(localeAsLCID,LOCALE_IDEFAULTANSICODEPAGE,acp_name,sizeof(acp_name))==0) { *_retValue = charset.ToNewUnicode(); return NS_ERROR_FAILURE; }
|
||||
|
||||
//
|
||||
// load property file and convert from LCID->charset
|
||||
//
|
||||
|
||||
nsAutoString property_url("resource:/res/wincharset.properties");
|
||||
nsURLProperties *charset_properties = new nsURLProperties(property_url);
|
||||
if (!charset_properties) { *_retValue = charset.ToNewUnicode(); return NS_ERROR_OUT_OF_MEMORY; }
|
||||
|
||||
nsAutoString acp_key("acp.");
|
||||
acp_key.Append(acp_name);
|
||||
result = charset_properties->Get(acp_key,charset);
|
||||
|
||||
*_retValue = charset.ToNewUnicode();
|
||||
return result;
|
||||
}
|
||||
|
||||
class nsWinCharsetFactory : public nsIFactory {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ MAKE_OBJ_TYPE = EXE
|
|||
PROG1 = .\$(OBJDIR)\convperf.exe
|
||||
PROG2 = .\$(OBJDIR)\nsTestUConv.exe
|
||||
PROG3 = .\$(OBJDIR)\nsconv.exe
|
||||
PROGRAMS = $(PROG1) $(PROG2) $(PROG3)
|
||||
PROG4 = .\$(OBJDIR)\plattest.exe
|
||||
PROGRAMS = $(PROG1) $(PROG2) $(PROG3) $(PROG4)
|
||||
|
||||
LCFLAGS=-DUSE_NSREG
|
||||
|
||||
|
@ -47,3 +48,4 @@ clobber::
|
|||
$(PROG1): $(OBJDIR) convperf.cpp
|
||||
$(PROG2): $(OBJDIR) nsTestUConv.cpp
|
||||
$(PROG3): $(OBJDIR) nsconv.cpp
|
||||
$(PROG4): $(OBJDIR) plattest.cpp
|
||||
|
|
|
@ -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 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 "nsIPlatformCharset.h"
|
||||
#include "nsILocaleService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include <stdio.h>
|
||||
|
||||
NS_DEFINE_IID(kLocaleServiceIID,NS_ILOCALESERVICE_IID);
|
||||
NS_DEFINE_CID(kLocaleServiceCID,NS_LOCALESERVICE_CID);
|
||||
NS_DEFINE_IID(kPlatformCharsetIID,NS_IPLATFORMCHARSET_IID);
|
||||
|
||||
int
|
||||
main(int argc, const char** argv)
|
||||
{
|
||||
nsCOMPtr<nsILocaleService> locale_service;
|
||||
nsCOMPtr<nsILocale> locale;
|
||||
nsCOMPtr<nsIPlatformCharset> platform_charset;
|
||||
nsString locale_category("NSILOCALE_MESSAGES");
|
||||
PRUnichar* category_value, *charset;
|
||||
nsString categoryAsNSString, charsetAsNSString;
|
||||
|
||||
nsresult rv = nsComponentManager::CreateInstance(NS_PLATFORMCHARSET_PROGID,NULL,kPlatformCharsetIID,getter_AddRefs(platform_charset));
|
||||
rv = nsComponentManager::CreateInstance(kLocaleServiceCID,NULL,kLocaleServiceIID,getter_AddRefs(locale_service));
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = locale_service->GetSystemLocale(getter_AddRefs(locale));
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = locale->GetCategory(locale_category.GetUnicode(),&category_value);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = platform_charset->GetDefaultCharsetForLocale(category_value,&charset);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
charsetAsNSString = charset;
|
||||
categoryAsNSString = category_value;
|
||||
printf("DefaultCharset for %s is %s\n",categoryAsNSString.ToNewCString(),charsetAsNSString.ToNewCString());
|
||||
|
||||
categoryAsNSString = "en-US";
|
||||
rv = platform_charset->GetDefaultCharsetForLocale(categoryAsNSString.GetUnicode(),&charset);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
charsetAsNSString = charset;
|
||||
printf("DefaultCharset for %s is %s\n",categoryAsNSString.ToNewCString(),charsetAsNSString.ToNewCString());
|
||||
|
||||
return 0;
|
||||
}
|
Загрузка…
Ссылка в новой задаче