mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: disentangle testing and quoting of regex characters
- originally had tests for regex meta characters strewn across regExp classes as well as wordRe, keyType, string. And had special-purpose quotemeta static function within string that relied on special naming convention for testing the meta characters. The regex meta character testing/handling now relegated entirely to the regExp class(es). Relocate quotemeta to stringOps, with a predicate. - avoid code duplication. Reuse some regExpCxx methods in regExpPosix
This commit is contained in:
committed by
Andrew Heather
parent
cdbc3e2de6
commit
57c1fceabf
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -140,8 +141,8 @@ int main(int argc, char *argv[])
|
||||
bool changed = false;
|
||||
for (label orig = 0; orig < names.size()-1; ++orig)
|
||||
{
|
||||
// skip patterns or entries that have already been done
|
||||
if (names[orig].empty() || wordRe::isPattern(names[orig]))
|
||||
// Skip patterns or entries that have already been done
|
||||
if (names[orig].empty() || regExp::is_meta(names[orig]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -150,15 +151,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
for (label check = orig+1; check < names.size(); ++check)
|
||||
{
|
||||
// skip patterns or entries that have already been done
|
||||
if (names[check].empty() || wordRe::isPattern(names[check]))
|
||||
// Skip patterns or entries that have already been done
|
||||
if (names[check].empty() || regExp::is_meta(names[check]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const dictionary& dict2 = solverDict.subDict(names[check]);
|
||||
|
||||
// check for identical content
|
||||
// Check for identical content
|
||||
if (checkDictionaryContent(dict1, dict2))
|
||||
{
|
||||
names[orig] += "|" + names[check];
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -34,6 +34,7 @@ Description
|
||||
#include "IFstream.H"
|
||||
#include "Switch.H"
|
||||
|
||||
#include "stringOps.H"
|
||||
#include "SubStrings.H"
|
||||
#include "regExpCxx.H"
|
||||
#ifndef _WIN32
|
||||
@ -294,19 +295,16 @@ int main(int argc, char *argv[])
|
||||
argList::noFunctionObjects();
|
||||
argList::noParallel();
|
||||
|
||||
argList::addBoolOption
|
||||
(
|
||||
"cxx",
|
||||
"Test C++11 regular expressions"
|
||||
);
|
||||
|
||||
argList::addBoolOption("cxx", "Test C++11 regular expressions");
|
||||
#ifndef _WIN32
|
||||
argList::addBoolOption
|
||||
(
|
||||
"posix",
|
||||
"Test POSIX regular expressions"
|
||||
);
|
||||
argList::addBoolOption("posix", "Test POSIX regular expressions");
|
||||
#endif
|
||||
argList::addOption
|
||||
(
|
||||
"regex",
|
||||
"expression",
|
||||
"regular expression to test"
|
||||
);
|
||||
|
||||
argList::addArgument("file");
|
||||
argList::addArgument("...");
|
||||
@ -315,24 +313,50 @@ int main(int argc, char *argv[])
|
||||
|
||||
#include "setRootCase.H"
|
||||
|
||||
// Newer compilers support regex directly
|
||||
#ifdef _GLIBCXX_RELEASE
|
||||
Info<< "_GLIBCXX_RELEASE = " << (_GLIBCXX_RELEASE) << nl;
|
||||
#endif
|
||||
|
||||
if (std::is_same<regExp, regExpCxx>::value)
|
||||
{
|
||||
Info<<"Foam::regExp uses C++11 regex" << nl << nl;
|
||||
Info<< "Foam::regExp uses C++11 regex" << nl;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
if (std::is_same<regExp, regExpPosix>::value)
|
||||
{
|
||||
Info<<"Foam::regExp uses POSIX regex" << nl << nl;
|
||||
Info<< "Foam::regExp uses POSIX regex" << nl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!args.count({"cxx", "posix"}))
|
||||
{
|
||||
Info<< "Specified one or more of -cxx, -posix" << nl;
|
||||
return 1;
|
||||
args.setOption("cxx");
|
||||
Info<< "Assuming -cxx as default" << nl;
|
||||
}
|
||||
Info<< nl;
|
||||
|
||||
if (args.size() < 2)
|
||||
if (args.found("regex"))
|
||||
{
|
||||
std::string expr(args["regex"]);
|
||||
Info<< "regex: " << expr << nl;
|
||||
|
||||
Info<< "(cxx)" << nl
|
||||
<< "meta : " << Switch(regExpCxx::is_meta(expr)) << nl
|
||||
<< "quotemeta: "
|
||||
<< stringOps::quotemeta(expr, regExpCxx::meta()) << nl
|
||||
<< nl;
|
||||
|
||||
#ifndef _WIN32
|
||||
Info<< "(posix):" << nl
|
||||
<< "meta : " << Switch(regExpPosix::is_meta(expr)) << nl
|
||||
<< "quotemeta: "
|
||||
<< stringOps::quotemeta(expr, regExpPosix::meta()) << nl
|
||||
<< nl;
|
||||
#endif
|
||||
Info<< nl;
|
||||
}
|
||||
else if (args.size() < 2)
|
||||
{
|
||||
Info<< "No test files specified .. restrict to general tests" << nl;
|
||||
|
||||
@ -351,7 +375,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
for (label argi = 1; argi < args.size(); ++argi)
|
||||
{
|
||||
List<regexTest> tests(IFstream(args[argi])());
|
||||
IFstream is(args[argi]);
|
||||
List<regexTest> tests(is);
|
||||
|
||||
Info<< "Test expressions:" << tests << endl;
|
||||
IOobject::writeDivider(Info) << endl;
|
||||
|
||||
Reference in New Issue
Block a user