Skip to content

Commit 9a0b59b

Browse files
authored
Merge pull request #6712 from bangerth/regex
Fix a regex.
2 parents 26b3cda + 8f16e43 commit 9a0b59b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

source/main.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ namespace
7575
{
7676
std::string return_value;
7777

78+
// Declare the regex we would like to match against each line of the
79+
// input file. Make sure we have a \r at the very end because the '.'
80+
// operator matches every printable character but not special ones
81+
// like \r. As a consequence, a line that ends in a Windows-style
82+
// \r would not match this regex even if it sets the correct parameter.
83+
//
84+
// We will deal with the presence of Windows line endings on Unix systems
85+
// in the places where we call this function, and so include the \r
86+
// in the second match group.
87+
const std::regex regex ("set[ \t]+" + parameter_name + "[ \t]*=[ \t]*(.*\r?)");
88+
7889
std::istringstream x_file(parameters);
7990
while (x_file)
8091
{
@@ -91,7 +102,6 @@ namespace
91102
line.erase(line.size() - 1, std::string::npos);
92103

93104
std::match_results<std::string::const_iterator> matches;
94-
const std::regex regex ("set[ \t]+" + parameter_name + "[ \t]*=[ \t]*(.*)");
95105
if (std::regex_match(line, matches, regex))
96106
{
97107
// Since the line as a whole matched, the 'matches' variable needs to

0 commit comments

Comments
 (0)