intl/locale/src/windows/nsWinCharset.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "mozilla/ArrayUtils.h"
     8 #include "nsIPlatformCharset.h"
     9 #include "nsUConvPropertySearch.h"
    10 #include <windows.h>
    11 #include "nsWin32Locale.h"
    12 #include "nsCOMPtr.h"
    13 #include "nsReadableUtils.h"
    14 #include "nsServiceManagerUtils.h"
    15 #include "nsPlatformCharset.h"
    16 #include "nsEncoderDecoderUtils.h"
    18 using namespace mozilla;
    20 static const char* kWinCharsets[][3] = {
    21 #include "wincharset.properties.h"
    22 };
    24 NS_IMPL_ISUPPORTS(nsPlatformCharset, nsIPlatformCharset)
    26 nsPlatformCharset::nsPlatformCharset()
    27 {
    28   nsAutoString acpKey(NS_LITERAL_STRING("acp."));
    29   acpKey.AppendInt(int32_t(::GetACP() & 0x00FFFF), 10);
    30   MapToCharset(acpKey, mCharset);
    31 }
    33 nsPlatformCharset::~nsPlatformCharset()
    34 {
    35 }
    37 nsresult
    38 nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
    39 {
    40   nsAutoCString key;
    41   LossyCopyUTF16toASCII(inANSICodePage, key);
    43   nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kWinCharsets,
    44       ArrayLength(kWinCharsets), key, outCharset);
    45   if (NS_FAILED(rv)) {
    46     outCharset.AssignLiteral("windows-1252");
    47     return NS_SUCCESS_USING_FALLBACK_LOCALE;
    48   }
    49   return rv;
    50 }
    52 NS_IMETHODIMP 
    53 nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
    54                               nsACString& oResult)
    55 {
    56   oResult = mCharset;
    57   return NS_OK;
    58 }
    60 NS_IMETHODIMP
    61 nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult)
    62 {
    63   LCID                      localeAsLCID;
    65   //
    66   // convert locale name to a code page (through the LCID)
    67   //
    68   nsresult rv;
    69   oResult.Truncate();
    71   rv = nsWin32Locale::GetPlatformLocale(localeName, &localeAsLCID);
    72   if (NS_FAILED(rv)) { return rv; }
    74   wchar_t acp_name[6];
    75   if (GetLocaleInfoW(localeAsLCID, LOCALE_IDEFAULTANSICODEPAGE, acp_name,
    76                      ArrayLength(acp_name))==0) {
    77     return NS_ERROR_FAILURE; 
    78   }
    79   nsAutoString acp_key(NS_LITERAL_STRING("acp."));
    80   acp_key.Append(acp_name);
    82   return MapToCharset(acp_key, oResult);
    83 }
    85 NS_IMETHODIMP 
    86 nsPlatformCharset::Init()
    87 {
    88   return NS_OK;
    89 }
    91 nsresult
    92 nsPlatformCharset::InitGetCharset(nsACString &oString)
    93 {
    94   return NS_OK;
    95 }
    97 nsresult
    98 nsPlatformCharset::VerifyCharset(nsCString &aCharset)
    99 {
   100   return NS_OK;
   101 }

mercurial