From 1829837c05b277ec0efbdb6ceda25d9fa4ebfd46 Mon Sep 17 00:00:00 2001 From: "sidchat@google.com" Date: Tue, 7 Jul 2009 17:41:14 +0000 Subject: Change the use of typedef Language in Spell Check files back to std::string. It is unnecessary, and is conflicting with enum Language definition for compact language detection library. BUG=none TEST=none Review URL: http://codereview.chromium.org/150139 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20042 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/spellcheck_worditerator.cc | 3 +- chrome/browser/spellchecker.cc | 45 ++++++++++++---------- chrome/browser/spellchecker.h | 19 ++++----- chrome/browser/spellchecker_common.h | 3 -- chrome/browser/spellchecker_linux.cc | 4 +- chrome/browser/spellchecker_mac.mm | 6 +-- chrome/browser/spellchecker_platform_engine.h | 4 +- chrome/browser/spellchecker_win.cc | 4 +- .../tab_contents/render_view_context_menu.cc | 6 +-- .../browser/views/options/languages_page_view.cc | 2 +- 10 files changed, 46 insertions(+), 50 deletions(-) diff --git a/chrome/browser/spellcheck_worditerator.cc b/chrome/browser/spellcheck_worditerator.cc index 2cbb6af..ab85fb0 100644 --- a/chrome/browser/spellcheck_worditerator.cc +++ b/chrome/browser/spellcheck_worditerator.cc @@ -60,8 +60,7 @@ SpellcheckCharAttribute::~SpellcheckCharAttribute() { // Sets the default language for this object. // This function retrieves the exemplar set to set up the default character // attributes. -void SpellcheckCharAttribute::SetDefaultLanguage( - const SpellChecker::Language& language) { +void SpellcheckCharAttribute::SetDefaultLanguage(const std::string& language) { UErrorCode status = U_ZERO_ERROR; ULocaleData* locale_data = ulocdata_open(language.c_str(), &status); if (U_FAILURE(status)) diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc index ec8aa38..7abab66 100644 --- a/chrome/browser/spellchecker.cc +++ b/chrome/browser/spellchecker.cc @@ -79,7 +79,7 @@ static const struct { } -void SpellChecker::SpellCheckLanguages(Languages* languages) { +void SpellChecker::SpellCheckLanguages(std::vector* languages) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); ++i) languages->push_back(g_supported_spellchecker_languages[i].language); @@ -87,44 +87,47 @@ void SpellChecker::SpellCheckLanguages(Languages* languages) { // This function returns the language-region version of language name. // e.g. returns hi-IN for hi. -SpellChecker::Language SpellChecker::GetSpellCheckLanguageRegion( - Language input_language) { +std::string SpellChecker::GetSpellCheckLanguageRegion( + std::string input_language) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); ++i) { - Language language(g_supported_spellchecker_languages[i].language); + std::string language( + g_supported_spellchecker_languages[i].language); if (language == input_language) - return Language(g_supported_spellchecker_languages[i].language_region); + return std::string( + g_supported_spellchecker_languages[i].language_region); } return input_language; } -SpellChecker::Language SpellChecker::GetLanguageFromLanguageRegion( - Language input_language) { +std::string SpellChecker::GetLanguageFromLanguageRegion( + std::string input_language) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); ++i) { - Language language(g_supported_spellchecker_languages[i].language_region); + std::string language( + g_supported_spellchecker_languages[i].language_region); if (language == input_language) - return Language(g_supported_spellchecker_languages[i].language); + return std::string(g_supported_spellchecker_languages[i].language); } return input_language; } -SpellChecker::Language SpellChecker::GetCorrespondingSpellCheckLanguage( - const Language& language) { +std::string SpellChecker::GetCorrespondingSpellCheckLanguage( + const std::string& language) { // Look for exact match in the Spell Check language list. for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); ++i) { // First look for exact match in the language region of the list. - Language spellcheck_language( + std::string spellcheck_language( g_supported_spellchecker_languages[i].language); if (spellcheck_language == language) return language; // Next, look for exact match in the language_region part of the list. - Language spellcheck_language_region( + std::string spellcheck_language_region( g_supported_spellchecker_languages[i].language_region); if (spellcheck_language_region == language) return g_supported_spellchecker_languages[i].language; @@ -137,10 +140,10 @@ SpellChecker::Language SpellChecker::GetCorrespondingSpellCheckLanguage( // 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part // locale ids with a script code in the middle, yet. // TODO(jungshik): Add a better fallback. - Language language_part(language, 0, language.find('-')); + std::string language_part(language, 0, language.find('-')); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); ++i) { - Language spellcheck_language( + std::string spellcheck_language( g_supported_spellchecker_languages[i].language_region); if (spellcheck_language.substr(0, spellcheck_language.find('-')) == language_part) @@ -148,12 +151,12 @@ SpellChecker::Language SpellChecker::GetCorrespondingSpellCheckLanguage( } // No match found - return blank. - return Language(); + return std::string(); } int SpellChecker::GetSpellCheckLanguages( Profile* profile, - Languages* languages) { + std::vector* languages) { StringPrefMember accept_languages_pref; StringPrefMember dictionary_language_pref; accept_languages_pref.Init(prefs::kAcceptLanguages, profile->GetPrefs(), @@ -168,10 +171,10 @@ int SpellChecker::GetSpellCheckLanguages( // Now scan through the list of accept languages, and find possible mappings // from this list to the existing list of spell check languages. - Languages accept_languages; + std::vector accept_languages; SplitString(WideToASCII(accept_languages_pref.GetValue()), ',', &accept_languages); - for (Languages::const_iterator i = accept_languages.begin(); + for (std::vector::const_iterator i = accept_languages.begin(); i != accept_languages.end(); ++i) { std::string language = GetCorrespondingSpellCheckLanguage(*i); if (!language.empty() && @@ -331,7 +334,7 @@ void SpellChecker::set_file_is_downloading(bool value) { // This part of the code is used for spell checking. // ################################################################ -FilePath SpellChecker::GetVersionedFileName(const Language& input_language, +FilePath SpellChecker::GetVersionedFileName(const std::string& input_language, const FilePath& dict_dir) { // The default dictionary version is 1-2. These versions have been augmented // with additional words found by the translation team. @@ -380,7 +383,7 @@ FilePath SpellChecker::GetVersionedFileName(const Language& input_language, } SpellChecker::SpellChecker(const FilePath& dict_dir, - const Language& language, + const std::string& language, URLRequestContext* request_context, const FilePath& custom_dictionary_file_name) : custom_dictionary_file_name_(custom_dictionary_file_name), diff --git a/chrome/browser/spellchecker.h b/chrome/browser/spellchecker.h index 40ba3f3..cfb7979 100644 --- a/chrome/browser/spellchecker.h +++ b/chrome/browser/spellchecker.h @@ -42,10 +42,6 @@ class MemoryMappedFile; // deleted on the I/O thread itself. class SpellChecker : public base::RefCountedThreadSafe { public: - // ASCII string representing a language and/or region, e.g. "en-US". - typedef std::string Language; - typedef std::vector Languages; - // Creates the spellchecker by reading dictionaries from the given directory, // and defaulting to the given language. Both strings must be provided. // @@ -55,7 +51,7 @@ class SpellChecker : public base::RefCountedThreadSafe { // can figure out the custom dictionary file. It is non empty only for unit // testing. SpellChecker(const FilePath& dict_dir, - const Language& language, + const std::string& language, URLRequestContext* request_context, const FilePath& custom_dictionary_file_name); @@ -92,7 +88,7 @@ class SpellChecker : public base::RefCountedThreadSafe { void AddWord(const std::wstring& word); // Get SpellChecker supported languages. - static void SpellCheckLanguages(Languages* languages); + static void SpellCheckLanguages(std::vector* languages); // This function computes a vector of strings which are to be displayed in // the context menu over a text area for changing spell check languages. It @@ -101,16 +97,16 @@ class SpellChecker : public base::RefCountedThreadSafe { // has some dependencies in l10n util that need porting first. static int GetSpellCheckLanguages( Profile* profile, - Languages* languages); + std::vector* languages); // This function returns the corresponding language-region code for the // spell check language. For example, for hi, it returns hi-IN. - static Language GetSpellCheckLanguageRegion(Language input_language); + static std::string GetSpellCheckLanguageRegion(std::string input_language); // This function returns ll (language code) from ll-RR where 'RR' (region // code) is redundant. However, if the region code matters, it's preserved. // That is, it returns 'hi' and 'en-GB' for 'hi-IN' and 'en-GB' respectively. - static Language GetLanguageFromLanguageRegion(Language input_language); + static std::string GetLanguageFromLanguageRegion(std::string input_language); private: @@ -145,10 +141,11 @@ class SpellChecker : public base::RefCountedThreadSafe { // Return the file name of the dictionary, including the path and the version // numbers. - FilePath GetVersionedFileName(const Language& language, + FilePath GetVersionedFileName(const std::string& language, const FilePath& dict_dir); - static Language GetCorrespondingSpellCheckLanguage(const Language& language); + static std::string GetCorrespondingSpellCheckLanguage( + const std::string& language); // Path to the spellchecker file. FilePath bdict_file_name_; diff --git a/chrome/browser/spellchecker_common.h b/chrome/browser/spellchecker_common.h index a64b724..4d393ab 100644 --- a/chrome/browser/spellchecker_common.h +++ b/chrome/browser/spellchecker_common.h @@ -11,9 +11,6 @@ // Some constants and typedefs that are common to all spellchecker // files/classes/backends/platforms/whatever. -typedef std::string Language; -typedef std::vector Languages; - static const int kMaxSuggestions = 5; // Max number of dictionary suggestions. static const int kMaxAutoCorrectWordSize = 8; diff --git a/chrome/browser/spellchecker_linux.cc b/chrome/browser/spellchecker_linux.cc index 25fcbff..086e627 100644 --- a/chrome/browser/spellchecker_linux.cc +++ b/chrome/browser/spellchecker_linux.cc @@ -16,14 +16,14 @@ bool SpellCheckerAvailable() { } // The following methods are just stubs to keep the linker happy. -bool PlatformSupportsLanguage(const Language& current_language) { +bool PlatformSupportsLanguage(const std::string& current_language) { return false; } void Init() { } -void SetLanguage(const Language& lang_to_set) { +void SetLanguage(const std::string& lang_to_set) { } bool CheckSpelling(const std::string& word_to_check) { diff --git a/chrome/browser/spellchecker_mac.mm b/chrome/browser/spellchecker_mac.mm index 81aa9e3..bcb6db1 100644 --- a/chrome/browser/spellchecker_mac.mm +++ b/chrome/browser/spellchecker_mac.mm @@ -20,7 +20,7 @@ const unsigned int kShortLanguageCodeSize = 2; // A private utility function to convert hunspell language codes to os x // language codes. -NSString* ConvertLanguageCodeToMac(const Language& lang_code) { +NSString* ConvertLanguageCodeToMac(const std::string& lang_code) { NSString* whole_code = base::SysUTF8ToNSString(lang_code); if ([whole_code length] > kShortLanguageCodeSize) { @@ -69,7 +69,7 @@ void Init() { [NSApplication sharedApplication]; } -bool PlatformSupportsLanguage(const Language& current_language) { +bool PlatformSupportsLanguage(const std::string& current_language) { // First, convert Language to an osx lang code NSString. NSString* mac_lang_code = ConvertLanguageCodeToMac(current_language); @@ -82,7 +82,7 @@ bool PlatformSupportsLanguage(const Language& current_language) { return [availableLanguages containsObject:mac_lang_code]; } -void SetLanguage(const Language& lang_to_set) { +void SetLanguage(const std::string& lang_to_set) { NSString* NS_lang_to_set = ConvertLanguageCodeToMac(lang_to_set); [[NSSpellChecker sharedSpellChecker] setLanguage:NS_lang_to_set]; } diff --git a/chrome/browser/spellchecker_platform_engine.h b/chrome/browser/spellchecker_platform_engine.h index 74a409a..b73253a 100644 --- a/chrome/browser/spellchecker_platform_engine.h +++ b/chrome/browser/spellchecker_platform_engine.h @@ -24,9 +24,9 @@ void Init(); // and checks the given language agains the languages that the current system // supports. If the platform-specific spellchecker supports the language, // then returns true, otherwise false. -bool PlatformSupportsLanguage(const Language& current_language); +bool PlatformSupportsLanguage(const std::string& current_language); // Sets the language for the platform-specific spellchecker. -void SetLanguage(const Language& lang_to_set); +void SetLanguage(const std::string& lang_to_set); // Checks the spelling of the given string, using the platform-specific // spellchecker. Returns true if the word is spelled correctly. bool CheckSpelling(const std::string& word_to_check); diff --git a/chrome/browser/spellchecker_win.cc b/chrome/browser/spellchecker_win.cc index 2632ee6..d553b02 100644 --- a/chrome/browser/spellchecker_win.cc +++ b/chrome/browser/spellchecker_win.cc @@ -16,14 +16,14 @@ bool SpellCheckerAvailable() { } // The following methods are just stubs to keep the linker happy. -bool PlatformSupportsLanguage(const Language& current_language) { +bool PlatformSupportsLanguage(const std::string& current_language) { return false; } void Init() { } -void SetLanguage(const Language& lang_to_set) { +void SetLanguage(const std::string& lang_to_set) { } bool CheckSpelling(const std::string& word_to_check) { diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index a32c557..855f23c 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -182,7 +182,7 @@ void RenderViewContextMenu::AppendEditableItems() { l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU)); // Add Spell Check languages to sub menu. - SpellChecker::Languages spellcheck_languages; + std::vector spellcheck_languages; SpellChecker::GetSpellCheckLanguages(profile_, &spellcheck_languages); DCHECK(spellcheck_languages.size() < @@ -336,7 +336,7 @@ bool RenderViewContextMenu::ItemIsChecked(int id) const { (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) return false; - SpellChecker::Languages languages; + std::vector languages; return SpellChecker::GetSpellCheckLanguages(profile_, &languages) == (id - IDC_SPELLCHECK_LANGUAGES_FIRST); } @@ -346,7 +346,7 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) { if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && id < IDC_SPELLCHECK_LANGUAGES_LAST) { const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST; - SpellChecker::Languages languages; + std::vector languages; SpellChecker::GetSpellCheckLanguages(profile_, &languages); if (language_number < languages.size()) { StringPrefMember dictionary_language; diff --git a/chrome/browser/views/options/languages_page_view.cc b/chrome/browser/views/options/languages_page_view.cc index 5ed8587..207142d 100644 --- a/chrome/browser/views/options/languages_page_view.cc +++ b/chrome/browser/views/options/languages_page_view.cc @@ -646,7 +646,7 @@ void LanguagesPageView::InitControlLayout() { enable_spellchecking_checkbox_->SetMultiLine(true); // Determine Locale Codes. - SpellChecker::Languages spell_check_languages; + std::vector spell_check_languages; SpellChecker::SpellCheckLanguages(&spell_check_languages); dictionary_language_model_.reset(new LanguageComboboxModel(profile(), spell_check_languages)); -- cgit v1.1