From 0f3f6a2332a3187e866c8a3fba985068a7598a88 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Thu, 23 Jan 2020 18:45:02 +0100
Subject: [PATCH] =?UTF-8?q?Add=20comments=20and=20simplify=20code=20in=20f?=
 =?UTF-8?q?unction=20that=20parses=20the=20--+=20options:=20=E2=80=A6=20+-?=
 =?UTF-8?q?-=20line?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/DynareMain.cc | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/DynareMain.cc b/src/DynareMain.cc
index 149d7f27..41c9c7a0 100644
--- a/src/DynareMain.cc
+++ b/src/DynareMain.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2003-2019 Dynare Team
+ * Copyright © 2003-2020 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -68,8 +68,9 @@ usage()
   exit(EXIT_FAILURE);
 }
 
-/* Looks for an options list in the first line of the mod file (but rewind
-   the input stream afterwards */
+/* Looks for an options list in the first non-empty line of the .mod file (but rewind
+   the input stream afterwards).
+   This function should be kept in sync with the one with the same name in matlab/dynare.m */
 vector<string>
 parse_options_line(istream &modfile)
 {
@@ -79,16 +80,16 @@ parse_options_line(istream &modfile)
   smatch matches;
 
   while (getline(modfile, first_nonempty_line))
-    if (first_nonempty_line != "")
+    if (!first_nonempty_line.empty())
       {
         if (regex_search(first_nonempty_line, matches, pat)
             && matches.size() > 1 && matches[1].matched)
           {
-            regex pat2{R"(([^,\s]+))"};
+            regex pat2{R"([^,\s]+)"};
             string s{matches[1]};
             for (sregex_iterator p(s.begin(), s.end(), pat2);
                  p != sregex_iterator{}; ++p)
-              options.push_back((*p)[1]);
+              options.push_back(p->str());
           }
         break;
       }
-- 
GitLab