/* AspellWrapperClass.hpp C++ STL compatible wrapper class for aspell api. http://aspell.net Version 0.1 We need a single library: libaspell.so We need a single include file: aspell.h David McCombs davidmc@w3sys.com This code is free use and extend as you see fit. http://www.w3sys.com */ #ifndef ASPELLWRAPPERCLASS_HPP #define ASPELLWRAPPERCLASS_HPP #include "aspell.h" #include #include using namespace std; typedef vector alternatives; class AspellWrapper { private: AspellConfig * config; AspellSpeller * speller; public: int rc; string error; alternatives suggestions; public: AspellWrapper( string lang, string size="", string encoding="", string jargon="", string prime_dictionary="", string personal_dictionary="" ):config(0),speller(0),rc(0) { AspellCanHaveError * ret = 0; config = new_aspell_config(); aspell_config_replace(config, "lang", lang.c_str()); // opt how many words to return if(size.length() ) { aspell_config_replace(config, "size", size.c_str()); } // need to add config for other options // create the aspeller ret = new_aspell_speller(config); // set error if any const struct AspellError * arc = aspell_error((const AspellCanHaveError *)ret); if( rc != 0) { error = aspell_error_message(ret); delete_aspell_can_have_error(ret); } // delete configurer delete_aspell_config(config); // make aspell instance speller = to_aspell_speller(ret); } bool checkWord( string word ) { int have = 0; if(speller) have = aspell_speller_check(speller, word.c_str(), -1); // -1 means null terminated string return have==1; } alternatives & suggestWords( string word ) { suggestions.clear(); if(speller) { const AspellWordList *wl = aspell_speller_suggest(speller,word.c_str(),-1); AspellStringEnumeration * els = aspell_word_list_elements(wl); if( els ) { const char * chWord; while ( (chWord = aspell_string_enumeration_next(els)) != 0) { string strWord = chWord; suggestions.push_back(strWord); } delete_aspell_string_enumeration(els); } } return suggestions; } ~AspellWrapper() { if(speller) delete_aspell_speller(speller); } }; #endif