32 #ifndef WRAPPER_ASPELLCHECKER_HPP_ 33 #define WRAPPER_ASPELLCHECKER_HPP_ 38 #include "../Main/Exception.hpp" 76 [[nodiscard]] AspellSpeller *
get();
77 [[nodiscard]]
const AspellSpeller *
getc()
const;
78 [[nodiscard]]
bool valid()
const;
90 [[nodiscard]]
bool check(
91 const std::string& token,
92 std::vector<std::string>& suggestionsTo
123 AspellSpeller * ptr{
nullptr};
177 return this->ptr !=
nullptr;
200 if(!configuration.
valid()) {
202 "AspellChecker::create():" 203 " The configuration is not valid" 207 AspellCanHaveError * possibleError{
208 new_aspell_speller(configuration.
get())
210 const auto errorNumber{
211 aspell_error_number(possibleError)
214 if(errorNumber != 0) {
216 "AspellChecker::create():" 218 + std::to_string(errorNumber)
220 + aspell_error_message(possibleError)
224 this->ptr = to_aspell_speller(possibleError);
255 const std::string& token,
256 std::vector<std::string>& suggestionsTo
258 if(this->ptr ==
nullptr) {
260 "AspellChecker::check():" 261 " The spell checker is not valid" 266 aspell_speller_check(this->ptr, token.c_str(), token.size())
271 "AspellChecker::check():" 273 + std::to_string(aspell_speller_error_number(this->ptr))
275 + aspell_speller_error_message(this->ptr)
283 AspellList suggestions(aspell_speller_suggest(this->ptr, token.c_str(), token.size()));
284 std::string suggestion;
286 while(suggestions.
next(suggestion)) {
287 suggestionsTo.emplace_back(suggestion);
299 if(this->ptr !=
nullptr) {
300 delete_aspell_speller(this->ptr);
353 this->ptr = other.ptr;
::AspellConfig * get()
Gets a pointer to the underlying configuration.
Definition: AspellConfig.hpp:141
bool valid() const
Gets whether the configuration is valid.
Definition: AspellConfig.hpp:163
void clear()
Deletes the spell checker, if necessary.
Definition: AspellChecker.hpp:298
RAII wrapper for aspell configurations.
Definition: AspellConfig.hpp:58
bool valid() const
Gets whether the spell checker is valid.
Definition: AspellChecker.hpp:176
#define MAIN_EXCEPTION_CLASS()
Macro used to easily define classes for general exceptions.
Definition: Exception.hpp:50
RAII wrapper for aspell spell checkers.
Definition: AspellChecker.hpp:62
virtual ~AspellChecker()
Destructor deleting the spell checker, if necessary.
Definition: AspellChecker.hpp:138
Class for aspell spell checker-specific exceptions.
Definition: AspellChecker.hpp:119
AspellChecker()=default
Default constructor.
Namespace for RAII wrappers and Wrapper::Database.
Definition: Database.hpp:109
RAII wrapper for aspell word lists.
Definition: AspellList.hpp:56
AspellSpeller * get()
Gets a pointer to the underlying spell checker.
Definition: AspellChecker.hpp:154
AspellChecker & operator=(AspellChecker &)=delete
Deleted copy assignment operator.
void create(AspellConfig &configuration)
Creates the spell checker.
Definition: AspellChecker.hpp:197
bool check(const std::string &token, std::vector< std::string > &suggestionsTo)
Checks whether a token is correctly spelled.
Definition: AspellChecker.hpp:254
bool next(std::string &nextTo)
Checks for the next list element.
Definition: AspellList.hpp:161
const AspellSpeller * getc() const
Gets a constant pointer to the underlying spell checker.
Definition: AspellChecker.hpp:167