mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 09:01:04 -05:00
feat(parse): Make digits in identifier optional
This commit is contained in:
parent
50c89ef761
commit
e093135ac1
1 changed files with 17 additions and 4 deletions
|
@ -9,6 +9,7 @@ pub enum Case {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct ParserBuilder {
|
pub struct ParserBuilder {
|
||||||
ignore_hex: bool,
|
ignore_hex: bool,
|
||||||
|
include_digits: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParserBuilder {
|
impl ParserBuilder {
|
||||||
|
@ -21,10 +22,19 @@ impl ParserBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn include_digits(&mut self, yes: bool) -> &mut Self {
|
||||||
|
self.include_digits = yes;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(&self) -> Parser {
|
pub fn build(&self) -> Parser {
|
||||||
let pattern = r#"\b(\p{Alphabetic}|\d|_|')+\b"#;
|
let mut pattern = r#"\b(\p{Alphabetic}|_|'"#.to_owned();
|
||||||
let words_str = regex::Regex::new(pattern).unwrap();
|
if self.include_digits {
|
||||||
let words_bytes = regex::bytes::Regex::new(pattern).unwrap();
|
pattern.push_str(r#"|\d"#);
|
||||||
|
}
|
||||||
|
pattern.push_str(r#")+\b"#);
|
||||||
|
let words_str = regex::Regex::new(&pattern).unwrap();
|
||||||
|
let words_bytes = regex::bytes::Regex::new(&pattern).unwrap();
|
||||||
Parser {
|
Parser {
|
||||||
words_str,
|
words_str,
|
||||||
words_bytes,
|
words_bytes,
|
||||||
|
@ -35,7 +45,10 @@ impl ParserBuilder {
|
||||||
|
|
||||||
impl Default for ParserBuilder {
|
impl Default for ParserBuilder {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { ignore_hex: true }
|
Self {
|
||||||
|
ignore_hex: true,
|
||||||
|
include_digits: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue