Commit 10cbd9bc authored by GILLES Sebastien's avatar GILLES Sebastien

#1475 Better error message when unbalanced braces in the input file.

parent 386aae41
......@@ -392,13 +392,37 @@ namespace MoReFEM
oconv << "Last brace found in the file " << file_ << " is an opening one!";
throw Exception(oconv.str(), __FILE__, __LINE__);
}
}
// Check there are an equal number of opening and closing braces.
auto opening_brace_lbd = [](int i)
{
return i > 0;
};
auto closing_brace_lbd = [](int i)
{
return i < 0;
};
const auto Nopening_brace = std::count_if(brace_position_list_.cbegin(),
brace_position_list_.cend(),
opening_brace_lbd);
const auto Nclosing_brace = std::count_if(brace_position_list_.cbegin(),
brace_position_list_.cend(),
closing_brace_lbd);
if (Nopening_brace != Nclosing_brace)
{
std::ostringstream oconv;
oconv << "Unbalanced braces in the file " << file_ << ": there is " << Nopening_brace << " '{'"
<< " and " << Nclosing_brace << " '}' [the ones related to maps or in comments aren't counted].";
throw Exception(oconv.str(), __FILE__, __LINE__);
}
// Pair the braces together.
std::vector<std::pair<std::size_t, std::size_t>> pair_list;
auto copy = brace_position_list_;
......@@ -415,10 +439,7 @@ namespace MoReFEM
// Find first negative value.
auto it = std::find_if(copy.cbegin(),
copy.cend(),
[](int i)
{
return i < 0;
});
closing_brace_lbd);
assert(it != copy.cend());
assert(it != copy.cbegin());
......
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