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

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: 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..76b87fe6dd96ebb45a083eb52fe4c97160998ec6 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
@@ -57,9 +57,32 @@ void SpellcheckCustomDictionary::LoadDictionaryIntoCustomWordList(
}
base::SplitString(contents, '\n', custom_words);
+
+ // Erase duplicates.
+ std::sort(custom_words->begin(), custom_words->end());
+ WordList::iterator it = std::unique(custom_words->begin(),
+ custom_words->end());
+ custom_words->resize(it - custom_words->begin());
groby-ooo-7-16 2012/11/29 23:35:47 nit: Use custom_words.erase instead - erase(unique
please use gerrit instead 2012/11/29 23:48:03 Done.
+
// 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;
+ std::string word;
+ char separator[] = {'\n', '\0'};
groby-ooo-7-16 2012/11/29 23:35:47 const char
please use gerrit instead 2012/11/29 23:48:03 Done.
+ for (WordList::iterator it = custom_words->begin();
+ it != custom_words->end();
+ ++it) {
+ word = *it;
+ ss.write(word.c_str(), word.length());
groby-ooo-7-16 2012/11/29 23:35:47 ss << *it << separator; // Why not this?
please use gerrit instead 2012/11/29 23:48:03 Done.
+ ss.write(separator, 1);
+ }
+ contents = ss.str();
+ file_util::WriteFile(custom_dictionary_path_,
+ contents.c_str(),
+ contents.length());
}
void SpellcheckCustomDictionary::SetCustomWordList(WordList* custom_words) {

Powered by Google App Engine
This is Rietveld 408576698