From 56b5d03fed5b58a1910034afdbd78d80235c6361 Mon Sep 17 00:00:00 2001 From: An Tao Date: Thu, 18 Jun 2020 21:44:54 +0800 Subject: [PATCH] Remove the restriction on the location of layout tags in views (#484) --- drogon_ctl/create_view.cc | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drogon_ctl/create_view.cc b/drogon_ctl/create_view.cc index 7c23669f..b338ef30 100644 --- a/drogon_ctl/create_view.cc +++ b/drogon_ctl/create_view.cc @@ -350,16 +350,25 @@ void create_view::newViewSourceFile(std::ofstream &file, file << "#include \n"; file << "#include \n"; file << "#include \n"; - - // file << "using namespace std;\n"; - // file <<"void __attribute__((constructor)) startup()\n"; - // file <<"{std::cout<<\"dynamic lib start to load!\"<"); for (std::string buffer; std::getline(infile, buffer);) + { + std::smatch results; + if (std::regex_search(buffer, results, layoutReg)) + { + if (results.size() > 1) + { + layoutName = results[1].str(); + break; + } + } + } + infile.clear(); + infile.seekg(0, std::ifstream::beg); + bool import_flag{false}; + for (std::string buffer; std::getline(infile, buffer);) { std::string::size_type pos(0); @@ -370,20 +379,11 @@ void create_view::newViewSourceFile(std::ofstream &file, lowerBuffer.end(), lowerBuffer.begin(), ::tolower); - std::smatch results; - if (std::regex_search(buffer, results, layoutReg)) - { - if (results.size() > 1) - { - layoutName = results[1].str(); - continue; - } - } if ((pos = lowerBuffer.find(cxx_include)) != std::string::npos) { // std::cout<<"haha find it!"<