mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 09:01:04 -05:00
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:
parent
14f1532bee
commit
6216fa0837
5 changed files with 16 additions and 14 deletions
|
@ -38,8 +38,12 @@ fn generate<W: std::io::Write>(file: &mut W) {
|
||||||
writeln!(file, "{}", codegenned).unwrap();
|
writeln!(file, "{}", codegenned).unwrap();
|
||||||
writeln!(file, ";").unwrap();
|
writeln!(file, ";").unwrap();
|
||||||
writeln!(file).unwrap();
|
writeln!(file).unwrap();
|
||||||
writeln!(file, "pub const WORD_MIN: usize = {};", smallest).unwrap();
|
writeln!(
|
||||||
writeln!(file, "pub const WORD_MAX: usize = {};", largest).unwrap();
|
file,
|
||||||
|
"pub const WORD_RANGE: std::ops::RangeInclusive<usize> = {}..={};",
|
||||||
|
smallest, largest
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
|
|
|
@ -33649,5 +33649,4 @@ pub static WORD_DICTIONARY: phf::Map<unicase::UniCase<&'static str>, &'static st
|
||||||
]),
|
]),
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const WORD_MIN: usize = 3;
|
pub const WORD_RANGE: std::ops::RangeInclusive<usize> = 3..=19;
|
||||||
pub const WORD_MAX: usize = 19;
|
|
||||||
|
|
|
@ -103,8 +103,12 @@ fn generate_variations<W: std::io::Write>(file: &mut W) {
|
||||||
writeln!(file, ";").unwrap();
|
writeln!(file, ";").unwrap();
|
||||||
|
|
||||||
writeln!(file).unwrap();
|
writeln!(file).unwrap();
|
||||||
writeln!(file, "pub const WORD_MIN: usize = {};", smallest).unwrap();
|
writeln!(
|
||||||
writeln!(file, "pub const WORD_MAX: usize = {};", largest).unwrap();
|
file,
|
||||||
|
"pub const WORD_RANGE: std::ops::RangeInclusive<usize> = {}..={};",
|
||||||
|
smallest, largest
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
for (symbol, entry) in entries.iter() {
|
for (symbol, entry) in entries.iter() {
|
||||||
if !referenced_symbols.contains(symbol.as_str()) {
|
if !referenced_symbols.contains(symbol.as_str()) {
|
||||||
|
|
|
@ -113082,8 +113082,7 @@ pub static VARS_DICTIONARY: phf::Map<
|
||||||
]),
|
]),
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const WORD_MIN: usize = 2;
|
pub const WORD_RANGE: std::ops::RangeInclusive<usize> = 2..=24;
|
||||||
pub const WORD_MAX: usize = 24;
|
|
||||||
pub(crate) static ENTRY_ABETTORS_7043394254318611656: VariantsMap =
|
pub(crate) static ENTRY_ABETTORS_7043394254318611656: VariantsMap =
|
||||||
[&["abettors"], &["abetters"], &["abettors"], &["abetters"]];
|
[&["abettors"], &["abetters"], &["abettors"], &["abetters"]];
|
||||||
|
|
||||||
|
|
|
@ -48,9 +48,7 @@ impl BuiltIn {
|
||||||
|
|
||||||
// Not using `Status` to avoid the allocations
|
// Not using `Status` to avoid the allocations
|
||||||
fn correct_with_dict(&self, word: &str) -> Option<&'static str> {
|
fn correct_with_dict(&self, word: &str) -> Option<&'static str> {
|
||||||
const WORD_RANGE: std::ops::RangeInclusive<usize> =
|
if typos_dict::WORD_RANGE.contains(&word.len()) {
|
||||||
typos_dict::WORD_MIN..=typos_dict::WORD_MAX;
|
|
||||||
if WORD_RANGE.contains(&word.len()) {
|
|
||||||
map_lookup(&typos_dict::WORD_DICTIONARY, word)
|
map_lookup(&typos_dict::WORD_DICTIONARY, word)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -58,9 +56,7 @@ impl BuiltIn {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> {
|
fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> {
|
||||||
const WORD_RANGE: std::ops::RangeInclusive<usize> =
|
if typos_vars::WORD_RANGE.contains(&word.len()) {
|
||||||
typos_vars::WORD_MIN..=typos_vars::WORD_MAX;
|
|
||||||
if WORD_RANGE.contains(&word.len()) {
|
|
||||||
map_lookup(&typos_vars::VARS_DICTIONARY, word)
|
map_lookup(&typos_vars::VARS_DICTIONARY, word)
|
||||||
.map(|variants| self.select_variant(variants))
|
.map(|variants| self.select_variant(variants))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue