mirror of
https://github.com/crate-ci/typos.git
synced 2026-11-29 08:17:46 +01:00
perf(parser): Allow people to bypass unicode cost
This commit is contained in:
1 parent
09d2124d0f
commit
517da7ecd2
5 files changed
+158
-30
No files matched your search
@@ -230,6 +230,8 @@ impl EngineConfig {
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct TokenizerConfig {
|
||||
/// Allow unicode characters in identifiers (and not just ASCII)
|
||||
pub unicode: Option<bool>,
|
||||
/// Do not check identifiers that appear to be hexadecimal values.
|
||||
pub ignore_hex: Option<bool>,
|
||||
/// Allow identifiers to start with digits, in addition to letters.
|
||||
@@ -240,12 +242,16 @@ impl TokenizerConfig {
|
||||
pub fn from_defaults() -> Self {
|
||||
let empty = Self::default();
|
||||
Self {
|
||||
unicode: Some(empty.unicode()),
|
||||
ignore_hex: Some(empty.ignore_hex()),
|
||||
identifier_leading_digits: Some(empty.identifier_leading_digits()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, source: &TokenizerConfig) {
|
||||
if let Some(source) = source.unicode {
|
||||
self.unicode = Some(source);
|
||||
}
|
||||
if let Some(source) = source.ignore_hex {
|
||||
self.ignore_hex = Some(source);
|
||||
}
|
||||
@@ -254,6 +260,10 @@ impl TokenizerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unicode(&self) -> bool {
|
||||
self.unicode.unwrap_or(true)
|
||||
}
|
||||
|
||||
pub fn ignore_hex(&self) -> bool {
|
||||
self.ignore_hex.unwrap_or(true)
|
||||
}
|
||||
|
||||
@@ -217,6 +217,7 @@ impl<'s> ConfigEngine<'s> {
|
||||
let dict_config = dict.unwrap_or_else(crate::config::DictConfig::from_defaults);
|
||||
|
||||
let tokenizer = typos::tokens::TokenizerBuilder::new()
|
||||
.unicode(tokenizer_config.unicode())
|
||||
.ignore_hex(tokenizer_config.ignore_hex())
|
||||
.leading_digits(tokenizer_config.identifier_leading_digits())
|
||||
.build();
|
||||
|
||||
Reference in new issue
Block a user