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) { |