| 47 | explicit include_processor(fs::path &&start_path) : m_start_path(std::move(start_path)) {} |
| 48 | |
| 49 | auto process_one(fs::path const &path) -> std::string { |
| 50 | // |
| 51 | // std::cout << "Processing path " << path << '\n'; |
| 52 | |
| 53 | std::ifstream infile(path); |
| 54 | |
| 55 | std::string text(std::istreambuf_iterator<char>{infile}, std::istreambuf_iterator<char>{}); |
| 56 | |
| 57 | std::deque<replacement> replacements; |
| 58 | |
| 59 | std::for_each(std::sregex_iterator(text.begin(), text.end(), m_regex), |
| 60 | std::sregex_iterator{}, |
| 61 | [&](auto const &match) { |
| 62 | // |
| 63 | auto rep = replacement{match.position(), match.length(), {}}; |
| 64 | |
| 65 | auto new_path = m_start_path; |
| 66 | |
| 67 | new_path = fs::canonical(new_path.append(match.str(1))); |
| 68 | |
| 69 | if (!contains(m_processed_paths, new_path)) { |
| 70 | std::cout << "Found " << match.str(1) << " in " << path << '\n'; |
| 71 | rep.text = "\n" + process_one(new_path) + "\n"; |
| 72 | } |
| 73 | |
| 74 | replacements.push_back(std::move(rep)); |
| 75 | }); |
| 76 | |
| 77 | process_replacements(text, replacements); |
| 78 | m_processed_paths.push_back(path); |
| 79 | return text; |
| 80 | } |
| 81 | |
| 82 | static void process_replacements(std::string &str, std::deque<replacement> &replacements) { |
| 83 | |