diff options
author | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-28 18:50:55 +0000 |
---|---|---|
committer | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-28 18:50:55 +0000 |
commit | c49d729253e861bff32cb2ac20ccca7156d4f343 (patch) | |
tree | 4716a5b79c2f85361d62d91e1cea78a07d7f7ddc /chrome/browser/spellchecker.cc | |
parent | 124646932219f4cd17a3dc80393485e923deb1ba (diff) | |
download | chromium_src-c49d729253e861bff32cb2ac20ccca7156d4f343.zip chromium_src-c49d729253e861bff32cb2ac20ccca7156d4f343.tar.gz chromium_src-c49d729253e861bff32cb2ac20ccca7156d4f343.tar.bz2 |
Get rid of unnecessary region code from spellcheck language/locale codes. Fix of Linux by using ARRAYSIZE_UNSAFE instead of arraysize.
Issue=Issue=6329
Review URL: http://codereview.chromium.org/18567
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8816 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/spellchecker.cc')
-rw-r--r-- | chrome/browser/spellchecker.cc | 107 |
1 files changed, 65 insertions, 42 deletions
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc index 11147b9..5cd32a6 100644 --- a/chrome/browser/spellchecker.cc +++ b/chrome/browser/spellchecker.cc @@ -34,55 +34,75 @@ using base::TimeTicks; static const int kMaxSuggestions = 5; // Max number of dictionary suggestions. namespace { -const wchar_t* const g_supported_spellchecker_languages[] = { - L"en-US", - L"en-GB", - L"fr-FR", - L"it-IT", - L"de-DE", - L"es-ES", - L"nl-NL", - L"pt-BR", - L"ru-RU", - L"pl-PL", - // L"th-TH", // Not to be included in Spellchecker as per B=1277824 - L"sv-SE", - L"da-DK", - L"pt-PT", - L"ro-RO", - // L"hu-HU", // Not to be included in Spellchecker as per B=1277824 - L"he-IL", - L"id-ID", - L"cs-CZ", - L"el-GR", - L"nb-NO", - L"vi-VN", - // L"bg-BG", // Not to be included in Spellchecker as per B=1277824 - L"hr-HR", - L"lt-LT", - L"sk-SK", - L"sl-SI", - L"ca-ES", - L"lv-LV", - // L"uk-UA", // Not to be included in Spellchecker as per B=1277824 - L"hi-IN", - // - // TODO(Sidchat): Uncomment/remove languages as and when they get resolved. - // +static const struct { + // The language. + const wchar_t* language; + + // The corresponding language and region, used by the dictionaries. + const wchar_t* language_region; +} g_supported_spellchecker_languages[] = { + {L"en-US", L"en-US"}, + {L"en-GB", L"en-GB"}, + {L"fr", L"fr-FR"}, + {L"it", L"it-IT"}, + {L"de", L"de-DE"}, + {L"es", L"es-ES"}, + {L"nl", L"nl-NL"}, + {L"pt-BR", L"pt-BR"}, + {L"ru", L"ru-RU"}, + {L"pl", L"pl-PL"}, + // {L"th", L"th-TH"}, // Not to be included in Spellchecker as per B=1277824 + {L"sv", L"sv-SE"}, + {L"da", L"da-DK"}, + {L"pt-PT", L"pt-PT"}, + {L"ro", L"ro-RO"}, + // {L"hu", L"hu-HU"}, // Not to be included in Spellchecker as per B=1277824 + {L"he", L"he-IL"}, + {L"id", L"id-ID"}, + {L"cs", L"cs-CZ"}, + {L"el", L"el-GR"}, + {L"nb", L"nb-NO"}, + {L"vi", L"vi-VN"}, + // {L"bg", L"bg-BG"}, // Not to be included in Spellchecker as per B=1277824 + {L"hr", L"hr-HR"}, + {L"lt", L"lt-LT"}, + {L"sk", L"sk-SK"}, + {L"sl", L"sl-SI"}, + {L"ca", L"ca-ES"}, + {L"lv", L"lv-LV"}, + // {L"uk", L"uk-UA"}, // Not to be included in Spellchecker as per B=1277824 + {L"hi", L"hi-IN"}, }; } void SpellChecker::SpellCheckLanguages(Languages* languages) { - for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) - languages->push_back(g_supported_spellchecker_languages[i]); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); + ++i) + languages->push_back(g_supported_spellchecker_languages[i].language); +} + +// This function returns the language-region version of language name. +// e.g. returns hi-IN for hi. +SpellChecker::Language SpellChecker::GetSpellCheckLanguageRegion( + Language input_language) { + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); + ++i) { + Language language(g_supported_spellchecker_languages[i].language); + if (language == input_language) + return Language(g_supported_spellchecker_languages[i].language_region); + } + + return input_language; } SpellChecker::Language SpellChecker::GetCorrespondingSpellCheckLanguage( const Language& language) { // Look for exact match in the Spell Check language list. - for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) { - Language spellcheck_language(g_supported_spellchecker_languages[i]); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); + ++i) { + Language spellcheck_language( + g_supported_spellchecker_languages[i].language); if (spellcheck_language == language) return language; } @@ -95,8 +115,10 @@ SpellChecker::Language SpellChecker::GetCorrespondingSpellCheckLanguage( // locale ids with a script code in the middle, yet. // TODO(jungshik): Add a better fallback. Language language_part(language, 0, language.find(L'-')); - for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) { - Language spellcheck_language(g_supported_spellchecker_languages[i]); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); + ++i) { + Language spellcheck_language( + g_supported_spellchecker_languages[i].language_region); if (spellcheck_language.substr(0, spellcheck_language.find(L'-')) == language_part) return spellcheck_language; @@ -301,7 +323,7 @@ void SpellChecker::set_file_is_downloading(bool value) { // This part of the code is used for spell checking. // ################################################################ -std::wstring SpellChecker::GetVersionedFileName(const Language& language, +std::wstring SpellChecker::GetVersionedFileName(const Language& input_language, const std::wstring& dict_dir) { // The default version string currently in use. static const wchar_t kDefaultVersionString[] = L"-1-2"; @@ -331,6 +353,7 @@ std::wstring SpellChecker::GetVersionedFileName(const Language& language, // Generate the bdict file name using default version string or special // version string, depending on the language. + std::wstring language = GetSpellCheckLanguageRegion(input_language); std::wstring versioned_bdict_file_name(language + kDefaultVersionString + L".bdic"); std::string language_string(WideToUTF8(language)); |