Tshepang Mbambo 2022-07-31 22:09:30 +02:00
parent 3faf82c00e
commit 74b9b456c1
1 changed files with 5 additions and 10 deletions

View File

@ -8,7 +8,7 @@ use std::{
use chrono::{Datelike as _, Month, TimeZone as _, Utc}; use chrono::{Datelike as _, Month, TimeZone as _, Utc};
use glob::glob; use glob::glob;
use regex::{Regex, RegexSet}; use regex::Regex;
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
struct Date { struct Date {
@ -37,15 +37,10 @@ impl fmt::Display for Date {
} }
fn make_date_regex() -> Vec<Regex> { fn make_date_regex() -> Vec<Regex> {
let patterns = [ Vec::from([
r"<!--\s+date-check:\s+(\D+)\s+(\d{4})\s+-->", Regex::new(r"<!--\s+date-check:\s+(\D+)\s+(\d{4})\s+-->").unwrap(),
r"<!--\s+date-check\s+-->\s+(\D+)\s+(\d{4})\b", Regex::new(r"<!--\s+date-check\s+-->\s+(\D+)\s+(\d{4})\b").unwrap(),
]; ])
let set = RegexSet::new(&patterns).unwrap();
set.patterns()
.iter()
.map(|pattern| Regex::new(pattern).unwrap())
.collect()
} }
fn collect_dates_from_file(date_regexes: &[Regex], text: &str) -> Vec<(usize, Date)> { fn collect_dates_from_file(date_regexes: &[Regex], text: &str) -> Vec<(usize, Date)> {