From b38b5e7974d9ba63ab1e5f257cfd0a4d7c463c0f Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Tue, 29 Sep 2020 20:10:05 +0200 Subject: Erste Version, die Daten extrahiert... --- src/srcut.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 10 deletions(-) (limited to 'src/srcut.cpp') diff --git a/src/srcut.cpp b/src/srcut.cpp index 194cc65..042608e 100644 --- a/src/srcut.cpp +++ b/src/srcut.cpp @@ -1,34 +1,105 @@ #include #include +#include +#include #include +#include using namespace std; -static void -process(istream& in, ostream& os) +istream& +operator>>(istream& in, map>& container) { - auto match_begin = [](string_view s) -> bool { - return s.empty(); + auto is_comment = [](string_view s) -> bool { + return s == "//" || s == "/*" || s == "#" || s == "--"; }; - auto match_end = [](string_view s) -> bool { - return s.empty(); + // --8<-- match_begin + auto match_begin = [&is_comment](const string& line, string& name) -> bool { + stringstream ss{ line }; + + string comment, cut_mark; + + if ( !(ss >> comment >> cut_mark >> name) ) { + return false; + } + + if ( !is_comment(comment) ) { + return false; + } + + if ( cut_mark != "--8<--" ) { + return false; + } + + return true; + }; + // -->8-- + + // --8<-- match_end + auto match_end = [&is_comment](const string& line) -> bool { + stringstream ss{ line }; + + string comment, cut_mark; + + if ( !(ss >> comment >> cut_mark) ) { + return false; + } + + if ( !is_comment(comment) ) { + return false; + } + + if ( cut_mark != "-->8--" ) { + return false; + } + + return true; }; + // -->8-- + vector chunks; for ( string line; getline(in, line); ) { - if ( match_begin(line) ) { + string marker; + if ( match_begin(line, marker) ) { + chunks.emplace_back(marker); } else if ( match_end(line) ) { + if ( !chunks.empty() ) { + chunks.pop_back(); + } } else { - os << line << '\n'; + for ( const auto& chunk: chunks ) { + container[chunk].emplace_back(line); + } } } - os << flush; + + return in; +} + +ostream& +operator<<(ostream& os, const map>& container) +{ + for ( const auto& chunk: container ) { + os << "CHUNK: " << chunk.first << '\n'; + auto line = begin(chunk.second); + while ( line != end(chunk.second) ) { + os << *line << '\n'; + + ++line; + } + os << "-------\n\n"; + } + return os; } int main(void) { - process(cin); + map> container; + + cin >> container; + cout << container; } -- cgit v1.3