1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/i18n/character_encoding.h"
7 #include "third_party/icu/source/common/unicode/ucnv.h"
12 // An array of all supported canonical encoding names.
13 const char* const kCanonicalEncodingNames[] = {
14 "Big5", "EUC-JP", "EUC-KR", "gb18030",
15 "GBK", "IBM866", "ISO-2022-JP", "ISO-8859-10",
16 "ISO-8859-13", "ISO-8859-14", "ISO-8859-15", "ISO-8859-16",
17 "ISO-8859-2", "ISO-8859-3", "ISO-8859-4", "ISO-8859-5",
18 "ISO-8859-6", "ISO-8859-7", "ISO-8859-8", "ISO-8859-8-I",
19 "KOI8-R", "KOI8-U", "macintosh", "Shift_JIS",
20 "UTF-16LE", "UTF-8", "windows-1250", "windows-1251",
21 "windows-1252", "windows-1253", "windows-1254", "windows-1255",
22 "windows-1256", "windows-1257", "windows-1258", "windows-874"};
26 std::string GetCanonicalEncodingNameByAliasName(const std::string& alias_name) {
27 for (auto* encoding_name : kCanonicalEncodingNames) {
28 if (alias_name == encoding_name)
31 static const char* kStandards[3] = {"HTML", "MIME", "IANA"};
32 for (auto* standard : kStandards) {
33 UErrorCode error_code = U_ZERO_ERROR;
34 const char* canonical_name =
35 ucnv_getStandardName(alias_name.c_str(), standard, &error_code);
36 if (U_SUCCESS(error_code) && canonical_name)
37 return canonical_name;