GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — learnmoderncpp-tutorial/scripts/extract-code.cpp at main · cpp-tutor/learnmoderncpp-tutorial Expand file tree/ Copy pathextract-code.cppMore file actions 57 lines (55 loc) · 1.88 KB / Copy pathextract-code.cppFile metadata and controls57 lines (55 loc) · 1.88 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 // extract-code.cpp : Scan a Markdown file for C++ programs #include <string> #include <sstream> #include <regex> #include <vector> #include <iostream> #include <fstream> using namespace std; int main(const int argc, const char **argv) { vector<string_view> args{ argv + 1, argv + argc }; for (const auto& filename : args) { cout << "- " << filename << ":\n"; string input_file, line; ifstream infile{ filename.data() }; if (!infile) { cerr << "Error opening file: " << filename << '\n'; return 1; } for (;;) { getline(infile, line); if (infile.eof()) { break; } input_file += line + '\n'; } infile.close(); istringstream iss{ input_file }; while (!iss.eof()) { getline(iss, line); if ((line != "```cpp") && (line != "```")) { continue; } bool no_cpp = line == "```"; getline(iss, line); regex is_cpp { R"(^// ([[:alnum:]_-]+\.cpp) :)" }; smatch matches; if (regex_search(line, matches, is_cpp)) { cerr << "Filename: " << matches[1] << (no_cpp ? " (no type)" : "") << '\n'; } string output_file = matches[1]; ofstream header{ "headers\\"s + output_file, ios_base::binary }, module{ "modules\\"s + output_file, ios_base::binary }; while (line != "```") { header << line << '\n'; if (line == "using namespace std;") { module << "import std;\n"; } if (line.substr(0, 8) != "#include") { module << line << '\n'; } getline(iss, line); } } } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |