openfoam/applications/test/stringList/Test-stringList.C
Mark Olesen 96a1b86fb9 ENH: consistency improvements for keyType and wordRe
- simplify compile/uncompile, reading, assignment

- implicit construct wordRe from keyType (was explicit) to simplify
  future API changes.

- make Foam::isspace consistent with std::isspace (C-locale)
  by including vertical tab and form feed

ENH: improve #ifeq float/label comparisons
2021-04-19 16:33:42 +00:00

115 lines
3.3 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "stringListOps.H"
#include "ListOps.H"
#include "FlatOutput.H"
#include "IOstreams.H"
#include "StringStream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
stringList strings
{
"hello",
"heello",
"heeello",
"bye",
"bbye",
"bbbye",
"okey",
"okkey",
"okkkey",
};
labelList matches;
wordRes matcher1(IStringStream("( okey \"[hy]e+.*\" )")());
Info<< "stringList " << strings << nl;
{
keyType key(".*ee.*", keyType::REGEX);
matches = findMatchingStrings(regExp(key), strings);
Info<< "matches found for regexp " << key << " :" << nl
<< matches << nl;
for (const label idx : matches)
{
Info<< " -> " << strings[idx] << nl;
}
}
Info<< "Match found using ListOps = "
<< ListOps::found(strings, regExp(".*ee.*")) << nl;
Info<< "First index = "
<< ListOps::find(strings, regExp(".*ee.*")) << nl;
Info<< endl;
matches = findMatchingStrings(matcher1, strings);
Info<< "matching " << flatOutput(matcher1) << " => "
<< matcher1.matching(strings) << nl;
Info<< "matches found for " << flatOutput(matcher1) << " => "
<< matches << nl;
for (const label idx : matches)
{
Info<< " -> " << strings[idx] << nl;
}
Info<< endl;
stringList subLst = subsetStrings(regExp(".*ee.*"), strings);
Info<< "subset stringList: " << subLst << nl;
subLst = subsetStrings(matcher1, strings);
Info<< "subset stringList: " << subLst << nl;
inplaceSubsetStrings(matcher1, strings);
Info<< "subsetted stringList: " << strings << nl;
inplaceSubsetStrings(regExp(".*l.*"), strings);
Info<< "subsetted stringList: " << strings << nl;
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //