Skip to content

Commit

Permalink
implement custom dicts add/remove
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Apr 3, 2012
1 parent 2c8c88b commit b532992
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class HunspellCustomDictionaries
std::vector<std::string> dictionaries() const;
FilePath dictionaryPath(const std::string& name) const;

Error add(const FilePath& dicPath);
Error remove(const std::string& name);

private:
core::FilePath customDictionariesDir_;
};
Expand Down
24 changes: 24 additions & 0 deletions src/cpp/core/spelling/HunspellCustomDictionaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ FilePath HunspellCustomDictionaries::dictionaryPath(
return customDictionariesDir_.childPath(name + ".dic");
}

Error HunspellCustomDictionaries::add(const FilePath& dicPath)
{
// validate .dic extension
if (!dicPath.hasExtensionLowerCase(".dic"))
{
return systemError(boost::system::errc::invalid_argument,
ERROR_LOCATION);
}

// remove existing with same name
std::string name = dicPath.stem();
Error error = remove(name);
if (error)
LOG_ERROR(error);

// add it
return dicPath.copy(dictionaryPath(name));
}

Error HunspellCustomDictionaries::remove(const std::string& name)
{
return dictionaryPath(name).removeIfExists();
}


} // namespace spelling
} // namespace core

0 comments on commit b532992

Please sign in to comment.