move all regex into lazy static

This commit is contained in:
Henry Schimke
2022-10-02 12:46:11 -05:00
parent e78b919c7b
commit 02288dcfc3
9 changed files with 123 additions and 72 deletions

View File

@@ -2,13 +2,16 @@ use regex::Regex;
use crate::common::BitArray;
const SPACES :&str= "\\s+";
const DOTX : &str = "[^.X]";
use lazy_static::lazy_static;
lazy_static! {
static ref SPACES: Regex =Regex::new("\\s+").unwrap();
static ref DOTX: Regex = Regex::new("[^.X]").unwrap();
}
pub fn toBitArray( bits:&str) -> BitArray{
let mut ba_in = BitArray::new();
let replacer_regex = Regex::new(DOTX).unwrap();
let str = replacer_regex.replace_all(bits, "");
let str = DOTX.replace_all(bits, "");
for a_str in str.chars() {
// for (char aStr : str) {
ba_in.appendBit(a_str == 'X');
@@ -27,6 +30,5 @@ pub fn toBitArray( bits:&str) -> BitArray{
}
pub fn stripSpace( s:&str) -> String{
let replacer_regex = Regex::new(SPACES).unwrap();
replacer_regex.replace_all(s, "").to_string()
SPACES.replace_all(s, "").to_string()
}