/src/aspell/common/speller.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // This file is part of The New Aspell |
2 | | // Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license |
3 | | // version 2.0 or 2.1. You should have received a copy of the LGPL |
4 | | // license along with this library if you did not you can find |
5 | | // it at http://www.gnu.org/. |
6 | | |
7 | | // Aspell implementation header file. |
8 | | // Applications that just use the Aspell library should not include |
9 | | // these files as they are subject to change. |
10 | | // Aspell Modules MUST include some of the implementation files and |
11 | | // spell checkers MAY include some of these files. |
12 | | // If ANY of the implementation files are included you also link with |
13 | | // libaspell-impl to protect you from changes in these files. |
14 | | |
15 | | #ifndef ASPELL_SPELLER__HPP |
16 | | #define ASPELL_SPELLER__HPP |
17 | | |
18 | | #include "can_have_error.hpp" |
19 | | #include "copy_ptr.hpp" |
20 | | #include "clone_ptr.hpp" |
21 | | #include "mutable_string.hpp" |
22 | | #include "posib_err.hpp" |
23 | | #include "parm_string.hpp" |
24 | | #include "char_vector.hpp" |
25 | | |
26 | | namespace acommon { |
27 | | |
28 | | typedef void * SpellerLtHandle; |
29 | | |
30 | | class Config; |
31 | | class WordList; |
32 | | class Convert; |
33 | | class Tokenizer; |
34 | | class Filter; |
35 | | class DocumentChecker; |
36 | | |
37 | | struct CheckInfo { |
38 | | const CheckInfo * next; |
39 | | // note: if 'incorrect' then word is a pointer into the string |
40 | | // passed into check and is not null terminated; |
41 | | // otherwise word is guaranteed to be null termanted |
42 | | struct Word { |
43 | | const char * str; |
44 | | unsigned len; |
45 | 0 | ParmString pstr() const {return ParmString(str, len);} |
46 | 669k | Word() {} |
47 | | Word(const char * str) |
48 | 252k | : str(str), len(strlen(str)) {} |
49 | | Word(const char * str, unsigned len) |
50 | 0 | : str(str), len(len) {} |
51 | | Word(ParmStr str) |
52 | 0 | : str(str.str()), len(str.size()) {} |
53 | | }; |
54 | | Word word; // generally the root |
55 | | short pre_strip_len; |
56 | | short pre_add_len; |
57 | | const char * pre_add; |
58 | | short suf_strip_len; |
59 | | short suf_add_len; |
60 | | const char * suf_add; |
61 | | short pre_flag; |
62 | | short suf_flag; |
63 | | bool guess; |
64 | | bool compound; |
65 | | bool incorrect; |
66 | | }; |
67 | | |
68 | | class Speller : public CanHaveError |
69 | | { |
70 | | private: |
71 | | SpellerLtHandle lt_handle_; |
72 | | Speller(const Speller &); |
73 | | Speller & operator= (const Speller &); |
74 | | public: |
75 | | String temp_str_0; |
76 | | String temp_str_1; |
77 | | ClonePtr<Convert> to_internal_; |
78 | | ClonePtr<Convert> from_internal_; |
79 | | protected: |
80 | | CopyPtr<Config> config_; |
81 | | Speller(SpellerLtHandle h); |
82 | | public: |
83 | 0 | SpellerLtHandle lt_handle() const {return lt_handle_;} |
84 | | |
85 | 4.90k | Config * config() {return config_;} |
86 | 0 | const Config * config() const {return config_;} |
87 | | |
88 | | // utility functions |
89 | | |
90 | | virtual char * to_lower(char *) = 0; |
91 | | |
92 | | // the setup class will take over for config |
93 | | virtual PosibErr<void> setup(Config *) = 0; |
94 | | |
95 | | // sets up the tokenizer class |
96 | | // should be called only after this class is setup |
97 | | virtual void setup_tokenizer(Tokenizer *) = 0; |
98 | | |
99 | | //////////////////////////////////////////////////////////////// |
100 | | // |
101 | | // Strings from this point on are expected to be in the |
102 | | // encoding specified by encoding() |
103 | | // |
104 | | |
105 | | virtual PosibErr<bool> check(MutableString) = 0; |
106 | | |
107 | | // these functions return information about the last word checked |
108 | | virtual const CheckInfo * check_info() = 0; |
109 | | |
110 | | virtual PosibErr<void> add_to_personal(MutableString) = 0; |
111 | | virtual PosibErr<void> add_to_session (MutableString) = 0; |
112 | | |
113 | | // because the word lists may potently have to convert from one |
114 | | // encoding to another the pointer returned by the enumeration is only |
115 | | // valid to the next call. |
116 | | |
117 | | virtual PosibErr<const WordList *> personal_word_list() const = 0; |
118 | | virtual PosibErr<const WordList *> session_word_list () const = 0; |
119 | | virtual PosibErr<const WordList *> main_word_list () const = 0; |
120 | | |
121 | | virtual PosibErr<void> save_all_word_lists() = 0; |
122 | | |
123 | | virtual PosibErr<void> clear_session() = 0; |
124 | | |
125 | | virtual PosibErr<const WordList *> suggest(MutableString) = 0; |
126 | | // return null on error |
127 | | // the word list returned by suggest is only valid until the next |
128 | | // call to suggest |
129 | | |
130 | | virtual PosibErr<void> store_replacement(MutableString, |
131 | | MutableString) = 0; |
132 | | |
133 | | virtual ~Speller(); |
134 | | |
135 | | }; |
136 | | |
137 | | |
138 | | // This function is current a hack to reload the filters in the |
139 | | // speller class. I hope to eventually find a better way. |
140 | | PosibErr<void> reload_filters(Speller * m); |
141 | | |
142 | | |
143 | | PosibErr<Speller *> new_speller(Config * c); |
144 | | |
145 | | } |
146 | | |
147 | | #endif |