diff options
Diffstat (limited to 'chrome/browser/character_encoding.cc')
-rw-r--r-- | chrome/browser/character_encoding.cc | 123 |
1 files changed, 61 insertions, 62 deletions
diff --git a/chrome/browser/character_encoding.cc b/chrome/browser/character_encoding.cc index b6659ea..c40895b 100644 --- a/chrome/browser/character_encoding.cc +++ b/chrome/browser/character_encoding.cc @@ -24,56 +24,56 @@ const int kUserSelectedEncodingsMaxLength = 3; typedef struct { int resource_id; - const char* name; + const wchar_t* name; int category_string_id; } CanonicalEncodingData; // An array of all supported canonical encoding names. static CanonicalEncodingData canonical_encoding_names[] = { - { IDC_ENCODING_UTF8, "UTF-8", IDS_ENCODING_UNICODE }, - { IDC_ENCODING_UTF16LE, "UTF-16LE", IDS_ENCODING_UNICODE }, - { IDC_ENCODING_ISO88591, "ISO-8859-1", IDS_ENCODING_WESTERN }, - { IDC_ENCODING_WINDOWS1252, "windows-1252", IDS_ENCODING_WESTERN }, - { IDC_ENCODING_GB2312, "GB2312", IDS_ENCODING_SIMP_CHINESE }, - { IDC_ENCODING_GB18030, "gb18030", IDS_ENCODING_SIMP_CHINESE }, - { IDC_ENCODING_BIG5, "Big5", IDS_ENCODING_TRAD_CHINESE }, - { IDC_ENCODING_BIG5HKSCS, "Big5-HKSCS", IDS_ENCODING_TRAD_CHINESE }, - { IDC_ENCODING_KOREAN, "EUC-KR", IDS_ENCODING_KOREAN }, - { IDC_ENCODING_SHIFTJIS, "Shift_JIS", IDS_ENCODING_JAPANESE }, - { IDC_ENCODING_ISO2022JP, "ISO-2022-JP", IDS_ENCODING_JAPANESE }, - { IDC_ENCODING_EUCJP, "EUC-JP", IDS_ENCODING_JAPANESE }, - { IDC_ENCODING_THAI, "TIS-620", IDS_ENCODING_THAI }, - { IDC_ENCODING_ISO885915, "ISO-8859-15", IDS_ENCODING_WESTERN }, - { IDC_ENCODING_MACINTOSH, "macintosh", IDS_ENCODING_WESTERN }, - { IDC_ENCODING_ISO88592, "ISO-8859-2", IDS_ENCODING_CENTRAL_EUROPEAN }, - { IDC_ENCODING_WINDOWS1250, "windows-1250", IDS_ENCODING_CENTRAL_EUROPEAN }, - { IDC_ENCODING_ISO88595, "ISO-8859-5", IDS_ENCODING_CYRILLIC }, - { IDC_ENCODING_WINDOWS1251, "windows-1251", IDS_ENCODING_CYRILLIC }, - { IDC_ENCODING_KOI8R, "KOI8-R", IDS_ENCODING_CYRILLIC }, - { IDC_ENCODING_KOI8U, "KOI8-U", IDS_ENCODING_CYRILLIC }, - { IDC_ENCODING_ISO88597, "ISO-8859-7", IDS_ENCODING_GREEK }, - { IDC_ENCODING_WINDOWS1253, "windows-1253", IDS_ENCODING_GREEK }, - { IDC_ENCODING_ISO88599, "ISO-8859-9", IDS_ENCODING_TURKISH }, - { IDC_ENCODING_WINDOWS1254, "windows-1254", IDS_ENCODING_TURKISH }, - { IDC_ENCODING_ISO88596, "ISO-8859-6", IDS_ENCODING_ARABIC }, - { IDC_ENCODING_WINDOWS1256, "windows-1256", IDS_ENCODING_ARABIC }, - { IDC_ENCODING_ISO88598, "ISO-8859-8", IDS_ENCODING_HEBREW }, - { IDC_ENCODING_WINDOWS1255, "windows-1255", IDS_ENCODING_HEBREW }, - { IDC_ENCODING_WINDOWS1258, "windows-1258", IDS_ENCODING_VIETNAMESE }, - { IDC_ENCODING_ISO88594, "ISO-8859-4", IDS_ENCODING_BALTIC }, - { IDC_ENCODING_ISO885913, "ISO-8859-13", IDS_ENCODING_BALTIC }, - { IDC_ENCODING_WINDOWS1257, "windows-1257", IDS_ENCODING_BALTIC }, - { IDC_ENCODING_ISO88593, "ISO-8859-3", IDS_ENCODING_SOUTH_EUROPEAN }, - { IDC_ENCODING_ISO885910, "ISO-8859-10", IDS_ENCODING_NORDIC }, - { IDC_ENCODING_ISO885914, "ISO-8859-14", IDS_ENCODING_CELTIC }, - { IDC_ENCODING_ISO885916, "ISO-8859-16", IDS_ENCODING_ROMANIAN }, + { IDC_ENCODING_UTF8, L"UTF-8", IDS_ENCODING_UNICODE }, + { IDC_ENCODING_UTF16LE, L"UTF-16LE", IDS_ENCODING_UNICODE }, + { IDC_ENCODING_ISO88591, L"ISO-8859-1", IDS_ENCODING_WESTERN }, + { IDC_ENCODING_WINDOWS1252, L"windows-1252", IDS_ENCODING_WESTERN }, + { IDC_ENCODING_GB2312, L"GB2312", IDS_ENCODING_SIMP_CHINESE }, + { IDC_ENCODING_GB18030, L"gb18030", IDS_ENCODING_SIMP_CHINESE }, + { IDC_ENCODING_BIG5, L"Big5", IDS_ENCODING_TRAD_CHINESE }, + { IDC_ENCODING_BIG5HKSCS, L"Big5-HKSCS", IDS_ENCODING_TRAD_CHINESE }, + { IDC_ENCODING_KOREAN, L"EUC-KR", IDS_ENCODING_KOREAN }, + { IDC_ENCODING_SHIFTJIS, L"Shift_JIS", IDS_ENCODING_JAPANESE }, + { IDC_ENCODING_ISO2022JP, L"ISO-2022-JP", IDS_ENCODING_JAPANESE }, + { IDC_ENCODING_EUCJP, L"EUC-JP", IDS_ENCODING_JAPANESE }, + { IDC_ENCODING_THAI, L"TIS-620", IDS_ENCODING_THAI }, + { IDC_ENCODING_ISO885915, L"ISO-8859-15", IDS_ENCODING_WESTERN }, + { IDC_ENCODING_MACINTOSH, L"macintosh", IDS_ENCODING_WESTERN }, + { IDC_ENCODING_ISO88592, L"ISO-8859-2", IDS_ENCODING_CENTRAL_EUROPEAN }, + { IDC_ENCODING_WINDOWS1250, L"windows-1250", IDS_ENCODING_CENTRAL_EUROPEAN }, + { IDC_ENCODING_ISO88595, L"ISO-8859-5", IDS_ENCODING_CYRILLIC }, + { IDC_ENCODING_WINDOWS1251, L"windows-1251", IDS_ENCODING_CYRILLIC }, + { IDC_ENCODING_KOI8R, L"KOI8-R", IDS_ENCODING_CYRILLIC }, + { IDC_ENCODING_KOI8U, L"KOI8-U", IDS_ENCODING_CYRILLIC }, + { IDC_ENCODING_ISO88597, L"ISO-8859-7", IDS_ENCODING_GREEK }, + { IDC_ENCODING_WINDOWS1253, L"windows-1253", IDS_ENCODING_GREEK }, + { IDC_ENCODING_ISO88599, L"ISO-8859-9", IDS_ENCODING_TURKISH }, + { IDC_ENCODING_WINDOWS1254, L"windows-1254", IDS_ENCODING_TURKISH }, + { IDC_ENCODING_ISO88596, L"ISO-8859-6", IDS_ENCODING_ARABIC }, + { IDC_ENCODING_WINDOWS1256, L"windows-1256", IDS_ENCODING_ARABIC }, + { IDC_ENCODING_ISO88598, L"ISO-8859-8", IDS_ENCODING_HEBREW }, + { IDC_ENCODING_WINDOWS1255, L"windows-1255", IDS_ENCODING_HEBREW }, + { IDC_ENCODING_WINDOWS1258, L"windows-1258", IDS_ENCODING_VIETNAMESE }, + { IDC_ENCODING_ISO88594, L"ISO-8859-4", IDS_ENCODING_BALTIC }, + { IDC_ENCODING_ISO885913, L"ISO-8859-13", IDS_ENCODING_BALTIC }, + { IDC_ENCODING_WINDOWS1257, L"windows-1257", IDS_ENCODING_BALTIC }, + { IDC_ENCODING_ISO88593, L"ISO-8859-3", IDS_ENCODING_SOUTH_EUROPEAN }, + { IDC_ENCODING_ISO885910, L"ISO-8859-10", IDS_ENCODING_NORDIC }, + { IDC_ENCODING_ISO885914, L"ISO-8859-14", IDS_ENCODING_CELTIC }, + { IDC_ENCODING_ISO885916, L"ISO-8859-16", IDS_ENCODING_ROMANIAN }, }; static const int canonical_encoding_names_length = arraysize(canonical_encoding_names); -typedef std::map<int, std::pair<const char*, int> > IdToCanonicalEncodingNameMapType; -typedef std::map<const std::string, int> CanonicalEncodingNameToIdMapType; +typedef std::map<int, std::pair<const wchar_t*, int> > IdToCanonicalEncodingNameMapType; +typedef std::map<const std::wstring, int> CanonicalEncodingNameToIdMapType; class CanonicalEncodingMap { public: @@ -134,7 +134,7 @@ static CanonicalEncodingMap canonical_encoding_name_map_singleton; // Get encoding command id according to input encoding name. If the name is // valid, return corresponding encoding command id. Otherwise return 0; static int GetCommandIdByCanonicalEncodingName( - const std::string& encoding_name) { + const std::wstring& encoding_name) { const CanonicalEncodingNameToIdMapType* map = canonical_encoding_name_map_singleton. GetCanonicalEncodingNameToIdMapData(); @@ -206,8 +206,7 @@ static void ParseEncodingListSeparatedWithComma( size_t maximum_size) { WStringTokenizer tokenizer(encoding_list, L","); while (tokenizer.GetNext()) { - std::string valid_encoding = WideToUTF8(tokenizer.token()); - int id = GetCommandIdByCanonicalEncodingName(valid_encoding); + int id = GetCommandIdByCanonicalEncodingName(tokenizer.token()); // Ignore invalid encoding. if (!id) continue; @@ -217,14 +216,14 @@ static void ParseEncodingListSeparatedWithComma( } } -std::wstring GetEncodingDisplayName(std::string encoding_name, +std::wstring GetEncodingDisplayName(std::wstring encoding_name, int category_string_id) { std::wstring category_name = l10n_util::GetString(category_string_id); if (category_string_id != IDS_ENCODING_KOREAN && category_string_id != IDS_ENCODING_THAI) { return l10n_util::GetStringF(IDS_ENCODING_DISPLAY_TEMPLATE, category_name, - UTF8ToWide(encoding_name)); + encoding_name); } return category_name; } @@ -232,7 +231,7 @@ std::wstring GetEncodingDisplayName(std::string encoding_name, } // namespace // Static. -std::string CharacterEncoding::GetCanonicalEncodingNameByCommandId(int id) { +std::wstring CharacterEncoding::GetCanonicalEncodingNameByCommandId(int id) { const IdToCanonicalEncodingNameMapType* map = canonical_encoding_name_map_singleton. GetIdToCanonicalEncodingNameMapData(); @@ -241,7 +240,7 @@ std::string CharacterEncoding::GetCanonicalEncodingNameByCommandId(int id) { IdToCanonicalEncodingNameMapType::const_iterator found_name = map->find(id); if (found_name != map->end()) return found_name->second.first; - return std::string(); + return std::wstring(); } // Static. @@ -266,10 +265,10 @@ int CharacterEncoding::GetSupportCanonicalEncodingCount() { } // Static. -std::string CharacterEncoding::GetCanonicalEncodingNameByIndex(int index) { +std::wstring CharacterEncoding::GetCanonicalEncodingNameByIndex(int index) { if (index < canonical_encoding_names_length) return canonical_encoding_names[index].name; - return std::string(); + return std::wstring(); } // Static. @@ -282,8 +281,8 @@ std::wstring CharacterEncoding::GetCanonicalEncodingDisplayNameByIndex( } // Static. -std::string CharacterEncoding::GetCanonicalEncodingNameByAliasName( - const std::string& alias_name) { +std::wstring CharacterEncoding::GetCanonicalEncodingNameByAliasName( + const std::wstring& alias_name) { // If the input alias_name is already canonical encoding name, just return it. const CanonicalEncodingNameToIdMapType* map = canonical_encoding_name_map_singleton. @@ -297,18 +296,19 @@ std::string CharacterEncoding::GetCanonicalEncodingNameByAliasName( UErrorCode error_code = U_ZERO_ERROR; - const char* canonical_name = ucnv_getCanonicalName(alias_name.c_str(), - "MIME", - &error_code); + const char* canonical_name = ucnv_getCanonicalName( + WideToASCII(alias_name).c_str(), "MIME", &error_code); // If failed, then try IANA next. if (U_FAILURE(error_code) || !canonical_name) { error_code = U_ZERO_ERROR; - canonical_name = ucnv_getCanonicalName(alias_name.c_str(), - "IANA", - &error_code); + canonical_name = ucnv_getCanonicalName( + WideToASCII(alias_name).c_str(), "IANA", &error_code); } - return std::string(canonical_name); + if (canonical_name) + return ASCIIToWide(canonical_name); + else + return std::wstring(); } // Static @@ -395,7 +395,7 @@ bool CharacterEncoding::UpdateRecentlySelectdEncoding( int new_selected_encoding_id, std::wstring* selected_encodings) { // Get encoding name. - std::string encoding_name = + std::wstring encoding_name = GetCanonicalEncodingNameByCommandId(new_selected_encoding_id); DCHECK(!encoding_name.empty()); // Check whether the new encoding is in local dependent encodings or original @@ -424,13 +424,12 @@ bool CharacterEncoding::UpdateRecentlySelectdEncoding( if (selected_encoding_list.size() == kUserSelectedEncodingsMaxLength) selected_encoding_list.pop_back(); // Insert new encoding to head of selected encoding list. - selected_encodings->append(UTF8ToWide(encoding_name)); + *selected_encodings = encoding_name; // Generate the string for rest selected encoding list. for (std::vector<int>::const_iterator it = selected_encoding_list.begin(); it != selected_encoding_list.end(); ++it) { selected_encodings->append(1, L','); - selected_encodings->append( - UTF8ToWide(GetCanonicalEncodingNameByCommandId(*it))); + selected_encodings->append(GetCanonicalEncodingNameByCommandId(*it)); } return true; } |