ENH: stringOps removeComments and inplaceRemoveComments

- useful for manual handling of string with comments
This commit is contained in:
Mark Olesen
2019-09-24 08:25:32 +02:00
committed by Andrew Heather
parent 603849383d
commit 13967565a6
3 changed files with 136 additions and 2 deletions

View File

@ -44,6 +44,20 @@ Description
using namespace Foam;
void testCommentStripping(const std::string& s)
{
Info<< "input" << nl
<< "========" << nl
<< s << nl
<< "========" << nl;
Info<< "output" << nl
<< "========" << nl
<< stringOps::removeComments(s) << nl
<< "========" << nl << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -158,6 +172,35 @@ int main(int argc, char *argv[])
Info<<"trimRight: " << stringOps::trimRight(test) << endl;
Info<<"trim: " << stringOps::trim(test) << endl;
// Test comment stripping
{
Info<< nl << "Test comment stripping" << nl;
testCommentStripping
(
"/String without comments/"
);
testCommentStripping
(
"Removed some/* C-comments */ / C comments"
);
testCommentStripping
(
"Removed some//C++ comments\n / C++ comments"
);
testCommentStripping
(
"Partly degenerate C comment </*/ C-comment..."
);
testCommentStripping
(
"Truncated C comment </* C-comment..."
);
testCommentStripping
(
"Truncated C++ comment <// C++ comment..."
);
}
if (false)
{
Info<<"test move construct - string size:" << test.size() << nl;