52{
53 inserted = false;
54 const std::string file =
sidecar_path(header, suffix).filename().string();
56 if (!text) {
57 error = "cannot read " + header.string();
58 return false;
59 }
60 if (!include_lines(*text, file + "\"").empty()) {
61 return true;
62 }
63
64 const std::string newline = text->find("\r\n") != std::string::npos ? "\r\n" : "\n";
65 const std::string line = "#include \"" + file + "\"" + newline;
66
67 std::size_t offset = 0;
68 for (unsigned i = 0; i < last_marker && offset != std::string::npos; ++i) {
69 const auto next = text->find('\n', offset);
70 offset = next == std::string::npos ? std::string::npos : next + 1;
71 }
72 if (offset == std::string::npos) {
73 *text += newline + line;
74 } else {
75 text->insert(offset, line);
76 }
77
79 return false;
80 }
81 inserted = true;
82 return true;
83}