aoe2_probe/parse/
censor.rs1use crate::{parse::Token, utils::PatchedMap};
2
3pub struct Censor {}
4
5impl Censor {
6 pub fn is_template(root: &Token, template: &Token, depth: usize) -> bool {
7 if depth == 0 {
8 return true;
9 }
10 match root {
11 Token::Union(map) => {
12 let root_type = root.eq(template);
13 if root_type {
14 let template_map = template.try_map();
15
16 let contains_key = template_map
17 .keys()
18 .map(|key| map.contains(key))
19 .fold(true, |acc, current| acc & current);
20 if contains_key {
21 let value_equal = template_map
22 .keys()
23 .map(|key| Self::is_template(&map[key], &template_map[key], depth - 1))
24 .fold(true, |acc, current| acc & current);
25 return value_equal;
26 }
27 }
28 false
29 }
30 _ => root.eq(template),
31 }
32 }
33
34 pub fn is_map(token: &Token) -> bool {
35 let map: Token = PatchedMap::new().into();
36 map.eq(token)
37 }
38}