Commit 1829837c authored by sidchat@google.com's avatar sidchat@google.com

Change the use of typedef Language in Spell Check files back to std::string....

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
parent 700d3d58
......@@ -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))
......
......@@ -79,7 +79,7 @@ static const struct {
}
void SpellChecker::SpellCheckLanguages(Languages* languages) {
void SpellChecker::SpellCheckLanguages(std::vector<std::string>* 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<std::string>* 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<std::string> accept_languages;
SplitString(WideToASCII(accept_languages_pref.GetValue()), ',',
&accept_languages);
for (Languages::const_iterator i = accept_languages.begin();
for (std::vector<std::string>::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),
......
......@@ -42,10 +42,6 @@ class MemoryMappedFile;
// deleted on the I/O thread itself.
class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> {
public:
// ASCII string representing a language and/or region, e.g. "en-US".
typedef std::string Language;
typedef std::vector<Language> 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<SpellChecker> {
// 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<SpellChecker> {
void AddWord(const std::wstring& word);
// Get SpellChecker supported languages.
static void SpellCheckLanguages(Languages* languages);
static void SpellCheckLanguages(std::vector<std::string>* 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<SpellChecker> {
// has some dependencies in l10n util that need porting first.
static int GetSpellCheckLanguages(
Profile* profile,
Languages* languages);
std::vector<std::string>* 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<SpellChecker> {
// 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_;
......
......@@ -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<Language> Languages;
static const int kMaxSuggestions = 5; // Max number of dictionary suggestions.
static const int kMaxAutoCorrectWordSize = 8;
......
......@@ -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) {
......
......@@ -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];
}
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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<std::string> 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<std::string> 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<std::string> languages;
SpellChecker::GetSpellCheckLanguages(profile_, &languages);
if (language_number < languages.size()) {
StringPrefMember dictionary_language;
......
......@@ -646,7 +646,7 @@ void LanguagesPageView::InitControlLayout() {
enable_spellchecking_checkbox_->SetMultiLine(true);
// Determine Locale Codes.
SpellChecker::Languages spell_check_languages;
std::vector<std::string> spell_check_languages;
SpellChecker::SpellCheckLanguages(&spell_check_languages);
dictionary_language_model_.reset(new LanguageComboboxModel(profile(),
spell_check_languages));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment