mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve space handling for removeComments
- include the trailing newline for the "// comment" form, but also add in leading space removal. This ensure that we do not introduce odd indentation, while also eliminating lines that are solely C++ comments.
This commit is contained in:
@ -1108,8 +1108,26 @@ void Foam::stringOps::inplaceRemoveComments(std::string& s)
|
|||||||
|
|
||||||
if (c == '/')
|
if (c == '/')
|
||||||
{
|
{
|
||||||
// C++ comment - search for end-of-line
|
// C++ comment - remove to end-of-line
|
||||||
|
|
||||||
--n;
|
--n;
|
||||||
|
s[n] = '\n';
|
||||||
|
|
||||||
|
// Backtrack to eliminate leading spaces,
|
||||||
|
// up to the previous newline
|
||||||
|
|
||||||
|
while (n && std::isspace(s[n-1]))
|
||||||
|
{
|
||||||
|
--n;
|
||||||
|
|
||||||
|
if (s[n] == '\n')
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s[n] = '\n';
|
||||||
|
}
|
||||||
|
|
||||||
i = s.find('\n', ++i);
|
i = s.find('\n', ++i);
|
||||||
|
|
||||||
if (i == std::string::npos)
|
if (i == std::string::npos)
|
||||||
@ -1117,6 +1135,8 @@ void Foam::stringOps::inplaceRemoveComments(std::string& s)
|
|||||||
// Trucated - done
|
// Trucated - done
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++n; // Include newline in output
|
||||||
}
|
}
|
||||||
else if (c == '*')
|
else if (c == '*')
|
||||||
{
|
{
|
||||||
@ -1130,7 +1150,7 @@ void Foam::stringOps::inplaceRemoveComments(std::string& s)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
++i;
|
++i; // Index past first of "*/", loop increment does the rest
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1144,7 +1164,7 @@ void Foam::stringOps::inplaceRemoveComments(std::string& s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.resize(n);
|
s.erase(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user