1use regex::Regex;
2
3pub struct Hpp {}
4
5pub enum Type {
6 Api,
7 Functions,
8}
9
10impl Hpp {
11 pub fn parse(full_file_path: &String,
12 _type: Type)
13 -> crate::ParsedData {
14 match _type {
15 Type::Api => todo!(),
16 Type::Functions => Hpp::functions_header(full_file_path),
17 }
18 }
19
20 pub fn functions_header(full_file_path: &String) -> crate::ParsedData {
21 let header_regex = Regex::new(r"\(\s*([^)]+?)\s*\)").unwrap();
22
23 let mut final_data = crate::ParsedData { offsets: vec![],
24 major_version: 0,
25 minor_version: 0,
26 platform: crate::Platform::UNDEFINED };
27
28 if let Ok(lines) = crate::read_lines(full_file_path) {
29 for line in lines {
30 if let Ok(line) = line {
31 if line.starts_with("N") {
32 let parse = header_regex.captures(&line).unwrap();
33 let mut data = parse.get(1).map_or("", |m| m.as_str()).split(", ");
34
35 if line.contains("NWNX_EXPECT_VERSION") {
36 final_data.major_version = data.next().unwrap().to_string().parse::<u16>().unwrap();
37 final_data.minor_version = data.next().unwrap().to_string().parse::<u16>().unwrap();
38 continue;
39 } else {
40 final_data.offsets.push(crate::NwOffset { name: data.next().unwrap().to_string(),
41 offset: data.next().unwrap().to_string() });
42 }
43
44 continue;
45 }
46 }
47 }
48 }
49
50 crate::ParsedData { major_version: final_data.major_version,
51 minor_version: final_data.minor_version,
52 platform: final_data.platform,
53 offsets: final_data.offsets }
54 }
55}