Skip to content

Commit d4f51ef

Browse files
committed
minor: Style improvements for spell_break
1 parent 18e1d6a commit d4f51ef

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/checker.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use crate::{
1111
// <https://github.com/nuspell/nuspell/blob/349e0d6bc68b776af035ca3ff664a7fc55d69387/src/nuspell/dictionary.cxx#L156>
1212
const MAX_WORD_LEN: usize = 360;
1313

14-
const MAX_BREAK_DEPTH: usize = 9;
15-
1614
// TODO: expose type and add options to it?
1715
pub(crate) struct Checker<'a, S: BuildHasher> {
1816
aff: &'a AffData<S>,
@@ -44,22 +42,28 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
4442

4543
// TODO: erase chars in `trimmed_word`
4644

47-
if self.spell_break(trimmed_word, 0) {
45+
if self.spell_break(trimmed_word) {
4846
return true;
4947
}
5048

5149
if abbreviated {
5250
// TODO: erase chars in `word` - or figure out abbreviation after ignore-chars.
5351
// TODO: only keep one `.`?
54-
return self.spell_break(word, 0);
52+
return self.spell_break(word);
5553
}
5654

5755
false
5856
}
5957

6058
/// Recursively breaks up a word according to the dictionary's `BREAK` rules and checks that
6159
/// 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+
6367
if let Some(flags) = &self.spell_casing(word) {
6468
if has_flag!(flags, self.aff.options.forbidden_word_flag) {
6569
return false;
@@ -78,15 +82,15 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
7882

7983
for pattern in self.aff.break_table.start_word_breaks() {
8084
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) {
8286
return true;
8387
}
8488
}
8589
}
8690

8791
for pattern in self.aff.break_table.end_word_breaks() {
8892
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) {
9094
return true;
9195
}
9296
}
@@ -101,11 +105,11 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
101105
continue;
102106
}
103107

104-
if !self.spell_break(part1, depth + 1) {
108+
if !self.do_spell_break(part1, depth + 1) {
105109
continue;
106110
}
107111

108-
if self.spell_break(part2, depth + 1) {
112+
if self.do_spell_break(part2, depth + 1) {
109113
return true;
110114
}
111115
}

0 commit comments

Comments
 (0)