Fix error when adding a word to the dictionary when the user dictionary file doesn't already exist

Originally committed to SVN as r6381.
This commit is contained in:
Thomas Goyne 2012-01-27 20:03:55 +00:00
parent bc9c521cfd
commit 78f1198426

View file

@ -92,12 +92,17 @@ void HunspellSpellChecker::AddWord(wxString word) {
} }
// Read the old contents of the user's dictionary // Read the old contents of the user's dictionary
else { else {
std::auto_ptr<std::istream> stream(agi::io::Open(STD_STR(userDicPath))); try {
std::remove_copy_if( agi::scoped_ptr<std::istream> stream(agi::io::Open(STD_STR(userDicPath)));
remove_copy_if(
++agi::line_iterator<std::string>(*stream.get()), ++agi::line_iterator<std::string>(*stream.get()),
agi::line_iterator<std::string>(), agi::line_iterator<std::string>(),
std::back_inserter(words), back_inserter(words),
std::mem_fun_ref(&std::string::empty)); mem_fun_ref(&std::string::empty));
}
catch (agi::FileNotFoundError&) {
LOG_I("dictionary/hunspell/add") << "User dictionary not found; creating it";
}
} }
// Add the word // Add the word
@ -105,14 +110,9 @@ void HunspellSpellChecker::AddWord(wxString word) {
words.sort(); words.sort();
// Write the new dictionary // Write the new dictionary
try {
agi::io::Save writer(STD_STR(userDicPath)); agi::io::Save writer(STD_STR(userDicPath));
writer.Get() << words.size() << "\n"; writer.Get() << words.size() << "\n";
std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(writer.Get(), "\n")); copy(words.begin(), words.end(), std::ostream_iterator<std::string>(writer.Get(), "\n"));
}
catch (const agi::Exception&) {
// Failed to open file
}
} }
bool HunspellSpellChecker::CheckWord(wxString word) { bool HunspellSpellChecker::CheckWord(wxString word) {