refactor: Move off of lazy_static

This commit is contained in:
Ed Page 2020-11-09 19:27:25 -06:00
parent 3bcd8a130e
commit 97f90da9bc
3 changed files with 18 additions and 12 deletions

8
Cargo.lock generated
View file

@ -523,6 +523,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"
[[package]]
name = "phf"
version = "0.8.0"
@ -982,8 +988,8 @@ dependencies = [
"derive_more 0.99.11",
"derive_setters",
"itertools",
"lazy_static",
"log",
"once_cell",
"regex",
"serde",
"serde_json",

View file

@ -18,7 +18,7 @@ codecov = { repository = "crate-ci/typos" }
anyhow = "1.0"
thiserror = "1.0"
regex = "1.3"
lazy_static = "1.2.0"
once_cell = "1.2.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
itertools = "0.9"

View file

@ -138,21 +138,21 @@ impl Default for Parser {
}
}
// `_`: number literal separator in Rust and other languages
// `'`: number literal separator in C++
static DIGITS: once_cell::sync::Lazy<regex::bytes::Regex> =
once_cell::sync::Lazy::new(|| regex::bytes::Regex::new(r#"^[0-9_']+$"#).unwrap());
fn is_number(ident: &[u8]) -> bool {
lazy_static::lazy_static! {
// `_`: number literal separator in Rust and other languages
// `'`: number literal separator in C++
static ref DIGITS: regex::bytes::Regex = regex::bytes::Regex::new(r#"^[0-9_']+$"#).unwrap();
}
DIGITS.is_match(ident)
}
// `_`: number literal separator in Rust and other languages
// `'`: number literal separator in C++
static HEX: once_cell::sync::Lazy<regex::bytes::Regex> =
once_cell::sync::Lazy::new(|| regex::bytes::Regex::new(r#"^0[xX][0-9a-fA-F_']+$"#).unwrap());
fn is_hex(ident: &[u8]) -> bool {
lazy_static::lazy_static! {
// `_`: number literal separator in Rust and other languages
// `'`: number literal separator in C++
static ref HEX: regex::bytes::Regex = regex::bytes::Regex::new(r#"^0[xX][0-9a-fA-F_']+$"#).unwrap();
}
HEX.is_match(ident)
}