Scribus
Open source desktop publishing at your fingertips
suggest.h
1 /*
2  For general Scribus (>=1.3.2) copyright and licensing information
3  please refer to the COPYING file provided with the
4  program. Following this notice may exist a copyright and/or license
5  notice that predates the release of Scribus 1.3.2 for which a new
6  license (GPL+exception) is in place.
7 */
8 #ifndef SUGGEST_H
9 #define SUGGEST_H
10 
11 // ISO C++ include files
12 #include <sstream> // For formatting aspell dictionary entries
13 #include <stdexcept> // For exceptions
14 #include <string> // Used in function arguments, errors
15 #include <vector> // Used in function arguments
16 #include <iostream> // Printing to std::cout
17 // aspell include files
18 #include <aspell.h>
19 
23 namespace Speller {
24  namespace Aspell {
31  class Suggest {
32  private:
34  AspellConfig* fconfig;
36  AspellSpeller* fspeller;
38  std::string flang;
40  std::string fjargon;
42  std::string fencoding;
43 
51  void checkError() throw( std::runtime_error );
59  void checkConfigError() throw( std::runtime_error );
70  void init(const std::string& lang, const std::string& jargon,
71  const std::string& encoding)
72  throw( std::invalid_argument, std::runtime_error );
81  void printWordList(const AspellWordList* wlist,
82  char delim='\n') throw(std::invalid_argument);
90  void setConfig() throw( std::invalid_argument );
99  void storeWordList(const AspellWordList* wlist,
100  std::vector<std::string>& replacement)
101  throw( std::invalid_argument );
102 
103  public:
107  static const char* kDICT_DELIM;
111  static const char* kEMPTY;
113  static const char* kDEF_LANG;
115  static const char* kDEF_JARGON;
117  static const char* kDEF_ENCODING;
118 
119  // Defaults are for standard aspell English dictionary. Use
120  // "iso8859-1" for Basic Latin. See aspell lang.dat file for
121  // actual encoding used for a given dictionary.
132  Suggest(const std::string& lang=kDEF_LANG,
133  const std::string& jargon=kDEF_JARGON,
134  const std::string& encoding=kDEF_ENCODING)
135  throw( std::invalid_argument, std::runtime_error );
145  Suggest(const AspellDictInfo* dinfo,
146  const std::string& encoding=kDEF_ENCODING)
147  throw( std::invalid_argument, std::runtime_error );
155  void addPersonalList(const std::string& word)
156  throw( std::runtime_error );
163  bool checkWord(const std::string& word);
171  bool checkWord(const std::string& word,
172  std::vector<std::string>& replacement,
173  bool always=true) throw( std::invalid_argument );
181  void clearSessionList() throw( std::runtime_error );
188  std::string getConfigOpt(const std::string& opt);
196  void getConfigOpt(const std::string& opt,
197  std::vector<std::string>& vals);
205  void ignoreWord(const std::string& word)
206  throw( std::runtime_error );
213  void listDicts(std::vector<AspellDictInfo>& vals);
220  void listDicts(std::vector<std::string>& vals);
228  void printMainList() throw( std::invalid_argument );
236  void printPersonalList() throw( std::invalid_argument );
244  void printSessionList() throw( std::invalid_argument );
253  bool printSuggestions(const std::string& word, bool always=true)
254  throw( std::invalid_argument );
263  void resetConfig()
264  throw( std::invalid_argument, std::runtime_error );
275  void resetConfig(const std::string& lang,
276  const std::string& jargon,
277  const std::string& encoding=kDEF_ENCODING)
278  throw( std::invalid_argument, std::runtime_error );
286  void saveLists() throw( std::runtime_error );
295  void setConfigOpt(const std::string& opt, const std::string& val)
296  throw( std::invalid_argument );
304  void StoreMainList(std::vector<std::string>& replacement)
305  throw( std::invalid_argument );
313  void StorePersonalList(std::vector<std::string>& replacement)
314  throw( std::invalid_argument );
322  void StoreSessionList(std::vector<std::string>& replacement)
323  throw( std::invalid_argument );
324  }; // class Suggest
325  } // namespace Aspell
326 } // namespace Speller
327 #endif // #ifndef SUGGEST_H
328 //@@@@@@@@@@@@@@@@@@@@@@@@@ END OF FILE @@@@@@@@@@@@@@@@@@@@@@@@@
bool checkWord(const std::string &word)
Spell-checks 'word'.
Definition: suggest.cpp:247
void StoreSessionList(std::vector< std::string > &replacement)
Stores session word list.
Definition: suggest.cpp:563
void printPersonalList()
Prints personal word list.
Definition: suggest.cpp:372
static const char * kDEF_ENCODING
Default character encoding for words.
Definition: suggest.h:117
Suggest(const std::string &lang=kDEF_LANG, const std::string &jargon=kDEF_JARGON, const std::string &encoding=kDEF_ENCODING)
Default constructor for spell-checking class.
Definition: suggest.cpp:190
Definition: path.h:799
void addPersonalList(const std::string &word)
Adds 'word' to personal list.
Definition: suggest.cpp:228
void clearSessionList()
Clears the current session word list.
Definition: suggest.cpp:304
void ignoreWord(const std::string &word)
Ignores 'word' for current session.
Definition: suggest.cpp:342
void listDicts(std::vector< AspellDictInfo > &vals)
Obtains list of available aspell dictionaries.
Definition: suggest.cpp:86
void StoreMainList(std::vector< std::string > &replacement)
Stores main word list. WARNING: This causes a crash due to a bug in aspell, as of aspell version 0...
Definition: suggest.cpp:532
Class for interfacing with aspell. Should work with any aspell version from 0.60 onwards.
Definition: suggest.h:31
static const char * kDEF_LANG
Default language for aspell dictionary.
Definition: suggest.h:113
Nested namespaces to allow different interfaces to different spell-checking engines.
Definition: suggest.h:23
static const char * kEMPTY
Used in place of an empty string for an aspell setting (currently, only jargon might be empty)...
Definition: suggest.h:111
void printSessionList()
Prints session word list.
Definition: suggest.cpp:387
void setConfigOpt(const std::string &opt, const std::string &val)
Sets configuration option, 'opt' to value 'val'.
Definition: suggest.cpp:516
static const char * kDICT_DELIM
Delimiter between different components of formatted strings for aspell dictionary entries...
Definition: suggest.h:107
void resetConfig()
Resets aspell configuration, as per current set of parameters.
Definition: suggest.cpp:446
static const char * kDEF_JARGON
Default jargon for aspell dictionary.
Definition: suggest.h:115
bool printSuggestions(const std::string &word, bool always=true)
Spell-checks word, and prints suggested replacements.
Definition: suggest.cpp:402
void printMainList()
Prints main word list. WARNING: This causes a crash due to a bug in aspell, as of aspell version 0...
Definition: suggest.cpp:358
void saveLists()
Saves all word lists.
Definition: suggest.cpp:502
void StorePersonalList(std::vector< std::string > &replacement)
Stores personal word list.
Definition: suggest.cpp:547
std::string getConfigOpt(const std::string &opt)
Gets value of configuration option, 'opt'.
Definition: suggest.cpp:317