| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/character_encoding.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "third_party/icu/source/common/unicode/ucnv.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 // An array of all supported canonical encoding names. | |
| 13 const char* const kCanonicalEncodingNames[] = { | |
| 14 "Big5", | |
| 15 "EUC-JP", | |
| 16 "EUC-KR", | |
| 17 "gb18030", | |
| 18 "GBK", | |
| 19 "IBM866", | |
| 20 "ISO-2022-JP", | |
| 21 "ISO-8859-10", | |
| 22 "ISO-8859-13", | |
| 23 "ISO-8859-14", | |
| 24 "ISO-8859-15", | |
| 25 "ISO-8859-16", | |
| 26 "ISO-8859-2", | |
| 27 "ISO-8859-3", | |
| 28 "ISO-8859-4", | |
| 29 "ISO-8859-5", | |
| 30 "ISO-8859-6", | |
| 31 "ISO-8859-7", | |
| 32 "ISO-8859-8", | |
| 33 "ISO-8859-8-I", | |
| 34 "KOI8-R", | |
| 35 "KOI8-U", | |
| 36 "macintosh", | |
| 37 "Shift_JIS", | |
| 38 "UTF-16LE", | |
| 39 "UTF-8", | |
| 40 "windows-1250", | |
| 41 "windows-1251", | |
| 42 "windows-1252", | |
| 43 "windows-1253", | |
| 44 "windows-1254", | |
| 45 "windows-1255", | |
| 46 "windows-1256", | |
| 47 "windows-1257", | |
| 48 "windows-1258", | |
| 49 "windows-874" | |
| 50 }; | |
| 51 } // namespace | |
| 52 | |
| 53 std::string GetCanonicalEncodingNameByAliasName(const std::string& alias_name) { | |
| 54 for (size_t i = 0; i < arraysize(kCanonicalEncodingNames); ++i) { | |
| 55 if (alias_name == kCanonicalEncodingNames[i]) | |
| 56 return alias_name; | |
| 57 } | |
| 58 const char* standards[3] = { "HTML", "MIME", "IANA" }; | |
| 59 for (size_t i = 0; i < arraysize(standards); ++i) { | |
| 60 UErrorCode error_code = U_ZERO_ERROR; | |
| 61 const char* canonical_name = ucnv_getCanonicalName( | |
| 62 alias_name.c_str(), standards[i], &error_code); | |
| 63 if (U_SUCCESS(error_code) && canonical_name) | |
| 64 return canonical_name; | |
| 65 } | |
| 66 return std::string(); | |
| 67 } | |
| OLD | NEW |