intl/locale/src/nsCharsetAlias.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     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 "nsCharsetAlias.h"
    10 // for NS_ERROR_UCONV_NOCONV
    11 #include "nsCharsetConverterManager.h"
    13 #include "nsUConvPropertySearch.h"
    15 using namespace mozilla;
    17 // 
    18 static const char* kAliases[][3] = {
    19 #include "charsetalias.properties.h"
    20 };
    22 //--------------------------------------------------------------
    23 // static
    24 nsresult
    25 nsCharsetAlias::GetPreferredInternal(const nsACString& aAlias,
    26                                      nsACString& oResult)
    27 {
    28    nsAutoCString key(aAlias);
    29    ToLowerCase(key);
    31    return nsUConvPropertySearch::SearchPropertyValue(kAliases,
    32       ArrayLength(kAliases), key, oResult);
    33 }
    35 //--------------------------------------------------------------
    36 // static
    37 nsresult
    38 nsCharsetAlias::GetPreferred(const nsACString& aAlias,
    39                              nsACString& oResult)
    40 {
    41    if (aAlias.IsEmpty()) return NS_ERROR_NULL_POINTER;
    43    nsresult res = GetPreferredInternal(aAlias, oResult);
    44    if (NS_FAILED(res))
    45       return res;
    47    if (nsCharsetConverterManager::IsInternal(oResult))
    48       return NS_ERROR_UCONV_NOCONV;
    50    return res;
    51 }
    53 //--------------------------------------------------------------
    54 // static
    55 nsresult
    56 nsCharsetAlias::Equals(const nsACString& aCharset1,
    57                        const nsACString& aCharset2, bool* oResult)
    58 {
    59    nsresult res = NS_OK;
    61    if(aCharset1.Equals(aCharset2, nsCaseInsensitiveCStringComparator())) {
    62       *oResult = true;
    63       return res;
    64    }
    66    if(aCharset1.IsEmpty() || aCharset2.IsEmpty()) {
    67       *oResult = false;
    68       return res;
    69    }
    71    *oResult = false;
    72    nsAutoCString name1;
    73    res = GetPreferredInternal(aCharset1, name1);
    74    if (NS_FAILED(res))
    75      return res;
    77    nsAutoCString name2;
    78    res = GetPreferredInternal(aCharset2, name2);
    79    if (NS_FAILED(res))
    80      return res;
    82    *oResult = name1.Equals(name2);
    83    return NS_OK;
    84 }

mercurial