MCPcopy Create free account
hub / github.com/ddiakopoulos/polymer / process_includes_recursive

Function process_includes_recursive

libraries/lib-engine/src/shader.cpp:9–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7////////////////////////////////////////
8
9std::string process_includes_recursive(const std::string & source, const std::string & includeSearchPath, std::vector<std::string> & includes, int depth)
10{
11 if (depth > 2) throw std::runtime_error("exceeded max include recursion depth");
12
13 static const std::regex re("^[ ]*#[ ]*include[ ]+[\"<](.*)[\">].*");
14 std::stringstream input;
15 std::stringstream output;
16
17 input << source;
18
19 size_t lineNumber = 1;
20 std::smatch matches;
21 std::string line;
22
23 while (std::getline(input, line))
24 {
25 if (std::regex_search(line, matches, re))
26 {
27 std::string includeFile = matches[1];
28 std::string includeString = read_file_text(includeSearchPath + "/" + includeFile);
29
30 if (!includeFile.empty())
31 {
32 includes.push_back(includeSearchPath + "/" + includeFile);
33 output << process_includes_recursive(includeString, includeSearchPath, includes, depth++) << std::endl;
34 }
35 }
36 else
37 {
38 output << "#line " << lineNumber << std::endl;
39 output << line << std::endl;
40 }
41 ++lineNumber;
42 }
43 return output.str();
44}
45
46std::string preprocess_version(const std::string & source)
47{

Callers 1

preprocessFunction · 0.85

Calls 2

read_file_textFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected