зеркало из https://github.com/mozilla/gecko-dev.git
r=pedemonte, sr=blizzard (platform specific), a=mkaply (OS/2 only) Implement GetPlatformLocale so JS dates/times work again
This commit is contained in:
Родитель
cb5a02337a
Коммит
8641dd0f8a
|
@ -41,8 +41,7 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "unidef.h"
|
||||
|
||||
#include <os2.h>
|
||||
|
||||
// {F25F74F0-FB59-11d3-A9F2-00203522A03C}
|
||||
#define NS_IOS2LOCALE_IID \
|
||||
|
@ -55,7 +54,7 @@ class nsIOS2Locale : public nsISupports
|
|||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IOS2LOCALE_IID)
|
||||
NS_IMETHOD GetPlatformLocale(PRUnichar* os2Locale,size_t length)=0;
|
||||
NS_IMETHOD GetPlatformLocale(const nsAString& locale, PULONG os2Codepage) = 0;
|
||||
NS_IMETHOD GetXPLocale(const char* os2Locale, nsAString& locale)=0;
|
||||
};
|
||||
|
||||
|
|
|
@ -56,6 +56,14 @@
|
|||
#include "nsLocaleCID.h"
|
||||
#include "prprf.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include <unidef.h>
|
||||
|
||||
extern "C" {
|
||||
#include <callconv.h>
|
||||
int APIENTRY UniQueryLocaleValue ( const LocaleObject locale_object,
|
||||
LocaleItem item,
|
||||
int *info_item);
|
||||
}
|
||||
|
||||
/* nsOS2Locale ISupports */
|
||||
NS_IMPL_ISUPPORTS1(nsOS2Locale,nsIOS2Locale)
|
||||
|
@ -75,22 +83,27 @@ nsOS2Locale::~nsOS2Locale(void)
|
|||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOS2Locale::GetPlatformLocale(PRUnichar* os2Locale, size_t length)
|
||||
nsOS2Locale::GetPlatformLocale(const nsAString& locale, PULONG os2Codepage)
|
||||
{
|
||||
|
||||
LocaleObject locObj = NULL;
|
||||
UniChar *localeName = NULL;
|
||||
int codePage;
|
||||
nsAutoString tempLocale(locale);
|
||||
tempLocale.ReplaceChar('-', '_');
|
||||
|
||||
int ret = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)L"", &locObj);
|
||||
|
||||
int ret = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)PromiseFlatString(tempLocale).get(), &locObj);
|
||||
if (ret != ULS_SUCCESS)
|
||||
UniCreateLocaleObject(UNI_UCS_STRING_POINTER, (UniChar *)L"C", &locObj);
|
||||
|
||||
ret = UniQueryLocaleItem(locObj, LOCI_sName, &localeName);
|
||||
ret = UniQueryLocaleValue(locObj, LOCI_iCodepage, &codePage);
|
||||
if (ret != ULS_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
UniStrncpy((UniChar*)os2Locale, localeName, length);
|
||||
UniFreeMem(localeName);
|
||||
if (codePage == 437) {
|
||||
*os2Codepage = 850;
|
||||
} else {
|
||||
*os2Codepage = codePage;
|
||||
}
|
||||
UniFreeLocaleObject(locObj);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIOS2Locale.h"
|
||||
#include <os2.h>
|
||||
|
||||
|
||||
class nsOS2Locale : public nsIOS2Locale {
|
||||
|
@ -52,8 +53,7 @@ public:
|
|||
nsOS2Locale();
|
||||
virtual ~nsOS2Locale();
|
||||
|
||||
NS_IMETHOD GetPlatformLocale(PRUnichar* os2Locale,
|
||||
size_t length);
|
||||
NS_IMETHOD GetPlatformLocale(const nsAString& locale, PULONG os2Codepage);
|
||||
NS_IMETHOD GetXPLocale(const char* os2Locale, nsAString& locale);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -152,8 +152,27 @@ nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
|
|||
NS_IMETHODIMP
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString &oResult)
|
||||
{
|
||||
oResult.AssignLiteral("ISO-8859-1");
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIOS2Locale> os2Locale;
|
||||
ULONG codepage;
|
||||
char acp_name[6];
|
||||
|
||||
//
|
||||
// convert locale name to a code page
|
||||
//
|
||||
nsresult rv;
|
||||
oResult.Truncate();
|
||||
|
||||
os2Locale = do_CreateInstance(NS_OS2LOCALE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) { return rv; }
|
||||
|
||||
rv = os2Locale->GetPlatformLocale(localeName, &codepage);
|
||||
if (NS_FAILED(rv)) { return rv; }
|
||||
|
||||
nsAutoString os2_key(NS_LITERAL_STRING("os2."));
|
||||
os2_key.AppendInt((PRUint32)codepage);
|
||||
|
||||
return MapToCharset(os2_key, oResult);
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
Загрузка…
Ссылка в новой задаче