@@ -11,8 +11,6 @@ use crate::{
11
11
// <https://github.com/nuspell/nuspell/blob/349e0d6bc68b776af035ca3ff664a7fc55d69387/src/nuspell/dictionary.cxx#L156>
12
12
const MAX_WORD_LEN : usize = 360 ;
13
13
14
- const MAX_BREAK_DEPTH : usize = 9 ;
15
-
16
14
// TODO: expose type and add options to it?
17
15
pub ( crate ) struct Checker < ' a , S : BuildHasher > {
18
16
aff : & ' a AffData < S > ,
@@ -44,22 +42,28 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
44
42
45
43
// TODO: erase chars in `trimmed_word`
46
44
47
- if self . spell_break ( trimmed_word, 0 ) {
45
+ if self . spell_break ( trimmed_word) {
48
46
return true ;
49
47
}
50
48
51
49
if abbreviated {
52
50
// TODO: erase chars in `word` - or figure out abbreviation after ignore-chars.
53
51
// TODO: only keep one `.`?
54
- return self . spell_break ( word, 0 ) ;
52
+ return self . spell_break ( word) ;
55
53
}
56
54
57
55
false
58
56
}
59
57
60
58
/// Recursively breaks up a word according to the dictionary's `BREAK` rules and checks that
61
59
/// each broken word is correct.
62
- fn spell_break ( & self , word : & str , depth : usize ) -> bool {
60
+ fn spell_break ( & self , word : & str ) -> bool {
61
+ self . do_spell_break ( word, 0 )
62
+ }
63
+
64
+ fn do_spell_break ( & self , word : & str , depth : usize ) -> bool {
65
+ const MAX_BREAK_DEPTH : usize = 9 ;
66
+
63
67
if let Some ( flags) = & self . spell_casing ( word) {
64
68
if has_flag ! ( flags, self . aff. options. forbidden_word_flag) {
65
69
return false ;
@@ -78,15 +82,15 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
78
82
79
83
for pattern in self . aff . break_table . start_word_breaks ( ) {
80
84
if let Some ( rest) = word. strip_prefix ( pattern) {
81
- if self . spell_break ( rest, depth + 1 ) {
85
+ if self . do_spell_break ( rest, depth + 1 ) {
82
86
return true ;
83
87
}
84
88
}
85
89
}
86
90
87
91
for pattern in self . aff . break_table . end_word_breaks ( ) {
88
92
if let Some ( rest) = word. strip_suffix ( pattern) {
89
- if self . spell_break ( rest, depth + 1 ) {
93
+ if self . do_spell_break ( rest, depth + 1 ) {
90
94
return true ;
91
95
}
92
96
}
@@ -101,11 +105,11 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
101
105
continue ;
102
106
}
103
107
104
- if !self . spell_break ( part1, depth + 1 ) {
108
+ if !self . do_spell_break ( part1, depth + 1 ) {
105
109
continue ;
106
110
}
107
111
108
- if self . spell_break ( part2, depth + 1 ) {
112
+ if self . do_spell_break ( part2, depth + 1 ) {
109
113
return true ;
110
114
}
111
115
}
0 commit comments