Add comments and simplify code in function that parses the --+ options: … +-- line

parent 8496e828
/* /*
* Copyright © 2003-2019 Dynare Team * Copyright © 2003-2020 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -68,8 +68,9 @@ usage() ...@@ -68,8 +68,9 @@ usage()
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Looks for an options list in the first line of the mod file (but rewind /* Looks for an options list in the first non-empty line of the .mod file (but rewind
the input stream afterwards */ the input stream afterwards).
This function should be kept in sync with the one with the same name in matlab/dynare.m */
vector<string> vector<string>
parse_options_line(istream &modfile) parse_options_line(istream &modfile)
{ {
...@@ -79,16 +80,16 @@ parse_options_line(istream &modfile) ...@@ -79,16 +80,16 @@ parse_options_line(istream &modfile)
smatch matches; smatch matches;
while (getline(modfile, first_nonempty_line)) while (getline(modfile, first_nonempty_line))
if (first_nonempty_line != "") if (!first_nonempty_line.empty())
{ {
if (regex_search(first_nonempty_line, matches, pat) if (regex_search(first_nonempty_line, matches, pat)
&& matches.size() > 1 && matches[1].matched) && matches.size() > 1 && matches[1].matched)
{ {
regex pat2{R"(([^,\s]+))"}; regex pat2{R"([^,\s]+)"};
string s{matches[1]}; string s{matches[1]};
for (sregex_iterator p(s.begin(), s.end(), pat2); for (sregex_iterator p(s.begin(), s.end(), pat2);
p != sregex_iterator{}; ++p) p != sregex_iterator{}; ++p)
options.push_back((*p)[1]); options.push_back(p->str());
} }
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment