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"
|
version = "0.2.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf",
|
"phf",
|
||||||
|
"phf_codegen",
|
||||||
"phf_shared",
|
"phf_shared",
|
||||||
"unicase",
|
"unicase",
|
||||||
]
|
]
|
||||||
|
@ -884,6 +885,16 @@ dependencies = [
|
||||||
"phf_shared",
|
"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]]
|
[[package]]
|
||||||
name = "phf_generator"
|
name = "phf_generator"
|
||||||
version = "0.11.2"
|
version = "0.11.2"
|
||||||
|
@ -1500,6 +1511,7 @@ dependencies = [
|
||||||
"edit-distance",
|
"edit-distance",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"itertools 0.13.0",
|
"itertools 0.13.0",
|
||||||
|
"phf",
|
||||||
"snapbox",
|
"snapbox",
|
||||||
"unicase",
|
"unicase",
|
||||||
"varcon",
|
"varcon",
|
||||||
|
|
|
@ -17,13 +17,14 @@ rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = []
|
std = []
|
||||||
codegen = ["std"]
|
codegen = ["std", "dep:phf_codegen"]
|
||||||
map = ["dep:phf", "dep:phf_shared"]
|
map = ["dep:phf", "dep:phf_shared"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
unicase = "2.7"
|
unicase = "2.7"
|
||||||
phf = { version = "0.11", features = ["unicase"], optional = true }
|
phf = { version = "0.11", features = ["unicase"], optional = true }
|
||||||
phf_shared = { version = "0.11", optional = true }
|
phf_shared = { version = "0.11", optional = true }
|
||||||
|
phf_codegen = { version = "0.11", optional = true }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
@ -18,6 +18,18 @@ impl<'s> InsensitiveStr<'s> {
|
||||||
InsensitiveStr::Unicode(s) | InsensitiveStr::Ascii(s) => 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> {
|
impl<'s> From<unicase::UniCase<&'s str>> for InsensitiveStr<'s> {
|
||||||
|
|
|
@ -18,33 +18,35 @@ impl DictMapGen<'_> {
|
||||||
|
|
||||||
let mut smallest = usize::MAX;
|
let mut smallest = usize::MAX;
|
||||||
let mut largest = usize::MIN;
|
let mut largest = usize::MIN;
|
||||||
|
let mut builder = phf_codegen::Map::new();
|
||||||
writeln!(
|
let data = data
|
||||||
file,
|
.iter()
|
||||||
"pub static {name}: dictgen::DictTable<{value_type}> = dictgen::DictTable {{"
|
.map(|(key, value)| {
|
||||||
)?;
|
(
|
||||||
writeln!(file, " keys: &[")?;
|
if key.is_ascii() {
|
||||||
for (key, _value) in data.iter() {
|
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());
|
smallest = std::cmp::min(smallest, key.len());
|
||||||
largest = std::cmp::max(largest, key.len());
|
largest = std::cmp::max(largest, key.len());
|
||||||
|
builder.entry(key, value.as_str());
|
||||||
let key = if key.is_ascii() {
|
|
||||||
format!("dictgen::InsensitiveStr::Ascii({key:?})")
|
|
||||||
} else {
|
|
||||||
format!("dictgen::InsensitiveStr::Unicode({key:?})")
|
|
||||||
};
|
|
||||||
|
|
||||||
writeln!(file, " {key},")?;
|
|
||||||
}
|
}
|
||||||
|
let builder = builder.build();
|
||||||
if largest == 0 {
|
if largest == 0 {
|
||||||
smallest = 0;
|
smallest = 0;
|
||||||
}
|
}
|
||||||
writeln!(file, " ],")?;
|
|
||||||
writeln!(file, " values: &[")?;
|
writeln!(
|
||||||
for (_key, value) in data.iter() {
|
file,
|
||||||
writeln!(file, " {value},")?;
|
"pub static {name}: dictgen::DictMap<{value_type}> = dictgen::DictMap {{"
|
||||||
}
|
)?;
|
||||||
writeln!(file, " ],")?;
|
writeln!(file, " map: {builder},")?;
|
||||||
writeln!(file, " range: {smallest}..={largest},")?;
|
writeln!(file, " range: {smallest}..={largest},")?;
|
||||||
writeln!(file, "}};")?;
|
writeln!(file, "}};")?;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ varcon = { version = "^1.0", path = "../varcon" }
|
||||||
snapbox = "0.6.5"
|
snapbox = "0.6.5"
|
||||||
indexmap = "2.2.6"
|
indexmap = "2.2.6"
|
||||||
divan = "0.1.16"
|
divan = "0.1.16"
|
||||||
|
phf = "0.11.2"
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue