MCPcopy Create free account
hub / github.com/ConorWilliams/libfork / process_one

Method process_one

tools/make_single_header.cpp:49–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

runMethod · 0.80

Calls 1

containsFunction · 0.85

Tested by

no test coverage detected