From 13967565a611d7de5c0f2bc688cadc0d6ba25b30 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 24 Sep 2019 08:25:32 +0200 Subject: [PATCH] ENH: stringOps removeComments and inplaceRemoveComments - useful for manual handling of string with comments --- applications/test/string/Test-string.C | 43 ++++++++++ .../primitives/strings/stringOps/stringOps.C | 86 ++++++++++++++++++- .../primitives/strings/stringOps/stringOps.H | 9 +- 3 files changed, 136 insertions(+), 2 deletions(-) diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index e3adafffab..46257c117b 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.C @@ -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