diff options
author | jnd@google.com <jnd@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-21 02:58:09 +0000 |
---|---|---|
committer | jnd@google.com <jnd@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-21 02:58:09 +0000 |
commit | 1a3ebe10ead2ca99d2beb45b9ec65a2863406184 (patch) | |
tree | b1c8b11cc0a32e1f561362ecee1b488bf7d91b15 /chrome/browser/character_encoding.cc | |
parent | aef050626d6412bffa292cbfcee23107cadc4b5d (diff) | |
download | chromium_src-1a3ebe10ead2ca99d2beb45b9ec65a2863406184.zip chromium_src-1a3ebe10ead2ca99d2beb45b9ec65a2863406184.tar.gz chromium_src-1a3ebe10ead2ca99d2beb45b9ec65a2863406184.tar.bz2 |
As Brett pointed it out, We normally use 8-bit for encoding names since they're always ASCII. Plus, wstrings will also be 32-bit characters on Linux and Mac, which is expensive. So I make this CL by using std::string instead of std::wstring every time you have an encoding name.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/character_encoding.cc')
-rw-r--r-- | chrome/browser/character_encoding.cc | 123 |
1 files changed, 62 insertions, 61 deletions
diff --git a/chrome/browser/character_encoding.cc b/chrome/browser/character_encoding.cc index 9e4404c..79cbc28 100644 --- a/chrome/browser/character_encoding.cc +++ b/chrome/browser/character_encoding.cc @@ -49,56 +49,56 @@ const int kUserSelectedEncodingsMaxLength = 3; typedef struct { int resource_id; - const wchar_t* name; + const char* name; int category_string_id; } CanonicalEncodingData; // An array of all supported canonical encoding names. static CanonicalEncodingData canonical_encoding_names[] = { - { 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 }, + { 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 }, }; static const int canonical_encoding_names_length = arraysize(canonical_encoding_names); -typedef std::map<int, std::pair<const wchar_t*, int> > IdToCanonicalEncodingNameMapType; -typedef std::map<const std::wstring, int> CanonicalEncodingNameToIdMapType; +typedef std::map<int, std::pair<const char*, int> > IdToCanonicalEncodingNameMapType; +typedef std::map<const std::string, int> CanonicalEncodingNameToIdMapType; class CanonicalEncodingMap { public: @@ -159,7 +159,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::wstring& encoding_name) { + const std::string& encoding_name) { const CanonicalEncodingNameToIdMapType* map = canonical_encoding_name_map_singleton. GetCanonicalEncodingNameToIdMapData(); @@ -231,7 +231,8 @@ static void ParseEncodingListSeparatedWithComma( size_t maximum_size) { WStringTokenizer tokenizer(encoding_list, L","); while (tokenizer.GetNext()) { - int id = GetCommandIdByCanonicalEncodingName(tokenizer.token()); + std::string valid_encoding = WideToUTF8(tokenizer.token()); + int id = GetCommandIdByCanonicalEncodingName(valid_encoding); // Ignore invalid encoding. if (!id) continue; @@ -241,14 +242,14 @@ static void ParseEncodingListSeparatedWithComma( } } -std::wstring GetEncodingDisplayName(std::wstring encoding_name, +std::wstring GetEncodingDisplayName(std::string 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, - encoding_name); + UTF8ToWide(encoding_name)); } return category_name; } @@ -256,7 +257,7 @@ std::wstring GetEncodingDisplayName(std::wstring encoding_name, } // namespace // Static. -std::wstring CharacterEncoding::GetCanonicalEncodingNameByCommandId(int id) { +std::string CharacterEncoding::GetCanonicalEncodingNameByCommandId(int id) { const IdToCanonicalEncodingNameMapType* map = canonical_encoding_name_map_singleton. GetIdToCanonicalEncodingNameMapData(); @@ -265,7 +266,7 @@ std::wstring CharacterEncoding::GetCanonicalEncodingNameByCommandId(int id) { IdToCanonicalEncodingNameMapType::const_iterator found_name = map->find(id); if (found_name != map->end()) return found_name->second.first; - return std::wstring(); + return std::string(); } // Static. @@ -290,10 +291,10 @@ int CharacterEncoding::GetSupportCanonicalEncodingCount() { } // Static. -std::wstring CharacterEncoding::GetCanonicalEncodingNameByIndex(int index) { +std::string CharacterEncoding::GetCanonicalEncodingNameByIndex(int index) { if (index < canonical_encoding_names_length) return canonical_encoding_names[index].name; - return std::wstring(); + return std::string(); } // Static. @@ -306,8 +307,8 @@ std::wstring CharacterEncoding::GetCanonicalEncodingDisplayNameByIndex( } // Static. -std::wstring CharacterEncoding::GetCanonicalEncodingNameByAliasName( - const std::wstring& alias_name) { +std::string CharacterEncoding::GetCanonicalEncodingNameByAliasName( + const std::string& alias_name) { // If the input alias_name is already canonical encoding name, just return it. const CanonicalEncodingNameToIdMapType* map = canonical_encoding_name_map_singleton. @@ -321,19 +322,18 @@ std::wstring CharacterEncoding::GetCanonicalEncodingNameByAliasName( UErrorCode error_code = U_ZERO_ERROR; - const char* canonical_name = ucnv_getCanonicalName( - WideToASCII(alias_name).c_str(), "MIME", &error_code); + const char* canonical_name = ucnv_getCanonicalName(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( - WideToASCII(alias_name).c_str(), "IANA", &error_code); + canonical_name = ucnv_getCanonicalName(alias_name.c_str(), + "IANA", + &error_code); } - if (canonical_name) - return ASCIIToWide(canonical_name); - else - return std::wstring(); + return std::string(canonical_name); } // Static @@ -420,7 +420,7 @@ bool CharacterEncoding::UpdateRecentlySelectdEncoding( int new_selected_encoding_id, std::wstring* selected_encodings) { // Get encoding name. - std::wstring encoding_name = + std::string encoding_name = GetCanonicalEncodingNameByCommandId(new_selected_encoding_id); DCHECK(!encoding_name.empty()); // Check whether the new encoding is in local dependent encodings or original @@ -449,12 +449,13 @@ 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 = encoding_name; + selected_encodings->append(UTF8ToWide(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(GetCanonicalEncodingNameByCommandId(*it)); + selected_encodings->append( + UTF8ToWide(GetCanonicalEncodingNameByCommandId(*it))); } return true; } |