19#ifndef NUSPELL_CHECKER_HXX
20#define NUSPELL_CHECKER_HXX
22#include "aff_data.hxx"
25NUSPELL_BEGIN_INLINE_NAMESPACE
34struct Affixing_Result_Base {
35 Word_List::const_pointer root_word = {};
37 operator Word_List::const_pointer()
const {
return root_word; }
38 auto& operator*()
const {
return *root_word; }
39 auto operator->()
const {
return root_word; }
42template <
class T1 =
void,
class T2 =
void>
43struct Affixing_Result : Affixing_Result_Base {
47 Affixing_Result() =
default;
48 Affixing_Result(Word_List::const_reference r,
const T1& a,
const T2& b)
49 : Affixing_Result_Base{&r}, a{&a}, b{&b}
54struct Affixing_Result<T1, void> : Affixing_Result_Base {
57 Affixing_Result() =
default;
58 Affixing_Result(Word_List::const_reference r,
const T1& a)
59 : Affixing_Result_Base{&r}, a{&a}
65struct Affixing_Result<void, void> : Affixing_Result_Base {
66 Affixing_Result() =
default;
67 Affixing_Result(Word_List::const_reference r) : Affixing_Result_Base{&r}
72struct Compounding_Result {
73 Word_List::const_pointer word_entry = {};
74 unsigned char num_words_modifier = {};
75 signed char num_syllable_modifier = {};
76 bool affixed_and_modified = {};
77 operator Word_List::const_pointer()
const {
return word_entry; }
78 auto& operator*()
const {
return *word_entry; }
79 auto operator->()
const {
return word_entry; }
82struct Checker :
public Aff_Data {
83 enum Forceucase :
bool {
84 FORBID_BAD_FORCEUCASE =
false,
85 ALLOW_BAD_FORCEUCASE =
true
88 enum Hidden_Homonym :
bool {
89 ACCEPT_HIDDEN_HOMONYM =
false,
90 SKIP_HIDDEN_HOMONYM =
true
93 auto spell_priv(std::string& s)
const -> bool;
94 auto spell_break(std::string& s,
size_t depth = 0) const ->
bool;
95 auto spell_casing(std::
string& s) const -> const Flag_Set*;
96 auto spell_casing_upper(std::
string& s) const -> const Flag_Set*;
97 auto spell_casing_title(std::
string& s) const -> const Flag_Set*;
98 auto spell_sharps(std::
string& base,
size_t n_pos = 0,
size_t n = 0,
99 size_t rep = 0) const -> const Flag_Set*;
101 auto check_word(std::
string& s, Forceucase allow_bad_forceucase = {},
102 Hidden_Homonym skip_hidden_homonym = {})
const
104 auto check_simple_word(std::string& word,
105 Hidden_Homonym skip_hidden_homonym = {})
const
108 template <Affixing_Mode m>
109 auto affix_NOT_valid(
const Prefix& a)
const;
110 template <Affixing_Mode m>
111 auto affix_NOT_valid(
const Suffix& a)
const;
112 template <Affixing_Mode m,
class AffixT>
113 auto outer_affix_NOT_valid(
const AffixT& a)
const;
114 template <
class AffixT>
115 auto is_circumfix(
const AffixT& a)
const;
116 template <Affixing_Mode m>
117 auto is_valid_inside_compound(
const Flag_Set& flags)
const;
119 template <Affixing_Mode m = FULL_WORD>
120 auto strip_prefix_only(std::string& s,
121 Hidden_Homonym skip_hidden_homonym = {})
const
122 -> Affixing_Result<Prefix>;
124 template <Affixing_Mode m = FULL_WORD>
125 auto strip_suffix_only(std::string& s,
126 Hidden_Homonym skip_hidden_homonym = {})
const
127 -> Affixing_Result<Suffix>;
129 template <Affixing_Mode m = FULL_WORD>
131 strip_prefix_then_suffix(std::string& s,
132 Hidden_Homonym skip_hidden_homonym = {})
const
133 -> Affixing_Result<Suffix, Prefix>;
135 template <Affixing_Mode m>
136 auto strip_pfx_then_sfx_2(
const Prefix& pe, std::string& s,
137 Hidden_Homonym skip_hidden_homonym)
const
138 -> Affixing_Result<Suffix, Prefix>;
140 template <Affixing_Mode m = FULL_WORD>
142 strip_suffix_then_prefix(std::string& s,
143 Hidden_Homonym skip_hidden_homonym = {})
const
144 -> Affixing_Result<Prefix, Suffix>;
146 template <Affixing_Mode m>
147 auto strip_sfx_then_pfx_2(
const Suffix& se, std::string& s,
148 Hidden_Homonym skip_hidden_homonym)
const
149 -> Affixing_Result<Prefix, Suffix>;
151 template <Affixing_Mode m = FULL_WORD>
152 auto strip_prefix_then_suffix_commutative(
153 std::string& word, Hidden_Homonym skip_hidden_homonym = {})
const
154 -> Affixing_Result<Suffix, Prefix>;
156 template <Affixing_Mode m = FULL_WORD>
157 auto strip_pfx_then_sfx_comm_2(
const Prefix& pe, std::string& word,
158 Hidden_Homonym skip_hidden_homonym)
const
159 -> Affixing_Result<Suffix, Prefix>;
161 template <Affixing_Mode m = FULL_WORD>
163 strip_suffix_then_suffix(std::string& s,
164 Hidden_Homonym skip_hidden_homonym = {})
const
165 -> Affixing_Result<Suffix, Suffix>;
167 template <Affixing_Mode m>
168 auto strip_sfx_then_sfx_2(
const Suffix& se1, std::string& s,
169 Hidden_Homonym skip_hidden_homonym)
const
170 -> Affixing_Result<Suffix, Suffix>;
172 template <Affixing_Mode m = FULL_WORD>
174 strip_prefix_then_prefix(std::string& s,
175 Hidden_Homonym skip_hidden_homonym = {})
const
176 -> Affixing_Result<Prefix, Prefix>;
178 template <Affixing_Mode m>
179 auto strip_pfx_then_pfx_2(
const Prefix& pe1, std::string& s,
180 Hidden_Homonym skip_hidden_homonym)
const
181 -> Affixing_Result<Prefix, Prefix>;
183 template <Affixing_Mode m = FULL_WORD>
184 auto strip_prefix_then_2_suffixes(
185 std::string& s, Hidden_Homonym skip_hidden_homonym = {})
const
186 -> Affixing_Result<>;
188 template <Affixing_Mode m>
189 auto strip_pfx_2_sfx_3(
const Prefix& pe1,
const Suffix& se1,
191 Hidden_Homonym skip_hidden_homonym)
const
192 -> Affixing_Result<>;
194 template <Affixing_Mode m = FULL_WORD>
195 auto strip_suffix_prefix_suffix(
196 std::string& s, Hidden_Homonym skip_hidden_homonym = {})
const
197 -> Affixing_Result<>;
199 template <Affixing_Mode m>
200 auto strip_s_p_s_3(
const Suffix& se1,
const Prefix& pe1,
202 Hidden_Homonym skip_hidden_homonym)
const
203 -> Affixing_Result<>;
205 template <Affixing_Mode m = FULL_WORD>
206 auto strip_2_suffixes_then_prefix(
207 std::string& s, Hidden_Homonym skip_hidden_homonym = {})
const
208 -> Affixing_Result<>;
210 template <Affixing_Mode m>
211 auto strip_2_sfx_pfx_3(
const Suffix& se1,
const Suffix& se2,
213 Hidden_Homonym skip_hidden_homonym)
const
214 -> Affixing_Result<>;
216 template <Affixing_Mode m = FULL_WORD>
217 auto strip_suffix_then_2_prefixes(
218 std::string& s, Hidden_Homonym skip_hidden_homonym = {})
const
219 -> Affixing_Result<>;
221 template <Affixing_Mode m>
222 auto strip_sfx_2_pfx_3(
const Suffix& se1,
const Prefix& pe1,
224 Hidden_Homonym skip_hidden_homonym)
const
225 -> Affixing_Result<>;
227 template <Affixing_Mode m = FULL_WORD>
228 auto strip_prefix_suffix_prefix(
229 std::string& word, Hidden_Homonym skip_hidden_homonym = {})
const
230 -> Affixing_Result<>;
232 template <Affixing_Mode m>
233 auto strip_p_s_p_3(
const Prefix& pe1,
const Suffix& se1,
235 Hidden_Homonym skip_hidden_homonym)
const
236 -> Affixing_Result<>;
238 template <Affixing_Mode m = FULL_WORD>
239 auto strip_2_prefixes_then_suffix(
240 std::string& word, Hidden_Homonym skip_hidden_homonym = {})
const
241 -> Affixing_Result<>;
243 template <Affixing_Mode m>
244 auto strip_2_pfx_sfx_3(
const Prefix& pe1,
const Prefix& pe2,
246 Hidden_Homonym skip_hidden_homonym)
const
247 -> Affixing_Result<>;
249 auto check_compound(std::string& word,
250 Forceucase allow_bad_forceucase)
const
251 -> Compounding_Result;
253 template <Affixing_Mode m = AT_COMPOUND_BEGIN>
254 auto check_compound(std::string& word,
size_t start_pos,
255 size_t num_part, std::string& part,
256 Forceucase allow_bad_forceucase)
const
257 -> Compounding_Result;
259 template <Affixing_Mode m = AT_COMPOUND_BEGIN>
260 auto check_compound_classic(std::string& word,
size_t start_pos,
261 size_t i,
size_t num_part,
263 Forceucase allow_bad_forceucase)
const
264 -> Compounding_Result;
266 template <Affixing_Mode m = AT_COMPOUND_BEGIN>
267 auto check_compound_with_pattern_replacements(
268 std::string& word,
size_t start_pos,
size_t i,
size_t num_part,
269 std::string& part, Forceucase allow_bad_forceucase)
const
270 -> Compounding_Result;
272 template <Affixing_Mode m>
273 auto check_word_in_compound(std::string& s)
const -> Compounding_Result;
275 auto calc_num_words_modifier(
const Prefix& pfx)
const ->
unsigned char;
277 template <Affixing_Mode m>
278 auto calc_syllable_modifier(Word_List::const_reference we)
const
281 template <Affixing_Mode m>
282 auto calc_syllable_modifier(Word_List::const_reference we,
283 const Suffix& sfx)
const ->
signed char;
285 auto count_syllables(std::string_view word)
const -> size_t;
287 auto check_compound_with_rules(std::string& word,
288 std::vector<const Flag_Set*>& words_data,
289 size_t start_pos, std::string& part,
290 Forceucase allow_bad_forceucase)
const
292 -> Compounding_Result;
293 auto is_rep_similar(std::string& word)
const -> bool;
296template <Affixing_Mode m>
297auto Checker::affix_NOT_valid(
const Prefix& e)
const
299 if (m == FULL_WORD && e.cont_flags.contains(compound_onlyin_flag))
301 if (m == AT_COMPOUND_END &&
302 !e.cont_flags.contains(compound_permit_flag))
304 if (m != FULL_WORD && e.cont_flags.contains(compound_forbid_flag))
308template <Affixing_Mode m>
309auto Checker::affix_NOT_valid(
const Suffix& e)
const
311 if (m == FULL_WORD && e.cont_flags.contains(compound_onlyin_flag))
313 if (m == AT_COMPOUND_BEGIN &&
314 !e.cont_flags.contains(compound_permit_flag))
316 if (m != FULL_WORD && e.cont_flags.contains(compound_forbid_flag))
320template <Affixing_Mode m,
class AffixT>
321auto Checker::outer_affix_NOT_valid(
const AffixT& e)
const
323 if (affix_NOT_valid<m>(e))
325 if (e.cont_flags.contains(need_affix_flag))
329template <
class AffixT>
330auto Checker::is_circumfix(
const AffixT& a)
const
332 return a.cont_flags.contains(circumfix_flag);
335template <
class AffixInner,
class AffixOuter>
336auto cross_valid_inner_outer(
const AffixInner& inner,
const AffixOuter& outer)
338 return inner.cont_flags.contains(outer.flag);
341template <
class Affix>
342auto cross_valid_inner_outer(
const Flag_Set& word_flags,
const Affix& afx)
344 return word_flags.contains(afx.flag);
347NUSPELL_END_INLINE_NAMESPACE
Library main namespace.
Definition aff_data.cxx:33