summaryrefslogtreecommitdiffstats
path: root/chrome/browser/spellchecker
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/spellchecker')
-rw-r--r--chrome/browser/spellchecker/spellcheck_custom_dictionary.cc22
-rw-r--r--chrome/browser/spellchecker/spellcheck_custom_dictionary.h5
-rw-r--r--chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc3
3 files changed, 27 insertions, 3 deletions
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
index f9e29414..4510332 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
@@ -57,9 +57,27 @@ void SpellcheckCustomDictionary::LoadDictionaryIntoCustomWordList(
}
base::SplitString(contents, '\n', custom_words);
+
+ // Erase duplicates.
+ std::sort(custom_words->begin(), custom_words->end());
+ custom_words->erase(std::unique(custom_words->begin(), custom_words->end()),
+ custom_words->end());
+
// Clear out empty words.
custom_words->erase(remove_if(custom_words->begin(), custom_words->end(),
mem_fun_ref(&std::string::empty)), custom_words->end());
+
+ // Write out the clean file.
+ std::stringstream ss;
+ for (WordList::iterator it = custom_words->begin();
+ it != custom_words->end();
+ ++it) {
+ ss << *it << '\n';
+ }
+ contents = ss.str();
+ file_util::WriteFile(custom_dictionary_path_,
+ contents.c_str(),
+ contents.length());
}
void SpellcheckCustomDictionary::SetCustomWordList(WordList* custom_words) {
@@ -170,8 +188,8 @@ void SpellcheckCustomDictionary::EraseWordFromCustomDictionary(
WordList custom_words;
LoadDictionaryIntoCustomWordList(&custom_words);
- char empty[] = {'\0'};
- char separator[] = {'\n', '\0'};
+ const char empty[] = {'\0'};
+ const char separator[] = {'\n', '\0'};
file_util::WriteFile(custom_dictionary_path_, empty, 0);
for (WordList::iterator it = custom_words.begin();
it != custom_words.end();
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary.h b/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
index 1c244e7..b1d6045 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
@@ -32,6 +32,9 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary {
const chrome::spellcheck_common::WordList& GetWords() const;
+ // Populates the |custom_words| with the list of words in the custom
+ // dictionary file. Makes sure that the custom dictionary file is sorted and
+ // does not have duplicates.
void LoadDictionaryIntoCustomWordList(
chrome::spellcheck_common::WordList* custom_words);
@@ -48,7 +51,7 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary {
void WriteWordToCustomDictionary(const std::string& word);
- // Removes the given word from the custom words list and inform renderer of
+ // Removes the given word from the custom words list and informs renderer of
// the update. Returns false for words that are not in the dictionary.
bool RemoveWord(const std::string& word);
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
index bdbc15e..1073440 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
@@ -102,6 +102,7 @@ TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) {
// The custom word list should include written words.
custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
+ std::sort(expected.begin(), expected.end());
EXPECT_EQ(loaded_custom_words, expected);
// Load in another instance of SpellCheckService.
@@ -151,10 +152,12 @@ TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) {
WordList actual1;
custom_dictionary->LoadDictionaryIntoCustomWordList(&actual1);
+ std::sort(expected1.begin(), expected1.end());
EXPECT_EQ(actual1, expected1);
WordList actual2;
custom_dictionary2->LoadDictionaryIntoCustomWordList(&actual2);
+ std::sort(expected2.begin(), expected2.end());
EXPECT_EQ(actual2, expected2);
// Flush the loop now to prevent service init tasks from being run during