mirror of
https://github.com/crate-ci/typos.git
synced 2025-01-11 09:11:39 -05:00
fix(dictgen)!: Generate phf for map feature
Unsure how this happened
This commit is contained in:
parent
016ae0c7c6
commit
3db1b3906e
6 changed files with 180512 additions and 138051 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -450,6 +450,7 @@ name = "dictgen"
|
|||
version = "0.2.11"
|
||||
dependencies = [
|
||||
"phf",
|
||||
"phf_codegen",
|
||||
"phf_shared",
|
||||
"unicase",
|
||||
]
|
||||
|
@ -884,6 +885,16 @@ dependencies = [
|
|||
"phf_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_codegen"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_generator"
|
||||
version = "0.11.2"
|
||||
|
@ -1500,6 +1511,7 @@ dependencies = [
|
|||
"edit-distance",
|
||||
"indexmap",
|
||||
"itertools 0.13.0",
|
||||
"phf",
|
||||
"snapbox",
|
||||
"unicase",
|
||||
"varcon",
|
||||
|
|
|
@ -17,13 +17,14 @@ rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
|
|||
[features]
|
||||
default = ["std"]
|
||||
std = []
|
||||
codegen = ["std"]
|
||||
codegen = ["std", "dep:phf_codegen"]
|
||||
map = ["dep:phf", "dep:phf_shared"]
|
||||
|
||||
[dependencies]
|
||||
unicase = "2.7"
|
||||
phf = { version = "0.11", features = ["unicase"], optional = true }
|
||||
phf_shared = { version = "0.11", optional = true }
|
||||
phf_codegen = { version = "0.11", optional = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -18,6 +18,18 @@ impl<'s> InsensitiveStr<'s> {
|
|||
InsensitiveStr::Unicode(s) | InsensitiveStr::Ascii(s) => s,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(self) -> bool {
|
||||
match self {
|
||||
InsensitiveStr::Unicode(s) | InsensitiveStr::Ascii(s) => s.is_empty(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn len(self) -> usize {
|
||||
match self {
|
||||
InsensitiveStr::Unicode(s) | InsensitiveStr::Ascii(s) => s.len(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> From<unicase::UniCase<&'s str>> for InsensitiveStr<'s> {
|
||||
|
|
|
@ -18,33 +18,35 @@ impl DictMapGen<'_> {
|
|||
|
||||
let mut smallest = usize::MAX;
|
||||
let mut largest = usize::MIN;
|
||||
|
||||
writeln!(
|
||||
file,
|
||||
"pub static {name}: dictgen::DictTable<{value_type}> = dictgen::DictTable {{"
|
||||
)?;
|
||||
writeln!(file, " keys: &[")?;
|
||||
for (key, _value) in data.iter() {
|
||||
let mut builder = phf_codegen::Map::new();
|
||||
let data = data
|
||||
.iter()
|
||||
.map(|(key, value)| {
|
||||
(
|
||||
if key.is_ascii() {
|
||||
crate::InsensitiveStr::Ascii(key)
|
||||
} else {
|
||||
crate::InsensitiveStr::Unicode(key)
|
||||
},
|
||||
value.to_string(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
for (key, value) in data.iter() {
|
||||
smallest = std::cmp::min(smallest, key.len());
|
||||
largest = std::cmp::max(largest, key.len());
|
||||
|
||||
let key = if key.is_ascii() {
|
||||
format!("dictgen::InsensitiveStr::Ascii({key:?})")
|
||||
} else {
|
||||
format!("dictgen::InsensitiveStr::Unicode({key:?})")
|
||||
};
|
||||
|
||||
writeln!(file, " {key},")?;
|
||||
builder.entry(key, value.as_str());
|
||||
}
|
||||
let builder = builder.build();
|
||||
if largest == 0 {
|
||||
smallest = 0;
|
||||
}
|
||||
writeln!(file, " ],")?;
|
||||
writeln!(file, " values: &[")?;
|
||||
for (_key, value) in data.iter() {
|
||||
writeln!(file, " {value},")?;
|
||||
}
|
||||
writeln!(file, " ],")?;
|
||||
|
||||
writeln!(
|
||||
file,
|
||||
"pub static {name}: dictgen::DictMap<{value_type}> = dictgen::DictMap {{"
|
||||
)?;
|
||||
writeln!(file, " map: {builder},")?;
|
||||
writeln!(file, " range: {smallest}..={largest},")?;
|
||||
writeln!(file, "}};")?;
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ varcon = { version = "^1.0", path = "../varcon" }
|
|||
snapbox = "0.6.5"
|
||||
indexmap = "2.2.6"
|
||||
divan = "0.1.16"
|
||||
phf = "0.11.2"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue