STYLE: single-string findStrings deprecated in favour of stringOps::match

- reduces ambiguity between matching a list of strings and a single string.
This commit is contained in:
Mark Olesen
2017-11-13 10:37:38 +01:00
parent 5a6b59d8b0
commit 14d4484fae
8 changed files with 25 additions and 23 deletions

View File

@ -79,7 +79,7 @@ Usage
#include "tensorIOField.H" #include "tensorIOField.H"
#include "passiveParticleCloud.H" #include "passiveParticleCloud.H"
#include "faceSet.H" #include "faceSet.H"
#include "stringListOps.H" #include "stringOps.H"
#include "wordReList.H" #include "wordReList.H"
#include "meshSubsetHelper.H" #include "meshSubsetHelper.H"
@ -137,7 +137,7 @@ labelList getSelectedPatches
Info<< " discarding empty/processor patch " << patchi Info<< " discarding empty/processor patch " << patchi
<< " " << pp.name() << endl; << " " << pp.name() << endl;
} }
else if (findStrings(excludePatches, pp.name())) else if (stringOps::match(excludePatches, pp.name()))
{ {
Info<< " excluding patch " << patchi Info<< " excluding patch " << patchi
<< " " << pp.name() << endl; << " " << pp.name() << endl;

View File

@ -154,7 +154,7 @@ Note
#include "faceZoneMesh.H" #include "faceZoneMesh.H"
#include "Cloud.H" #include "Cloud.H"
#include "passiveParticle.H" #include "passiveParticle.H"
#include "stringListOps.H" #include "stringOps.H"
#include "meshSubsetHelper.H" #include "meshSubsetHelper.H"
#include "readFields.H" #include "readFields.H"
@ -1172,7 +1172,7 @@ int main(int argc, char *argv[])
{ {
const polyPatch& pp = patches[patchi]; const polyPatch& pp = patches[patchi];
if (findStrings(excludePatches, pp.name())) if (stringOps::match(excludePatches, pp.name()))
{ {
// Skip excluded patch // Skip excluded patch
continue; continue;

View File

@ -44,19 +44,14 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Single-string matches: //- Single-string match for one of the regular expressions
// \deprecated use stringOps::match instead (deprecated NOV-2017)
//- Return true if text matches one of the regular expressions
// The primary purpose of this function is to automatically convert
// a wordReList to a wordRes for matching.
inline bool findStrings(const wordRes& matcher, const std::string& text) inline bool findStrings(const wordRes& matcher, const std::string& text)
{ {
return matcher(text); return matcher(text);
} }
// Multi-string matches:
//- Extract list indices //- Extract list indices
// The unary match predicate has the following signature: // The unary match predicate has the following signature:
// \code // \code

View File

@ -42,6 +42,7 @@ SourceFiles
#include "dictionary.H" #include "dictionary.H"
#include "HashTable.H" #include "HashTable.H"
#include "stringOpsSort.H" #include "stringOpsSort.H"
#include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -61,6 +62,13 @@ namespace stringOps
// Correctly handles nullptr. // Correctly handles nullptr.
std::string::size_type count(const char* str, const char c); std::string::size_type count(const char* str, const char c);
//- Return true if text matches one of the regular expressions.
// Simply forwards a wordReList to a wordRes for the matching.
inline bool match(const wordReList& patterns, const std::string& text)
{
return wordRes(patterns).match(text);
}
//- Expand occurences of variables according to the mapping //- Expand occurences of variables according to the mapping
// Expansion includes: // Expansion includes:

View File

@ -23,7 +23,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::wordRes::wordRes inline Foam::wordRes::wordRes

View File

@ -30,7 +30,7 @@ Description
#include "SLList.H" #include "SLList.H"
#include "Ostream.H" #include "Ostream.H"
#include "stringListOps.H" #include "stringOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -109,21 +109,21 @@ public:
{ {
List<word> matched(SLList<T>::size()); List<word> matched(SLList<T>::size());
label matchI = 0; label matchi = 0;
forAllConstIters(*this, iter) forAllConstIters(*this, iter)
{ {
const word& name = iter().name(); const word& name = iter().name();
if if
( (
findStrings(whiteLst, name) stringOps::match(whiteLst, name)
&& !findStrings(blackLst, name) && !stringOps::match(blackLst, name)
) )
{ {
matched[matchI++] = name; matched[matchi++] = name;
} }
} }
matched.setSize(matchI); matched.setSize(matchi);
return matched; return matched;
} }

View File

@ -26,7 +26,7 @@ License
#include "boundaryRegion.H" #include "boundaryRegion.H"
#include "IOMap.H" #include "IOMap.H"
#include "OFstream.H" #include "OFstream.H"
#include "stringListOps.H" #include "stringOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -109,7 +109,7 @@ Foam::Map<Foam::word> Foam::boundaryRegion::names
"boundaryRegion_" + Foam::name(iter.key()) "boundaryRegion_" + Foam::name(iter.key())
); );
if (findStrings(patterns, lookupName)) if (stringOps::match(patterns, lookupName))
{ {
lookup.insert(iter.key(), lookupName); lookup.insert(iter.key(), lookupName);
} }

View File

@ -27,7 +27,7 @@ License
#include "IOMap.H" #include "IOMap.H"
#include "OFstream.H" #include "OFstream.H"
#include "wordList.H" #include "wordList.H"
#include "stringListOps.H" #include "stringOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -179,7 +179,7 @@ Foam::Map<Foam::word> Foam::cellTable::names
"cellTable_" + Foam::name(iter.key()) "cellTable_" + Foam::name(iter.key())
); );
if (findStrings(patterns, lookupName)) if (stringOps::match(patterns, lookupName))
{ {
lookup.insert(iter.key(), lookupName); lookup.insert(iter.key(), lookupName);
} }
@ -523,7 +523,7 @@ void Foam::cellTable::combine(const dictionary& mapDict, labelList& tableIds)
Map<word> matches; Map<word> matches;
forAllConstIter(Map<word>, origNames, namesIter) forAllConstIter(Map<word>, origNames, namesIter)
{ {
if (findStrings(patterns, namesIter())) if (stringOps::match(patterns, namesIter()))
{ {
matches.insert(namesIter.key(), namesIter()); matches.insert(namesIter.key(), namesIter());
} }