fix(dict)!: Clarify word sizes with Ranges

The code was generated with separate min / max, rather than using a
Range and ensuring the API is used correctly.
This commit is contained in:
Ed Page committed 2021-04-30 21:33:33 -05:00
1 parent 14f1532bee
commit 6216fa0837
5 files changed
+16 -14

No files matched your search

+2 -6
View File
@@ -48,9 +48,7 @@ impl BuiltIn {
// Not using `Status` to avoid the allocations
fn correct_with_dict(&self, word: &str) -> Option<&'static str> {
const WORD_RANGE: std::ops::RangeInclusive<usize> =
typos_dict::WORD_MIN..=typos_dict::WORD_MAX;
if WORD_RANGE.contains(&word.len()) {
if typos_dict::WORD_RANGE.contains(&word.len()) {
map_lookup(&typos_dict::WORD_DICTIONARY, word)
} else {
None
@@ -58,9 +56,7 @@ impl BuiltIn {
}
fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> {
const WORD_RANGE: std::ops::RangeInclusive<usize> =
typos_vars::WORD_MIN..=typos_vars::WORD_MAX;
if WORD_RANGE.contains(&word.len()) {
if typos_vars::WORD_RANGE.contains(&word.len()) {
map_lookup(&typos_vars::VARS_DICTIONARY, word)
.map(|variants| self.select_variant(variants))
} else {