revert using regex
This commit is contained in:
parent
047a0c6fa5
commit
ab15157960
1 changed files with 41 additions and 11 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
use regex::{Regex, RegexSet};
|
||||
use std::collections::HashMap;
|
||||
use std::{ffi::OsStr, path::Path};
|
||||
|
||||
/// Error code markdown is restricted to 80 columns because they can be
|
||||
|
@ -65,8 +66,39 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
|
|||
"//@ normalize-stderr-test",
|
||||
];
|
||||
|
||||
fn generate_problems<'a>(
|
||||
consts: &'a [u32],
|
||||
letter_digit: &'a HashMap<char, char>,
|
||||
) -> impl Iterator<Item = u32> + 'a {
|
||||
consts.into_iter().flat_map(move |const_value| {
|
||||
let mut problem = format!("{:X}", const_value);
|
||||
for (key, value) in letter_digit {
|
||||
problem = problem.replace(&value.to_string(), &key.to_string());
|
||||
}
|
||||
let indexes: Vec<usize> = problem
|
||||
.chars()
|
||||
.enumerate()
|
||||
.filter_map(|(index, c)| if letter_digit.contains_key(&c) { Some(index) } else { None })
|
||||
.collect();
|
||||
(0..1 << indexes.len()).map(move |i| {
|
||||
let result = problem
|
||||
.chars()
|
||||
.enumerate()
|
||||
.map(|(index, c)| {
|
||||
if let Some(pos) = indexes.iter().position(|&x| x == index) {
|
||||
if (i >> pos) & 1 == 1 { letter_digit[&c] } else { c }
|
||||
} else {
|
||||
c
|
||||
}
|
||||
})
|
||||
.collect::<String>();
|
||||
u32::from_str_radix(&result, 0x10).unwrap()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Intentionally written in decimal rather than hex
|
||||
const PROBLEMATIC_CONSTS: &[u32] = &[
|
||||
const ROOT_PROBLEMATIC_CONSTS: &[u32] = &[
|
||||
184594741, 2880289470, 2881141438, 2965027518, 2976579765, 3203381950, 3405691582, 3405697037,
|
||||
3735927486, 3735932941, 4027431614, 4276992702, 195934910, 252707358, 762133, 179681982,
|
||||
173390526,
|
||||
|
@ -268,16 +300,14 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||
// We only check CSS files in rustdoc.
|
||||
path.extension().map_or(false, |e| e == "css") && !is_in(path, "src", "librustdoc")
|
||||
}
|
||||
let problematic_consts_strings: Vec<String> = (PROBLEMATIC_CONSTS.iter().map(u32::to_string))
|
||||
.chain(PROBLEMATIC_CONSTS.iter().map(|v| {
|
||||
format!("{:x}", v)
|
||||
.replace("a", "[aA4]")
|
||||
.replace("b", "[bB8]")
|
||||
.replace("c", "[cC]")
|
||||
.replace("d", "[dD]")
|
||||
.replace("e", "[eE3]")
|
||||
.replace("f", "[fF]")
|
||||
}))
|
||||
let problematic_consts = generate_problems(
|
||||
ROOT_PROBLEMATIC_CONSTS,
|
||||
&[('A', '4'), ('B', '8'), ('E', '3')].iter().cloned().collect(),
|
||||
)
|
||||
.collect::<Vec<u32>>();
|
||||
let problematic_consts_strings: Vec<String> = (problematic_consts.iter().map(u32::to_string))
|
||||
.chain(problematic_consts.iter().map(|v| format!("{:x}", v)))
|
||||
.chain(problematic_consts.iter().map(|v| format!("{:X}", v)))
|
||||
.collect();
|
||||
let problematic_regex = RegexSet::new(problematic_consts_strings.as_slice()).unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue