rsphp_build_tools/
comment_processor.rs1use bindgen::callbacks::ParseCallbacks;
2
3#[derive(Clone, Copy, Debug, Default)]
5#[non_exhaustive]
6pub struct CommentProcessor;
7
8impl CommentProcessor {
9 #[must_use]
11 pub fn new() -> Self {
12 CommentProcessor
13 }
14}
15
16impl ParseCallbacks for CommentProcessor {
17 fn process_comment(&self, comment: &str) -> Option<String> {
18 if !comment.contains("Parses an ini quantity") {
20 return None;
21 }
22 let lines = comment.split('\n');
23 let mut in_backticks = false;
24 let mut result = String::new();
25 for line in lines {
26 let should_be_code = line.starts_with(" ");
27 match (should_be_code, in_backticks) {
28 (true, false) => {
29 in_backticks = true;
30 result += "```text\n";
31 }
32 (false, true) => {
33 in_backticks = false;
34 result += "```\n";
35 }
36 _ => (),
37 }
38 result += line;
39 result += "\n";
40 }
41 Some(result)
42 }
43}