intl/locale/src/windows/nsWinCharset.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/locale/src/windows/nsWinCharset.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "mozilla/ArrayUtils.h"
    1.10 +
    1.11 +#include "nsIPlatformCharset.h"
    1.12 +#include "nsUConvPropertySearch.h"
    1.13 +#include <windows.h>
    1.14 +#include "nsWin32Locale.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsReadableUtils.h"
    1.17 +#include "nsServiceManagerUtils.h"
    1.18 +#include "nsPlatformCharset.h"
    1.19 +#include "nsEncoderDecoderUtils.h"
    1.20 +
    1.21 +using namespace mozilla;
    1.22 +
    1.23 +static const char* kWinCharsets[][3] = {
    1.24 +#include "wincharset.properties.h"
    1.25 +};
    1.26 +
    1.27 +NS_IMPL_ISUPPORTS(nsPlatformCharset, nsIPlatformCharset)
    1.28 +
    1.29 +nsPlatformCharset::nsPlatformCharset()
    1.30 +{
    1.31 +  nsAutoString acpKey(NS_LITERAL_STRING("acp."));
    1.32 +  acpKey.AppendInt(int32_t(::GetACP() & 0x00FFFF), 10);
    1.33 +  MapToCharset(acpKey, mCharset);
    1.34 +}
    1.35 +
    1.36 +nsPlatformCharset::~nsPlatformCharset()
    1.37 +{
    1.38 +}
    1.39 +
    1.40 +nsresult
    1.41 +nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
    1.42 +{
    1.43 +  nsAutoCString key;
    1.44 +  LossyCopyUTF16toASCII(inANSICodePage, key);
    1.45 +
    1.46 +  nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kWinCharsets,
    1.47 +      ArrayLength(kWinCharsets), key, outCharset);
    1.48 +  if (NS_FAILED(rv)) {
    1.49 +    outCharset.AssignLiteral("windows-1252");
    1.50 +    return NS_SUCCESS_USING_FALLBACK_LOCALE;
    1.51 +  }
    1.52 +  return rv;
    1.53 +}
    1.54 +
    1.55 +NS_IMETHODIMP 
    1.56 +nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
    1.57 +                              nsACString& oResult)
    1.58 +{
    1.59 +  oResult = mCharset;
    1.60 +  return NS_OK;
    1.61 +}
    1.62 +
    1.63 +NS_IMETHODIMP
    1.64 +nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult)
    1.65 +{
    1.66 +  LCID                      localeAsLCID;
    1.67 +
    1.68 +  //
    1.69 +  // convert locale name to a code page (through the LCID)
    1.70 +  //
    1.71 +  nsresult rv;
    1.72 +  oResult.Truncate();
    1.73 +
    1.74 +  rv = nsWin32Locale::GetPlatformLocale(localeName, &localeAsLCID);
    1.75 +  if (NS_FAILED(rv)) { return rv; }
    1.76 +
    1.77 +  wchar_t acp_name[6];
    1.78 +  if (GetLocaleInfoW(localeAsLCID, LOCALE_IDEFAULTANSICODEPAGE, acp_name,
    1.79 +                     ArrayLength(acp_name))==0) {
    1.80 +    return NS_ERROR_FAILURE; 
    1.81 +  }
    1.82 +  nsAutoString acp_key(NS_LITERAL_STRING("acp."));
    1.83 +  acp_key.Append(acp_name);
    1.84 +
    1.85 +  return MapToCharset(acp_key, oResult);
    1.86 +}
    1.87 +
    1.88 +NS_IMETHODIMP 
    1.89 +nsPlatformCharset::Init()
    1.90 +{
    1.91 +  return NS_OK;
    1.92 +}
    1.93 +
    1.94 +nsresult
    1.95 +nsPlatformCharset::InitGetCharset(nsACString &oString)
    1.96 +{
    1.97 +  return NS_OK;
    1.98 +}
    1.99 +
   1.100 +nsresult
   1.101 +nsPlatformCharset::VerifyCharset(nsCString &aCharset)
   1.102 +{
   1.103 +  return NS_OK;
   1.104 +}

mercurial