michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/ArrayUtils.h" michael@0: michael@0: #include "nsCharsetAlias.h" michael@0: michael@0: // for NS_ERROR_UCONV_NOCONV michael@0: #include "nsCharsetConverterManager.h" michael@0: michael@0: #include "nsUConvPropertySearch.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: // michael@0: static const char* kAliases[][3] = { michael@0: #include "charsetalias.properties.h" michael@0: }; michael@0: michael@0: //-------------------------------------------------------------- michael@0: // static michael@0: nsresult michael@0: nsCharsetAlias::GetPreferredInternal(const nsACString& aAlias, michael@0: nsACString& oResult) michael@0: { michael@0: nsAutoCString key(aAlias); michael@0: ToLowerCase(key); michael@0: michael@0: return nsUConvPropertySearch::SearchPropertyValue(kAliases, michael@0: ArrayLength(kAliases), key, oResult); michael@0: } michael@0: michael@0: //-------------------------------------------------------------- michael@0: // static michael@0: nsresult michael@0: nsCharsetAlias::GetPreferred(const nsACString& aAlias, michael@0: nsACString& oResult) michael@0: { michael@0: if (aAlias.IsEmpty()) return NS_ERROR_NULL_POINTER; michael@0: michael@0: nsresult res = GetPreferredInternal(aAlias, oResult); michael@0: if (NS_FAILED(res)) michael@0: return res; michael@0: michael@0: if (nsCharsetConverterManager::IsInternal(oResult)) michael@0: return NS_ERROR_UCONV_NOCONV; michael@0: michael@0: return res; michael@0: } michael@0: michael@0: //-------------------------------------------------------------- michael@0: // static michael@0: nsresult michael@0: nsCharsetAlias::Equals(const nsACString& aCharset1, michael@0: const nsACString& aCharset2, bool* oResult) michael@0: { michael@0: nsresult res = NS_OK; michael@0: michael@0: if(aCharset1.Equals(aCharset2, nsCaseInsensitiveCStringComparator())) { michael@0: *oResult = true; michael@0: return res; michael@0: } michael@0: michael@0: if(aCharset1.IsEmpty() || aCharset2.IsEmpty()) { michael@0: *oResult = false; michael@0: return res; michael@0: } michael@0: michael@0: *oResult = false; michael@0: nsAutoCString name1; michael@0: res = GetPreferredInternal(aCharset1, name1); michael@0: if (NS_FAILED(res)) michael@0: return res; michael@0: michael@0: nsAutoCString name2; michael@0: res = GetPreferredInternal(aCharset2, name2); michael@0: if (NS_FAILED(res)) michael@0: return res; michael@0: michael@0: *oResult = name1.Equals(name2); michael@0: return NS_OK; michael@0: }