Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2511)

Unified Diff: chrome/browser/spellchecker/spellcheck_custom_dictionary.cc

Issue 11434043: Remove duplicate words from custom spelling dictionary on load (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix unit test Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
index f9e2941406768f9f6d9e0894877cf1689b698893..4510332e59e3032ee7b35bf26f640ff6f3f2885c 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();

Powered by Google App Engine
This is Rietveld 408576698