mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: cleanup wordRe interfaces etc.
- ensure that the string-related classes have consistently similar
matching methods. Use operator()(const std::string) as an entry
point for the match() method, which makes it easier to use for
filters and predicates. In some cases this will also permit using
a HashSet as a match predicate.
regExp
====
- the set method now returns a bool to signal that the requested
pattern was compiled.
wordRe
====
- have separate constructors with the compilation option (was previously
a default parameter). This leaves the single parameter constructor
explicit, but the two parameter version is now non-explicit, which
makes it easier to use when building lists.
- renamed compile-option from REGEX (to REGEXP) for consistency with
with the <regex.h>, <regex> header names etc.
wordRes
====
- renamed from wordReListMatcher -> wordRes. For reduced typing and
since it behaves as an entity only slightly related to its underlying
list nature.
- Provide old name as typedef and include for code transition.
- pass through some list methods into wordRes
hashedWordList
====
- hashedWordList[const word& name] now returns a -1 if the name is is
not found in the list of indices. That has been a pending change
ever since hashedWordList was generalized out of speciesTable
(Oct-2010).
- add operator()(const word& name) for easy use as a predicate
STYLE: adjust parameter names in stringListOps
- reflect if the parameter is being used as a primary matcher, or the
matcher will be derived from the parameter.
For example,
(const char* re), which first creates a regExp
versus (const regExp& matcher) which is used directly.
This commit is contained in:
@ -180,9 +180,9 @@ int main(int argc, char *argv[])
|
|||||||
// A regex with a zero length matcher doesn't work at all:
|
// A regex with a zero length matcher doesn't work at all:
|
||||||
// eg "(png|jpg|txt|)" regex matcher itself
|
// eg "(png|jpg|txt|)" regex matcher itself
|
||||||
|
|
||||||
wordRe matcher0("()", wordRe::REGEXP);
|
wordRe matcher0("()", wordRe::REGEX);
|
||||||
wordRe matcher1("(png|jpg|txt)", wordRe::REGEXP);
|
wordRe matcher1("(png|jpg|txt)", wordRe::REGEX);
|
||||||
wordRe matcher2("(png|txt)", wordRe::REGEXP);
|
wordRe matcher2("(png|txt)", wordRe::REGEX);
|
||||||
|
|
||||||
Info<<"Has extension(s):" << nl
|
Info<<"Has extension(s):" << nl
|
||||||
<< "input: " << endWithDot << nl;
|
<< "input: " << endWithDot << nl;
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -30,7 +30,9 @@ Description
|
|||||||
#include "IFstream.H"
|
#include "IFstream.H"
|
||||||
#include "List.H"
|
#include "List.H"
|
||||||
#include "Tuple2.H"
|
#include "Tuple2.H"
|
||||||
|
#include "keyType.H"
|
||||||
#include "wordRe.H"
|
#include "wordRe.H"
|
||||||
|
#include "wordRes.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -44,12 +46,36 @@ int main(int argc, char *argv[])
|
|||||||
Foam::string s2("this .* file");
|
Foam::string s2("this .* file");
|
||||||
const char * s3 = "this .* file";
|
const char * s3 = "this .* file";
|
||||||
|
|
||||||
|
keyType keyre("x.*", true);
|
||||||
|
|
||||||
|
wordReList wordrelist
|
||||||
|
{
|
||||||
|
{"this", wordRe::LITERAL},
|
||||||
|
{"x.*", wordRe::REGEX},
|
||||||
|
{"file[a-b]", wordRe::REGEX},
|
||||||
|
};
|
||||||
|
|
||||||
|
wordRes wrelist(wordrelist);
|
||||||
|
|
||||||
|
Info<< "re-list:" << wrelist() << endl;
|
||||||
|
Info<< "match this: " << wrelist("this") << endl;
|
||||||
|
Info<< "match xyz: " << wrelist("xyz") << endl;
|
||||||
|
Info<< "match zyx: " << wrelist("zyx") << endl;
|
||||||
|
Info<< "match xyz: " << wrelist.match("xyz") << endl;
|
||||||
|
Info<< "keyre match: " << keyre("xyz") << endl;
|
||||||
|
Info<< "string match: " << string("this").match("xyz") << endl;
|
||||||
|
Info<< "string match: " << string("x.*")("xyz") << endl;
|
||||||
|
Info<< "string match: " << string("x.*")(keyre) << endl;
|
||||||
|
|
||||||
wordRe(s1, wordRe::DETECT).info(Info) << endl;
|
wordRe(s1, wordRe::DETECT).info(Info) << endl;
|
||||||
wordRe(s2).info(Info) << endl;
|
wordRe(s2).info(Info) << endl;
|
||||||
wordRe(s2, wordRe::DETECT).info(Info) << endl;
|
wordRe(s2, wordRe::DETECT).info(Info) << endl;
|
||||||
wordRe(s3, wordRe::REGEXP).info(Info) << endl;
|
wordRe(s3, wordRe::REGEX).info(Info) << endl;
|
||||||
|
|
||||||
wre = "this .* file";
|
wre = "this .* file";
|
||||||
|
|
||||||
|
Info<<"substring: " << wre(4) << endl;
|
||||||
|
|
||||||
wre.info(Info) << endl;
|
wre.info(Info) << endl;
|
||||||
wre = s1;
|
wre = s1;
|
||||||
wre.info(Info) << endl;
|
wre.info(Info) << endl;
|
||||||
|
|||||||
@ -24,7 +24,7 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "doxygenXmlParser.H"
|
#include "doxygenXmlParser.H"
|
||||||
#include "wordRe.H"
|
#include "regExp.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -40,8 +40,8 @@ Foam::doxygenXmlParser::doxygenXmlParser
|
|||||||
dictionary(dictionary::null)
|
dictionary(dictionary::null)
|
||||||
{
|
{
|
||||||
// Pre-construct and compile regular expressions
|
// Pre-construct and compile regular expressions
|
||||||
const wordRe nameRe(".*.H", wordRe::DETECT);
|
const regExp nameRe(".*.H");
|
||||||
const wordRe searchStrRe(searchStr, wordRe::DETECT);
|
const regExp searchStrRe(searchStr);
|
||||||
|
|
||||||
// Pre-construct constant strings and names to speed-up comparisons
|
// Pre-construct constant strings and names to speed-up comparisons
|
||||||
const string slashStartTag('/' + startTag);
|
const string slashStartTag('/' + startTag);
|
||||||
@ -163,7 +163,7 @@ Foam::doxygenXmlParser::doxygenXmlParser
|
|||||||
(
|
(
|
||||||
!exactMatch
|
!exactMatch
|
||||||
&& !found(tName) // not already added
|
&& !found(tName) // not already added
|
||||||
&& wordRe(".*" + tName + ".*", wordRe::DETECT).match(name)
|
&& regExp(".*" + tName + ".*").match(name)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
dictionary dict(dictionary::null);
|
dictionary dict(dictionary::null);
|
||||||
|
|||||||
@ -199,7 +199,7 @@ void print(Ostream& os, const wordList& flds)
|
|||||||
labelList getSelectedPatches
|
labelList getSelectedPatches
|
||||||
(
|
(
|
||||||
const polyBoundaryMesh& patches,
|
const polyBoundaryMesh& patches,
|
||||||
const List<wordRe>& excludePatches
|
const wordRes& excludePatches
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DynamicList<label> patchIDs(patches.size());
|
DynamicList<label> patchIDs(patches.size());
|
||||||
@ -219,7 +219,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 (excludePatches.match(pp.name()))
|
||||||
{
|
{
|
||||||
Info<< " excluding patch " << patchi
|
Info<< " excluding patch " << patchi
|
||||||
<< " " << pp.name() << endl;
|
<< " " << pp.name() << endl;
|
||||||
@ -379,7 +379,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
const bool allPatches = args.optionFound("allPatches");
|
const bool allPatches = args.optionFound("allPatches");
|
||||||
|
|
||||||
List<wordRe> excludePatches;
|
wordReList excludePatches;
|
||||||
if (args.optionFound("excludePatches"))
|
if (args.optionFound("excludePatches"))
|
||||||
{
|
{
|
||||||
args.optionLookup("excludePatches")() >> excludePatches;
|
args.optionLookup("excludePatches")() >> excludePatches;
|
||||||
|
|||||||
@ -169,7 +169,7 @@ void Foam::boundaryInfo::setType(const label patchI, const word& condition)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wordRe(".*[Mm]apped.*", wordRe::REGEXP).match(types_[patchI]))
|
if (regExp(".*[Mm]apped.*").match(types_[patchI]))
|
||||||
{
|
{
|
||||||
// ugly hack to avoid overriding mapped types
|
// ugly hack to avoid overriding mapped types
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -111,7 +111,7 @@ Foam::regExp::~regExp()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::regExp::set(const char* pattern, bool ignoreCase)
|
bool Foam::regExp::set(const char* pattern, bool ignoreCase)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ void Foam::regExp::set(const char* pattern, bool ignoreCase)
|
|||||||
// avoid zero-length patterns
|
// avoid zero-length patterns
|
||||||
if (!*pat)
|
if (!*pat)
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,11 +154,15 @@ void Foam::regExp::set(const char* pattern, bool ignoreCase)
|
|||||||
<< nl << errbuf
|
<< nl << errbuf
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false; // Was cleared and nothing was set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::regExp::set(const std::string& pattern, bool ignoreCase)
|
bool Foam::regExp::set(const std::string& pattern, bool ignoreCase)
|
||||||
{
|
{
|
||||||
return set(pattern.c_str(), ignoreCase);
|
return set(pattern.c_str(), ignoreCase);
|
||||||
}
|
}
|
||||||
@ -208,7 +212,7 @@ bool Foam::regExp::match(const std::string& text) const
|
|||||||
if
|
if
|
||||||
(
|
(
|
||||||
regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0
|
regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0
|
||||||
&& (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(text.size()))
|
&& (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == regoff_t(text.size()))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -128,20 +128,23 @@ public:
|
|||||||
|
|
||||||
// Editing
|
// Editing
|
||||||
|
|
||||||
//- Compile pattern into a regular expression, optionally ignore case
|
//- Compile pattern into a regular expression, optionally ignore case.
|
||||||
void set(const char* pattern, bool ignoreCase=false);
|
// \return True if the pattern was compiled
|
||||||
|
bool set(const char* pattern, bool ignoreCase=false);
|
||||||
|
|
||||||
//- Compile pattern into a regular expression, optionally ignore case
|
//- Compile pattern into a regular expression, optionally ignore case
|
||||||
void set(const std::string& pattern, bool ignoreCase=false);
|
// \return True if the pattern was compiled
|
||||||
|
bool set(const std::string& pattern, bool ignoreCase=false);
|
||||||
|
|
||||||
//- Clear expression, return true if expression had existed.
|
//- Clear expression.
|
||||||
|
// \return True if expression had existed prior to the clear.
|
||||||
bool clear();
|
bool clear();
|
||||||
|
|
||||||
|
|
||||||
// Matching/Searching
|
// Matching/Searching
|
||||||
|
|
||||||
//- Find position within string.
|
//- Find position within string.
|
||||||
// Returns the index where it begins or string::npos if not found
|
// \Return The index where it begins or string::npos if not found
|
||||||
std::string::size_type find(const std::string& text) const;
|
std::string::size_type find(const std::string& text) const;
|
||||||
|
|
||||||
//- Return true if it matches the entire string
|
//- Return true if it matches the entire string
|
||||||
@ -158,6 +161,9 @@ public:
|
|||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
|
//- Perform match on text
|
||||||
|
inline bool operator()(const std::string& text) const;
|
||||||
|
|
||||||
//- Assign and compile pattern from a character array
|
//- Assign and compile pattern from a character array
|
||||||
// Always case sensitive
|
// Always case sensitive
|
||||||
inline void operator=(const char* pattern);
|
inline void operator=(const char* pattern);
|
||||||
|
|||||||
@ -66,6 +66,12 @@ inline bool Foam::regExp::search(const std::string& text) const
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::regExp::operator()(const std::string& text) const
|
||||||
|
{
|
||||||
|
return match(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::regExp::operator=(const char* pattern)
|
inline void Foam::regExp::operator=(const char* pattern)
|
||||||
{
|
{
|
||||||
set(pattern);
|
set(pattern);
|
||||||
|
|||||||
@ -97,8 +97,8 @@ $(strings)/fileName/fileName.C
|
|||||||
$(strings)/fileName/fileNameIO.C
|
$(strings)/fileName/fileNameIO.C
|
||||||
$(strings)/keyType/keyType.C
|
$(strings)/keyType/keyType.C
|
||||||
$(strings)/wordRe/wordRe.C
|
$(strings)/wordRe/wordRe.C
|
||||||
|
$(strings)/wordRes/wordRes.C
|
||||||
$(strings)/lists/hashedWordList.C
|
$(strings)/lists/hashedWordList.C
|
||||||
$(strings)/lists/wordReListMatcher.C
|
|
||||||
$(strings)/stringOps/stringOps.C
|
$(strings)/stringOps/stringOps.C
|
||||||
|
|
||||||
ops = primitives/ops
|
ops = primitives/ops
|
||||||
|
|||||||
@ -169,7 +169,7 @@ Foam::IOobjectList Foam::IOobjectList::lookup(const wordRe& matcher) const
|
|||||||
|
|
||||||
Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& matcher) const
|
Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& matcher) const
|
||||||
{
|
{
|
||||||
wordReListMatcher mat(matcher);
|
wordRes mat(matcher);
|
||||||
|
|
||||||
IOobjectList results(size());
|
IOobjectList results(size());
|
||||||
|
|
||||||
|
|||||||
@ -52,13 +52,11 @@ bool Foam::keyType::match(const std::string& text, bool literal) const
|
|||||||
{
|
{
|
||||||
if (literal || !isPattern_)
|
if (literal || !isPattern_)
|
||||||
{
|
{
|
||||||
// check as string
|
return !compare(text); // Compare as literal string
|
||||||
return (text == *this);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// check as regex
|
return regExp(*this).match(text); // Match as regex
|
||||||
return regExp(*this).match(text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -121,19 +121,26 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
// Assignment
|
//- Avoid masking the normal operator()
|
||||||
|
using word::operator();
|
||||||
|
|
||||||
//- Assignment operator, retaining type (literal or regex)
|
//- Perform smart match on text
|
||||||
inline void operator=(const keyType& s);
|
inline bool operator()(const std::string& text) const;
|
||||||
|
|
||||||
//- Assign as word, not treated as a regular expression.
|
|
||||||
inline void operator=(const word& s);
|
|
||||||
|
|
||||||
//- Assign as regular expression
|
// Assignment
|
||||||
inline void operator=(const string& s);
|
|
||||||
|
|
||||||
//- Assign as word, not treated as a regular expression.
|
//- Assignment operator, retaining type (literal or regex)
|
||||||
inline void operator=(const char* s);
|
inline void operator=(const keyType& s);
|
||||||
|
|
||||||
|
//- Assign as word, not treated as a regular expression.
|
||||||
|
inline void operator=(const word& s);
|
||||||
|
|
||||||
|
//- Assign as regular expression
|
||||||
|
inline void operator=(const string& s);
|
||||||
|
|
||||||
|
//- Assign as word, not treated as a regular expression.
|
||||||
|
inline void operator=(const char* s);
|
||||||
|
|
||||||
|
|
||||||
// IOstream operators
|
// IOstream operators
|
||||||
|
|||||||
@ -81,6 +81,12 @@ inline bool Foam::keyType::isPattern() const
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::keyType::operator()(const std::string& text) const
|
||||||
|
{
|
||||||
|
return match(text); // Use smart match
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::keyType::operator=(const keyType& s)
|
inline void Foam::keyType::operator=(const keyType& s)
|
||||||
{
|
{
|
||||||
string::operator=(s); // Bypass checking
|
string::operator=(s); // Bypass checking
|
||||||
|
|||||||
@ -47,8 +47,8 @@ namespace Foam
|
|||||||
class hashedWordList;
|
class hashedWordList;
|
||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
// Forward declaration of friend functions and operators
|
||||||
Istream& operator>>(Istream&, hashedWordList&);
|
Istream& operator>>(Istream& is, hashedWordList& lst);
|
||||||
Ostream& operator<<(Ostream&, const hashedWordList&);
|
Ostream& operator<<(Ostream& os, const hashedWordList& lst);
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -97,7 +97,7 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Construct from an initializer list
|
//- Construct from an initializer list
|
||||||
inline hashedWordList(std::initializer_list<word>);
|
inline hashedWordList(std::initializer_list<word> lst);
|
||||||
|
|
||||||
//- Construct from the word keys of any HashTable, sorting immediately.
|
//- Construct from the word keys of any HashTable, sorting immediately.
|
||||||
// This also handles a wordHashSet, which is derived from a HashTable.
|
// This also handles a wordHashSet, which is derived from a HashTable.
|
||||||
@ -105,7 +105,7 @@ public:
|
|||||||
template<class AnyType, class AnyHash>
|
template<class AnyType, class AnyHash>
|
||||||
explicit inline hashedWordList
|
explicit inline hashedWordList
|
||||||
(
|
(
|
||||||
const HashTable<AnyType, word, AnyHash>& h
|
const HashTable<AnyType, word, AnyHash>& tbl
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct from number and list of words,
|
//- Construct from number and list of words,
|
||||||
@ -122,7 +122,7 @@ public:
|
|||||||
hashedWordList(const char** lst, const bool removeDuplicates=false);
|
hashedWordList(const char** lst, const bool removeDuplicates=false);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
hashedWordList(Istream&);
|
hashedWordList(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
@ -161,26 +161,33 @@ public:
|
|||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Assignment operator from list of words
|
|
||||||
inline void operator=(const UList<word>& lst);
|
|
||||||
|
|
||||||
//- Assignment operator from initializer list
|
|
||||||
inline void operator=(std::initializer_list<word> lst);
|
|
||||||
|
|
||||||
//- Assignment operator.
|
|
||||||
inline void operator=(const hashedWordList& lst);
|
|
||||||
|
|
||||||
//- Return name corresponding to specified index
|
//- Return name corresponding to specified index
|
||||||
inline const word& operator[](const label index) const;
|
inline const word& operator[](const label index) const;
|
||||||
|
|
||||||
//- Return index corresponding to specified name
|
//- Return index corresponding to specified name, or -1 on failure
|
||||||
inline label operator[](const word& name) const;
|
inline label operator[](const word& name) const;
|
||||||
|
|
||||||
|
//- Does the list contain the specified name - same as found.
|
||||||
|
// Makes hashedWordList suitable as a unary predicate.
|
||||||
|
inline bool operator()(const word& name) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Assignment
|
||||||
|
|
||||||
|
//- Assignment operator from list of words. Rehashes the indices.
|
||||||
|
inline void operator=(const UList<word>& lst);
|
||||||
|
|
||||||
|
//- Assignment operator from initializer list. Rehashes the indices.
|
||||||
|
inline void operator=(std::initializer_list<word> lst);
|
||||||
|
|
||||||
|
//- Assignment operator. Rehashes the indices.
|
||||||
|
inline void operator=(const hashedWordList& lst);
|
||||||
|
|
||||||
|
|
||||||
// Istream operators
|
// Istream operators
|
||||||
|
|
||||||
friend Istream& operator>>(Istream&, hashedWordList&);
|
friend Istream& operator>>(Istream& is, hashedWordList& lst);
|
||||||
friend Ostream& operator<<(Ostream&, const hashedWordList&);
|
friend Ostream& operator<<(Ostream& os, const hashedWordList& lst);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -90,21 +90,15 @@ inline Foam::hashedWordList::hashedWordList(std::initializer_list<word> lst)
|
|||||||
template<class AnyType, class AnyHash>
|
template<class AnyType, class AnyHash>
|
||||||
inline Foam::hashedWordList::hashedWordList
|
inline Foam::hashedWordList::hashedWordList
|
||||||
(
|
(
|
||||||
const HashTable<AnyType, word, AnyHash>& h
|
const HashTable<AnyType, word, AnyHash>& tbl
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
List<word>(h.size())
|
List<word>(tbl.size())
|
||||||
{
|
{
|
||||||
label nElem = 0;
|
label count = 0;
|
||||||
for
|
for (auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
|
||||||
(
|
|
||||||
typename HashTable<AnyType, word, AnyHash>::const_iterator
|
|
||||||
iter = h.cbegin();
|
|
||||||
iter != h.cend();
|
|
||||||
++iter
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
List<word>::operator[](nElem++) = iter.key();
|
List<word>::operator[](count++) = iter.key();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->sort();
|
this->sort();
|
||||||
@ -162,6 +156,34 @@ inline void Foam::hashedWordList::sort()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline const Foam::word& Foam::hashedWordList::operator[]
|
||||||
|
(
|
||||||
|
const label index
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return List<word>::operator[](index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::label Foam::hashedWordList::operator[](const word& name) const
|
||||||
|
{
|
||||||
|
auto iter = indices_.find(name);
|
||||||
|
|
||||||
|
if (iter.found())
|
||||||
|
{
|
||||||
|
return iter.object();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1; // Not found (or not hashed?)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::hashedWordList::operator()(const word& name) const
|
||||||
|
{
|
||||||
|
return indices_.found(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::hashedWordList::operator=(const UList<word>& lst)
|
inline void Foam::hashedWordList::operator=(const UList<word>& lst)
|
||||||
{
|
{
|
||||||
List<word>::operator=(lst);
|
List<word>::operator=(lst);
|
||||||
@ -182,20 +204,4 @@ inline void Foam::hashedWordList::operator=(const hashedWordList& lst)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::word& Foam::hashedWordList::operator[]
|
|
||||||
(
|
|
||||||
const label index
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
return List<word>::operator[](index);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline Foam::label Foam::hashedWordList::operator[](const word& name) const
|
|
||||||
{
|
|
||||||
// Could return -1 instead of bombing out
|
|
||||||
return indices_[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -35,91 +35,99 @@ SourceFiles
|
|||||||
#ifndef stringListOps_H
|
#ifndef stringListOps_H
|
||||||
#define stringListOps_H
|
#define stringListOps_H
|
||||||
|
|
||||||
#include "regExp.H"
|
|
||||||
#include "labelList.H"
|
#include "labelList.H"
|
||||||
#include "stringList.H"
|
#include "stringList.H"
|
||||||
#include "wordReList.H"
|
#include "regExp.H"
|
||||||
#include "wordReListMatcher.H"
|
#include "wordRes.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
// Single-string matches:
|
// Single-string matches:
|
||||||
|
|
||||||
//- Return true if string matches one of the regular expressions
|
//- Return true if text matches one of the regular expressions
|
||||||
inline bool findStrings
|
// The primary purpose of this function is to automatically convert
|
||||||
(
|
// a wordReList to a wordRes for matching.
|
||||||
const wordReListMatcher& matcher,
|
inline bool findStrings(const wordRes& matcher, const std::string& text)
|
||||||
const std::string& str
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return matcher.match(str);
|
return matcher(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multi-string matches:
|
|
||||||
|
|
||||||
//- Return list indices for matching strings
|
// Multi-string matches:
|
||||||
template<class Matcher, class StringType>
|
|
||||||
|
//- Extract list indices
|
||||||
|
// The unary match predicate has the following signature:
|
||||||
|
// \code
|
||||||
|
// bool operator()(const std::string& text);
|
||||||
|
// \endcode
|
||||||
|
//
|
||||||
|
// \return List indices for matching strings
|
||||||
|
template<class UnaryMatchPredicate, class StringType>
|
||||||
labelList findMatchingStrings
|
labelList findMatchingStrings
|
||||||
(
|
(
|
||||||
const Matcher& matcher,
|
const UnaryMatchPredicate& matcher,
|
||||||
const UList<StringType>& lst,
|
const UList<StringType>& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Return list indices for strings matching the regular expression
|
|
||||||
// Template partial specialization of findMatchingStrings
|
|
||||||
template<class StringType>
|
|
||||||
labelList findStrings
|
|
||||||
(
|
|
||||||
const regExp& re,
|
|
||||||
const UList<StringType>& lst,
|
|
||||||
const bool invert=false
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return findMatchingStrings(re, lst, invert);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Return list indices for strings matching the regular expression
|
//- Return list indices for strings matching the regular expression
|
||||||
// Template partial specialization of findMatchingStrings
|
// Template partial specialization of findMatchingStrings
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
labelList findStrings
|
labelList findStrings
|
||||||
(
|
(
|
||||||
const char* rePattern,
|
const regExp& matcher,
|
||||||
const UList<StringType>& lst,
|
const UList<StringType>& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const regExp re(rePattern);
|
return findMatchingStrings(matcher, lst, invert);
|
||||||
return findMatchingStrings(re, lst, invert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//- Return list indices for strings matching the regular expression
|
//- Return list indices for strings matching the regular expression
|
||||||
// Template partial specialization of findMatchingStrings
|
// Template partial specialization of findMatchingStrings
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
labelList findStrings
|
labelList findStrings
|
||||||
(
|
(
|
||||||
const std::string& rePattern,
|
const char* re,
|
||||||
const UList<StringType>& lst,
|
const UList<StringType>& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const regExp re(rePattern);
|
const regExp matcher(re);
|
||||||
return findMatchingStrings(re, lst, invert);
|
return findMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//- Return list indices for strings matching the regular expression
|
//- Return list indices for strings matching the regular expression
|
||||||
// Template partial specialization of findMatchingStrings
|
// Template partial specialization of findMatchingStrings
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
labelList findStrings
|
labelList findStrings
|
||||||
(
|
(
|
||||||
const wordRe& wre,
|
const std::string& re,
|
||||||
const UList<StringType>& lst,
|
const UList<StringType>& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return findMatchingStrings(wre, lst, invert);
|
const regExp matcher(re);
|
||||||
|
return findMatchingStrings(matcher, lst, invert);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Return list indices for strings matching the regular expression
|
||||||
|
// Template partial specialization of findMatchingStrings
|
||||||
|
template<class StringType>
|
||||||
|
labelList findStrings
|
||||||
|
(
|
||||||
|
const wordRe& matcher,
|
||||||
|
const UList<StringType>& lst,
|
||||||
|
const bool invert=false
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return findMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -128,7 +136,7 @@ namespace Foam
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
labelList findStrings
|
labelList findStrings
|
||||||
(
|
(
|
||||||
const wordReListMatcher& matcher,
|
const wordRes& matcher,
|
||||||
const UList<StringType>& lst,
|
const UList<StringType>& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
@ -136,31 +144,50 @@ namespace Foam
|
|||||||
return findMatchingStrings(matcher, lst, invert);
|
return findMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
// subsetting multi-string matches (similar to ListOp):
|
|
||||||
|
// Subsetting multi-string matches (similar to ListOp):
|
||||||
|
|
||||||
//- Extract elements of StringList when regular expression matches
|
//- Extract elements of StringList when regular expression matches
|
||||||
// optionally invert the match
|
// optionally invert the match
|
||||||
// eg, to extract all selected elements:
|
// eg, to extract all selected elements:
|
||||||
|
// \code
|
||||||
// subsetMatchingStrings<regExp, stringList>(myRegExp, lst);
|
// subsetMatchingStrings<regExp, stringList>(myRegExp, lst);
|
||||||
template<class Matcher, class StringListType>
|
// \endcode
|
||||||
|
template<class UnaryMatchPredicate, class StringListType>
|
||||||
StringListType subsetMatchingStrings
|
StringListType subsetMatchingStrings
|
||||||
(
|
(
|
||||||
const Matcher&,
|
const UnaryMatchPredicate& matcher,
|
||||||
const StringListType&,
|
const StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
//- Extract elements of StringList when regular expression matches
|
//- Extract elements of StringList when regular expression matches
|
||||||
// Template partial specialization of subsetMatchingStrings
|
// Template partial specialization of subsetMatchingStrings
|
||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
StringListType subsetStrings
|
StringListType subsetStrings
|
||||||
(
|
(
|
||||||
const regExp& re,
|
const regExp& matcher,
|
||||||
const StringListType& lst,
|
const StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return subsetMatchingStrings(re, lst, invert);
|
return subsetMatchingStrings(matcher, lst, invert);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Extract elements of StringList when regular expression matches
|
||||||
|
// Template partial specialization of subsetMatchingStrings
|
||||||
|
template<class StringListType>
|
||||||
|
StringListType subsetStrings
|
||||||
|
(
|
||||||
|
const char* re,
|
||||||
|
const StringListType& lst,
|
||||||
|
const bool invert=false
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const regExp matcher(re);
|
||||||
|
return subsetMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Extract elements of StringList when regular expression matches
|
//- Extract elements of StringList when regular expression matches
|
||||||
@ -168,13 +195,13 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
StringListType subsetStrings
|
StringListType subsetStrings
|
||||||
(
|
(
|
||||||
const char* rePattern,
|
const std::string& re,
|
||||||
const StringListType& lst,
|
const StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const regExp re(rePattern);
|
const regExp matcher(re);
|
||||||
return subsetMatchingStrings(re, lst, invert);
|
return subsetMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Extract elements of StringList when regular expression matches
|
//- Extract elements of StringList when regular expression matches
|
||||||
@ -182,13 +209,12 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
StringListType subsetStrings
|
StringListType subsetStrings
|
||||||
(
|
(
|
||||||
const std::string& rePattern,
|
const wordRe& matcher,
|
||||||
const StringListType& lst,
|
const StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const regExp re(rePattern);
|
return subsetMatchingStrings(matcher, lst, invert);
|
||||||
return subsetMatchingStrings(re, lst, invert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Extract elements of StringList when regular expression matches
|
//- Extract elements of StringList when regular expression matches
|
||||||
@ -196,20 +222,7 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
StringListType subsetStrings
|
StringListType subsetStrings
|
||||||
(
|
(
|
||||||
const wordRe& wre,
|
const wordRes& matcher,
|
||||||
const StringListType& lst,
|
|
||||||
const bool invert=false
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return subsetMatchingStrings(wre, lst, invert);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Extract elements of StringList when regular expression matches
|
|
||||||
// Template partial specialization of subsetMatchingStrings
|
|
||||||
template<class StringListType>
|
|
||||||
StringListType subsetStrings
|
|
||||||
(
|
|
||||||
const wordReListMatcher& matcher,
|
|
||||||
const StringListType& lst,
|
const StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
@ -222,11 +235,11 @@ namespace Foam
|
|||||||
// optionally invert the match
|
// optionally invert the match
|
||||||
// eg, to extract all selected elements:
|
// eg, to extract all selected elements:
|
||||||
// inplaceSubsetMatchingStrings<regExp, stringList>(myRegExp, lst);
|
// inplaceSubsetMatchingStrings<regExp, stringList>(myRegExp, lst);
|
||||||
template<class Matcher, class StringListType>
|
template<class UnaryMatchPredicate, class StringListType>
|
||||||
void inplaceSubsetMatchingStrings
|
void inplaceSubsetMatchingStrings
|
||||||
(
|
(
|
||||||
const Matcher&,
|
const UnaryMatchPredicate& matcher,
|
||||||
StringListType&,
|
StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -235,12 +248,12 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
void inplaceSubsetStrings
|
void inplaceSubsetStrings
|
||||||
(
|
(
|
||||||
const regExp& re,
|
const regExp& matcher,
|
||||||
StringListType& lst,
|
StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
inplaceSubsetMatchingStrings(re, lst, invert);
|
inplaceSubsetMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Inplace extract elements of StringList when regular expression matches
|
//- Inplace extract elements of StringList when regular expression matches
|
||||||
@ -248,13 +261,13 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
void inplaceSubsetStrings
|
void inplaceSubsetStrings
|
||||||
(
|
(
|
||||||
const char* rePattern,
|
const char* re,
|
||||||
StringListType& lst,
|
StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const regExp re(rePattern);
|
const regExp matcher(re);
|
||||||
inplaceSubsetMatchingStrings(re, lst, invert);
|
inplaceSubsetMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Inplace extract elements of StringList when regular expression matches
|
//- Inplace extract elements of StringList when regular expression matches
|
||||||
@ -262,13 +275,13 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
void inplaceSubsetStrings
|
void inplaceSubsetStrings
|
||||||
(
|
(
|
||||||
const std::string& rePattern,
|
const std::string& re,
|
||||||
StringListType& lst,
|
StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const regExp re(rePattern);
|
const regExp matcher(re);
|
||||||
inplaceSubsetMatchingStrings(re, lst, invert);
|
inplaceSubsetMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Inplace extract elements of StringList when regular expression matches
|
//- Inplace extract elements of StringList when regular expression matches
|
||||||
@ -276,12 +289,12 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
void inplaceSubsetStrings
|
void inplaceSubsetStrings
|
||||||
(
|
(
|
||||||
const wordRe& wre,
|
const wordRe& matcher,
|
||||||
StringListType& lst,
|
StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
inplaceSubsetMatchingStrings(wre, lst, invert);
|
inplaceSubsetMatchingStrings(matcher, lst, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Inplace extract elements of StringList when regular expression matches
|
//- Inplace extract elements of StringList when regular expression matches
|
||||||
@ -289,7 +302,7 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
void inplaceSubsetStrings
|
void inplaceSubsetStrings
|
||||||
(
|
(
|
||||||
const wordReListMatcher& matcher,
|
const wordRes& matcher,
|
||||||
StringListType& lst,
|
StringListType& lst,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,75 +25,79 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Matcher, class StringType>
|
template<class UnaryMatchPredicate, class StringType>
|
||||||
Foam::labelList Foam::findMatchingStrings
|
Foam::labelList Foam::findMatchingStrings
|
||||||
(
|
(
|
||||||
const Matcher& matcher,
|
const UnaryMatchPredicate& matcher,
|
||||||
const UList<StringType>& lst,
|
const UList<StringType>& lst,
|
||||||
const bool invert
|
const bool invert
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
labelList indices(lst.size());
|
labelList indices(lst.size());
|
||||||
|
|
||||||
label nElem = 0;
|
label count = 0;
|
||||||
forAll(lst, elemI)
|
forAll(lst, elemi)
|
||||||
{
|
{
|
||||||
if (matcher.match(lst[elemI]) ? !invert : invert)
|
if (matcher(lst[elemi]) ? !invert : invert)
|
||||||
{
|
{
|
||||||
indices[nElem++] = elemI;
|
indices[count++] = elemi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indices.setSize(nElem);
|
indices.setSize(count);
|
||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Matcher, class StringListType>
|
template<class UnaryMatchPredicate, class StringListType>
|
||||||
StringListType Foam::subsetMatchingStrings
|
StringListType Foam::subsetMatchingStrings
|
||||||
(
|
(
|
||||||
const Matcher& matcher,
|
const UnaryMatchPredicate& matcher,
|
||||||
const StringListType& lst,
|
const StringListType& lst,
|
||||||
const bool invert
|
const bool invert
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Create copy
|
// Create as a copy
|
||||||
StringListType newLst(lst.size());
|
StringListType newLst(lst.size());
|
||||||
|
|
||||||
// ensure consistent addressable size (eg, DynamicList)
|
// Ensure consistent addressable size (eg, DynamicList)
|
||||||
newLst.setSize(lst.size());
|
newLst.setSize(lst.size());
|
||||||
|
|
||||||
label nElem = 0;
|
label count = 0;
|
||||||
forAll(lst, elemI)
|
forAll(lst, elemi)
|
||||||
{
|
{
|
||||||
if (matcher.match(lst[elemI]) ? !invert : invert)
|
if (matcher(lst[elemi]) ? !invert : invert)
|
||||||
{
|
{
|
||||||
newLst[nElem++] = lst[elemI];
|
newLst[count++] = lst[elemi];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newLst.setSize(nElem);
|
newLst.setSize(count);
|
||||||
|
|
||||||
return newLst;
|
return newLst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Matcher, class StringListType>
|
template<class UnaryMatchPredicate, class StringListType>
|
||||||
void Foam::inplaceSubsetMatchingStrings
|
void Foam::inplaceSubsetMatchingStrings
|
||||||
(
|
(
|
||||||
const Matcher& matcher,
|
const UnaryMatchPredicate& matcher,
|
||||||
StringListType& lst,
|
StringListType& lst,
|
||||||
const bool invert
|
const bool invert
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
label nElem = 0;
|
label count = 0;
|
||||||
forAll(lst, elemI)
|
forAll(lst, elemi)
|
||||||
{
|
{
|
||||||
if (matcher.match(lst[elemI]) ? !invert : invert)
|
if (matcher(lst[elemi]) ? !invert : invert)
|
||||||
{
|
{
|
||||||
lst[nElem++] = lst[elemI];
|
if (count != elemi)
|
||||||
|
{
|
||||||
|
lst[count] = lst[elemi];
|
||||||
|
}
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lst.setSize(nElem);
|
lst.setSize(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -94,7 +94,9 @@ public:
|
|||||||
hash()
|
hash()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline unsigned operator()(const string&, unsigned seed = 0) const;
|
//- Hash for string.
|
||||||
|
// Uses Foam::string instead of std::string for automatic conversions.
|
||||||
|
inline unsigned operator()(const string& str, unsigned seed = 0) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -109,7 +111,7 @@ public:
|
|||||||
//- Construct as copy of character array
|
//- Construct as copy of character array
|
||||||
inline string(const char* str);
|
inline string(const char* str);
|
||||||
|
|
||||||
//- Construct as copy of specified number of characters
|
//- Construct as copy with a maximum number of characters
|
||||||
inline string(const char* str, const size_type len);
|
inline string(const char* str, const size_type len);
|
||||||
|
|
||||||
//- Construct from a single character
|
//- Construct from a single character
|
||||||
@ -222,14 +224,18 @@ public:
|
|||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Return the sub-string from the i-th character for \a n characters
|
//- Match text
|
||||||
|
// \return True when strings match literally.
|
||||||
|
inline bool operator()(const std::string& text) const;
|
||||||
|
|
||||||
|
//- Return sub-string from the i-th character for \a n characters
|
||||||
inline string operator()
|
inline string operator()
|
||||||
(
|
(
|
||||||
const size_type i,
|
const size_type i,
|
||||||
const size_type n
|
const size_type n
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Return the sub-string from the first character for \a n characters
|
//- Return sub-string from the first character for \a n characters
|
||||||
inline string operator()
|
inline string operator()
|
||||||
(
|
(
|
||||||
const size_type n
|
const size_type n
|
||||||
|
|||||||
@ -178,15 +178,21 @@ inline String Foam::string::validate(const std::string& str)
|
|||||||
return ss;
|
return ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::string::match(const std::string& text) const
|
inline bool Foam::string::match(const std::string& text) const
|
||||||
{
|
{
|
||||||
// check as string
|
return !compare(text); // Always compare as literal string
|
||||||
return (text == *this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::string::operator()(const std::string& text) const
|
||||||
|
{
|
||||||
|
return !compare(text); // Always compare as literal string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::string Foam::string::operator()
|
inline Foam::string Foam::string::operator()
|
||||||
(
|
(
|
||||||
const size_type i,
|
const size_type i,
|
||||||
@ -205,11 +211,11 @@ inline Foam::string Foam::string::operator()(const size_type n) const
|
|||||||
|
|
||||||
inline unsigned Foam::string::hash::operator()
|
inline unsigned Foam::string::hash::operator()
|
||||||
(
|
(
|
||||||
const string& key,
|
const string& str,
|
||||||
unsigned seed
|
unsigned seed
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return Hasher(key.data(), key.size(), seed);
|
return Hasher(str.data(), str.size(), seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -25,7 +25,7 @@ Class
|
|||||||
Foam::word
|
Foam::word
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A class for handling words, derived from string.
|
A class for handling words, derived from Foam::string.
|
||||||
|
|
||||||
A word is a string of characters without whitespace, quotes, slashes,
|
A word is a string of characters without whitespace, quotes, slashes,
|
||||||
semicolons or brace brackets. Words are delimited by whitespace.
|
semicolons or brace brackets. Words are delimited by whitespace.
|
||||||
@ -93,7 +93,7 @@ public:
|
|||||||
inline word
|
inline word
|
||||||
(
|
(
|
||||||
const char* s,
|
const char* s,
|
||||||
const size_type,
|
const size_type len,
|
||||||
const bool doStripInvalid
|
const bool doStripInvalid
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -119,12 +119,12 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
|
|
||||||
inline void operator=(const word& w);
|
inline void operator=(const word& w);
|
||||||
inline void operator=(const string& s);
|
inline void operator=(const string& s);
|
||||||
inline void operator=(const std::string& s);
|
inline void operator=(const std::string& s);
|
||||||
inline void operator=(const char* s);
|
inline void operator=(const char* s);
|
||||||
|
|
||||||
|
|
||||||
// Friend Operators
|
// Friend Operators
|
||||||
|
|||||||
@ -99,11 +99,11 @@ inline Foam::word::word(const char* s, const bool doStripInvalid)
|
|||||||
inline Foam::word::word
|
inline Foam::word::word
|
||||||
(
|
(
|
||||||
const char* s,
|
const char* s,
|
||||||
const size_type n,
|
const size_type len,
|
||||||
const bool doStripInvalid
|
const bool doStripInvalid
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
string(s, n)
|
string(s, len)
|
||||||
{
|
{
|
||||||
if (doStripInvalid)
|
if (doStripInvalid)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -92,15 +92,15 @@ public:
|
|||||||
// Public data types
|
// Public data types
|
||||||
|
|
||||||
//- Enumeration with compile options
|
//- Enumeration with compile options
|
||||||
// Note that 'REGEXP' is implicit if 'NOCASE' is specified alone.
|
// Note that 'REGEX' is implicit if 'NOCASE' is specified alone.
|
||||||
enum compOption
|
enum compOption
|
||||||
{
|
{
|
||||||
LITERAL = 0, //!< Treat as a string literal
|
LITERAL = 0, //!< Treat as a string literal
|
||||||
DETECT = 1, //!< Detect if the string contains meta-characters
|
DETECT = 1, //!< Detect if the string contains meta-characters
|
||||||
REGEXP = 2, //!< Treat as regular expression
|
REGEX = 2, //!< Treat as regular expression
|
||||||
NOCASE = 4, //!< Ignore case in regular expression
|
NOCASE = 4, //!< Ignore case in regular expression
|
||||||
DETECT_NOCASE = DETECT | NOCASE, //!< Combined DETECT and NOCASE
|
DETECT_NOCASE = DETECT|NOCASE, //!< Combined DETECT and NOCASE
|
||||||
REGEXP_NOCASE = REGEXP | NOCASE //!< Combined REGEXP and NOCASE
|
REGEX_NOCASE = REGEX|NOCASE //!< Combined REGEX and NOCASE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -119,30 +119,35 @@ public:
|
|||||||
//- Construct as copy
|
//- Construct as copy
|
||||||
inline wordRe(const wordRe& str);
|
inline wordRe(const wordRe& str);
|
||||||
|
|
||||||
//- Construct from keyType
|
//- Construct from keyType, using its compile information
|
||||||
inline explicit wordRe(const keyType& str);
|
inline explicit wordRe(const keyType& str);
|
||||||
|
|
||||||
|
//- Construct as copy of character array, treat as a literal
|
||||||
|
inline explicit wordRe(const char* str);
|
||||||
|
|
||||||
|
//- Construct as copy of std::string, treat as a literal
|
||||||
|
inline explicit wordRe(const std::string& str);
|
||||||
|
|
||||||
|
//- Construct as copy of string, treat as a literal
|
||||||
|
inline explicit wordRe(const string& str);
|
||||||
|
|
||||||
|
//- Construct as copy of word, treat as a literal
|
||||||
|
inline explicit wordRe(const word& str);
|
||||||
|
|
||||||
//- Construct from keyType, use specified compile option
|
//- Construct from keyType, use specified compile option
|
||||||
inline wordRe(const keyType& str, const compOption);
|
inline wordRe(const keyType& str, const compOption);
|
||||||
|
|
||||||
//- Construct as copy of word
|
//- Construct as copy of character array, use specified compile option
|
||||||
inline explicit wordRe(const word& str);
|
inline wordRe(const char* str, const compOption);
|
||||||
|
|
||||||
//- Construct as copy of character array
|
//- Construct as copy of std::string, use specified compile option
|
||||||
// Optionally specify how it should be treated.
|
inline wordRe(const std::string& str, const compOption);
|
||||||
inline explicit wordRe(const char* str, const compOption = LITERAL);
|
|
||||||
|
|
||||||
//- Construct as copy of string.
|
//- Construct as copy of string, use specified compile option
|
||||||
// Optionally specify how it should be treated.
|
inline wordRe(const string& str, const compOption);
|
||||||
inline explicit wordRe(const string& str, const compOption = LITERAL);
|
|
||||||
|
|
||||||
//- Construct as copy of std::string
|
//- Construct as copy of word, use specified compile option
|
||||||
// Optionally specify how it should be treated.
|
inline wordRe(const word& str, const compOption);
|
||||||
inline explicit wordRe
|
|
||||||
(
|
|
||||||
const std::string& str,
|
|
||||||
const compOption = LITERAL
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
// Words are treated as literals, strings with an auto-test
|
// Words are treated as literals, strings with an auto-test
|
||||||
@ -200,6 +205,13 @@ public:
|
|||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
|
//- Avoid masking the normal operator()
|
||||||
|
using word::operator();
|
||||||
|
|
||||||
|
//- Perform smart match on text, as per match()
|
||||||
|
inline bool operator()(const std::string& text) const;
|
||||||
|
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
|
|
||||||
//- Copy wordRe and its type (literal or regex)
|
//- Copy wordRe and its type (literal or regex)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -48,7 +48,7 @@ inline Foam::wordRe::wordRe()
|
|||||||
|
|
||||||
inline Foam::wordRe::wordRe(const wordRe& str)
|
inline Foam::wordRe::wordRe(const wordRe& str)
|
||||||
:
|
:
|
||||||
word(str),
|
word(str, false),
|
||||||
re_()
|
re_()
|
||||||
{
|
{
|
||||||
if (str.isPattern())
|
if (str.isPattern())
|
||||||
@ -58,13 +58,6 @@ inline Foam::wordRe::wordRe(const wordRe& str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::wordRe::wordRe(const word& str)
|
|
||||||
:
|
|
||||||
word(str),
|
|
||||||
re_()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
inline Foam::wordRe::wordRe(const keyType& str)
|
inline Foam::wordRe::wordRe(const keyType& str)
|
||||||
:
|
:
|
||||||
word(str, false),
|
word(str, false),
|
||||||
@ -77,6 +70,34 @@ inline Foam::wordRe::wordRe(const keyType& str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::wordRe::wordRe(const char* str)
|
||||||
|
:
|
||||||
|
word(str, false),
|
||||||
|
re_()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::wordRe::wordRe(const std::string& str)
|
||||||
|
:
|
||||||
|
word(str, false),
|
||||||
|
re_()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::wordRe::wordRe(const string& str)
|
||||||
|
:
|
||||||
|
word(str, false),
|
||||||
|
re_()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::wordRe::wordRe(const word& str)
|
||||||
|
:
|
||||||
|
word(str, false),
|
||||||
|
re_()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::wordRe::wordRe(const keyType& str, const compOption opt)
|
inline Foam::wordRe::wordRe(const keyType& str, const compOption opt)
|
||||||
:
|
:
|
||||||
word(str, false),
|
word(str, false),
|
||||||
@ -91,17 +112,7 @@ inline Foam::wordRe::wordRe(const keyType& str, const compOption opt)
|
|||||||
|
|
||||||
inline Foam::wordRe::wordRe(const char* str, const compOption opt)
|
inline Foam::wordRe::wordRe(const char* str, const compOption opt)
|
||||||
:
|
:
|
||||||
word(str, false),
|
wordRe(str)
|
||||||
re_()
|
|
||||||
{
|
|
||||||
compile(opt);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline Foam::wordRe::wordRe(const string& str, const compOption opt)
|
|
||||||
:
|
|
||||||
word(str, false),
|
|
||||||
re_()
|
|
||||||
{
|
{
|
||||||
compile(opt);
|
compile(opt);
|
||||||
}
|
}
|
||||||
@ -109,8 +120,23 @@ inline Foam::wordRe::wordRe(const string& str, const compOption opt)
|
|||||||
|
|
||||||
inline Foam::wordRe::wordRe(const std::string& str, const compOption opt)
|
inline Foam::wordRe::wordRe(const std::string& str, const compOption opt)
|
||||||
:
|
:
|
||||||
word(str, false),
|
wordRe(str)
|
||||||
re_()
|
{
|
||||||
|
compile(opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::wordRe::wordRe(const string& str, const compOption opt)
|
||||||
|
:
|
||||||
|
wordRe(str)
|
||||||
|
{
|
||||||
|
compile(opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::wordRe::wordRe(const word& str, const compOption opt)
|
||||||
|
:
|
||||||
|
wordRe(str)
|
||||||
{
|
{
|
||||||
compile(opt);
|
compile(opt);
|
||||||
}
|
}
|
||||||
@ -126,42 +152,38 @@ inline bool Foam::wordRe::isPattern() const
|
|||||||
|
|
||||||
inline bool Foam::wordRe::compile(const compOption opt) const
|
inline bool Foam::wordRe::compile(const compOption opt) const
|
||||||
{
|
{
|
||||||
bool doCompile = false;
|
if (opt)
|
||||||
|
{
|
||||||
|
bool comp = false;
|
||||||
|
|
||||||
if (opt & wordRe::REGEXP)
|
if (opt & wordRe::REGEX)
|
||||||
{
|
|
||||||
doCompile = true;
|
|
||||||
}
|
|
||||||
else if (opt & wordRe::DETECT)
|
|
||||||
{
|
|
||||||
if (string::meta<regExp>(*this) || !string::valid<word>(*this))
|
|
||||||
{
|
{
|
||||||
doCompile = true;
|
comp = true;
|
||||||
|
}
|
||||||
|
else if (opt & wordRe::DETECT)
|
||||||
|
{
|
||||||
|
comp = string::meta<regExp>(*this) || !string::valid<word>(*this);
|
||||||
|
}
|
||||||
|
else if (opt & wordRe::NOCASE)
|
||||||
|
{
|
||||||
|
comp = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comp)
|
||||||
|
{
|
||||||
|
return re_.set(*this, (opt & wordRe::NOCASE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (opt & wordRe::NOCASE)
|
|
||||||
{
|
|
||||||
doCompile = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Fall-through behaviour - not a regex
|
||||||
if (doCompile)
|
re_.clear();
|
||||||
{
|
return false;
|
||||||
re_.set(*this, (opt & wordRe::NOCASE));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
re_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
return re_.exists();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::wordRe::compile() const
|
inline bool Foam::wordRe::compile() const
|
||||||
{
|
{
|
||||||
re_ = *this;
|
return re_.set(*this);
|
||||||
return re_.exists();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -169,7 +191,7 @@ inline void Foam::wordRe::uncompile(const bool doStripInvalid) const
|
|||||||
{
|
{
|
||||||
if (re_.clear() && doStripInvalid)
|
if (re_.clear() && doStripInvalid)
|
||||||
{
|
{
|
||||||
// skip stripping unless debug is active to avoid costly operations
|
// Skip stripping unless debug is active to avoid costly operations
|
||||||
if (word::debug)
|
if (word::debug)
|
||||||
{
|
{
|
||||||
string::stripInvalid<word>
|
string::stripInvalid<word>
|
||||||
@ -192,13 +214,11 @@ inline bool Foam::wordRe::match(const std::string& text, bool literal) const
|
|||||||
{
|
{
|
||||||
if (literal || !re_.exists())
|
if (literal || !re_.exists())
|
||||||
{
|
{
|
||||||
// check as string
|
return !compare(text); // Compare as literal string
|
||||||
return (text == *this);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// check as regex
|
return re_.match(text); // Match as regex
|
||||||
return re_.match(text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +245,12 @@ inline void Foam::wordRe::set(const char* str, const compOption opt)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::wordRe::operator()(const std::string& text) const
|
||||||
|
{
|
||||||
|
return match(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::wordRe::operator=(const wordRe& str)
|
inline void Foam::wordRe::operator=(const wordRe& str)
|
||||||
{
|
{
|
||||||
string::operator=(str);
|
string::operator=(str);
|
||||||
@ -263,21 +289,21 @@ inline void Foam::wordRe::operator=(const keyType& str)
|
|||||||
inline void Foam::wordRe::operator=(const string& str)
|
inline void Foam::wordRe::operator=(const string& str)
|
||||||
{
|
{
|
||||||
string::operator=(str);
|
string::operator=(str);
|
||||||
compile(wordRe::DETECT); // auto-detect regex
|
compile(wordRe::DETECT); // Auto-detect regex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::wordRe::operator=(const std::string& str)
|
inline void Foam::wordRe::operator=(const std::string& str)
|
||||||
{
|
{
|
||||||
string::operator=(str);
|
string::operator=(str);
|
||||||
compile(wordRe::DETECT); // auto-detect regex
|
compile(wordRe::DETECT); // Auto-detect regex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::wordRe::operator=(const char* str)
|
inline void Foam::wordRe::operator=(const char* str)
|
||||||
{
|
{
|
||||||
string::operator=(str);
|
string::operator=(str);
|
||||||
compile(wordRe::DETECT); // auto-detect regex
|
compile(wordRe::DETECT); // Auto-detect regex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
51
src/OpenFOAM/primitives/strings/wordRes/wordReListMatcher.H
Normal file
51
src/OpenFOAM/primitives/strings/wordRes/wordReListMatcher.H
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
Typedef
|
||||||
|
Foam::wordReListMatcher
|
||||||
|
|
||||||
|
Description
|
||||||
|
The older name for Foam::wordRes, which is a wrapper for matching
|
||||||
|
a std::string against wordRe list.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef wordReListMatcher_H
|
||||||
|
#define wordReListMatcher_H
|
||||||
|
|
||||||
|
#include "wordRes.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
typedef wordRes wordReListMatcher;
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -23,17 +23,17 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "wordReListMatcher.H"
|
#include "wordRes.H"
|
||||||
#include "HashSet.H"
|
#include "HashSet.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::wordReList Foam::wordReListMatcher::uniq(const UList<wordRe>& input)
|
Foam::wordReList Foam::wordRes::uniq(const UList<wordRe>& input)
|
||||||
{
|
{
|
||||||
wordReList retain(input.size());
|
wordReList retain(input.size());
|
||||||
wordHashSet uniqWord;
|
wordHashSet uniqWord;
|
||||||
|
|
||||||
label nUniq = 0;
|
label count = 0;
|
||||||
forAll(input, i)
|
forAll(input, i)
|
||||||
{
|
{
|
||||||
const wordRe& select = input[i];
|
const wordRe& select = input[i];
|
||||||
@ -44,11 +44,11 @@ Foam::wordReList Foam::wordReListMatcher::uniq(const UList<wordRe>& input)
|
|||||||
|| uniqWord.insert(static_cast<const word&>(select))
|
|| uniqWord.insert(static_cast<const word&>(select))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
retain[nUniq++] = select;
|
retain[count++] = select;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
retain.setSize(nUniq);
|
retain.setSize(count);
|
||||||
return retain;
|
return retain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -22,23 +22,23 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Class
|
Class
|
||||||
Foam::wordReListMatcher
|
Foam::wordRes
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A wrapper for matching a List of wordRe.
|
A wrapper for matching a std::string against a wordRe list.
|
||||||
|
|
||||||
Note
|
Note
|
||||||
The constructor should remain non-explicit. This allows automatic
|
The constructor should remain non-explicit. This allows automatic
|
||||||
conversion from UList\<wordRe\> to wordReListMatcher in search
|
conversion from UList\<wordRe\> to wordRes in search functions.
|
||||||
functions.
|
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
wordReListMatcherI.H
|
wordResI.H
|
||||||
|
wordRes.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef wordReListMatcher_H
|
#ifndef wordRes_H
|
||||||
#define wordReListMatcher_H
|
#define wordRes_H
|
||||||
|
|
||||||
#include "wordReList.H"
|
#include "wordReList.H"
|
||||||
|
|
||||||
@ -48,48 +48,70 @@ namespace Foam
|
|||||||
{
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class wordReListMatcher Declaration
|
Class wordRes Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class wordReListMatcher
|
class wordRes
|
||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Reference to underlying list
|
//- Reference to underlying list
|
||||||
const UList<wordRe>& reList_;
|
const UList<wordRe>& list_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// STL type definitions
|
||||||
|
|
||||||
|
//- Type of values the list contains
|
||||||
|
typedef wordRe value_type;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from a List of wordRe
|
//- Construct from a list of wordRe
|
||||||
inline wordReListMatcher(const UList<wordRe>&);
|
inline wordRes(const UList<wordRe>& lst);
|
||||||
|
|
||||||
|
|
||||||
|
// Static Constructors, Helpers
|
||||||
|
|
||||||
|
//- Return a wordReList with duplicate words filtered out.
|
||||||
|
// No filtering is done on regular expressions.
|
||||||
|
static wordReList uniq(const UList<wordRe>& input);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Access
|
// Access
|
||||||
|
|
||||||
|
//- The number of elements in the list
|
||||||
inline label size() const;
|
inline label size() const;
|
||||||
inline bool empty() const;
|
|
||||||
|
//- True if the list is empty
|
||||||
|
inline bool empty() const;
|
||||||
|
|
||||||
|
|
||||||
|
// Searching
|
||||||
|
|
||||||
|
//- Return true if string matches any of the regular expressions
|
||||||
|
// Smart match as regular expression or as a string.
|
||||||
|
// Optionally specify a literal match only.
|
||||||
|
inline bool match
|
||||||
|
(
|
||||||
|
const std::string& text,
|
||||||
|
const bool literal = false
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Member operators
|
||||||
|
|
||||||
//- Return underlying list of wordRe
|
//- Return underlying list of wordRe
|
||||||
inline const UList<wordRe>& operator()() const;
|
inline const UList<wordRe>& operator()() const;
|
||||||
|
|
||||||
|
//- Perform smart match on text, as per match()
|
||||||
|
inline bool operator()(const std::string& text) const;
|
||||||
|
|
||||||
// Searching
|
//- Return element of constant list
|
||||||
|
inline const wordRe& operator[](const label i) const;
|
||||||
//- Return true if string matches any of the regular expressions
|
|
||||||
// Smart match as regular expression or as a string.
|
|
||||||
// Optionally specify a literal match only.
|
|
||||||
inline bool match(const std::string&, bool literalMatch=false) const;
|
|
||||||
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
|
|
||||||
//- Return a wordReList with duplicate words filtered out.
|
|
||||||
// No filtering is done on regular expressions.
|
|
||||||
static wordReList uniq(const UList<wordRe>& input);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -100,7 +122,7 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#include "wordReListMatcherI.H"
|
#include "wordResI.H"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -26,46 +26,40 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::wordReListMatcher::wordReListMatcher
|
inline Foam::wordRes::wordRes
|
||||||
(
|
(
|
||||||
const UList<wordRe>& lst
|
const UList<wordRe>& list
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
reList_(lst)
|
list_(list)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::label Foam::wordReListMatcher::size() const
|
inline Foam::label Foam::wordRes::size() const
|
||||||
{
|
{
|
||||||
return reList_.size();
|
return list_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::wordReListMatcher::empty() const
|
inline bool Foam::wordRes::empty() const
|
||||||
{
|
{
|
||||||
return reList_.empty();
|
return list_.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::UList<Foam::wordRe>&
|
inline bool Foam::wordRes::match
|
||||||
Foam::wordReListMatcher::operator()() const
|
|
||||||
{
|
|
||||||
return reList_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::wordReListMatcher::match
|
|
||||||
(
|
(
|
||||||
const std::string& text,
|
const std::string& text,
|
||||||
bool literalMatch
|
const bool literal
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const label n = reList_.size();
|
const label n = list_.size();
|
||||||
|
|
||||||
for (label i = 0; i < n; ++i)
|
for (label i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
if (reList_[i].match(text, literalMatch))
|
if (list_[i].match(text, literal))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -75,4 +69,24 @@ inline bool Foam::wordReListMatcher::match
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline const Foam::UList<Foam::wordRe>& Foam::wordRes::operator()() const
|
||||||
|
{
|
||||||
|
return list_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::wordRes::operator()(const std::string& text) const
|
||||||
|
{
|
||||||
|
return match(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline const Foam::wordRe& Foam::wordRes::operator[](const label i) const
|
||||||
|
{
|
||||||
|
return list_[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
@ -151,7 +151,7 @@ void Foam::ensightMesh::correct()
|
|||||||
useAll = false;
|
useAll = false;
|
||||||
matched = findMatchingStrings
|
matched = findMatchingStrings
|
||||||
(
|
(
|
||||||
wordReListMatcher(matcher),
|
wordRes(matcher),
|
||||||
patchNames
|
patchNames
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ void Foam::ensightMesh::correct()
|
|||||||
wordList selectZones = mesh_.faceZones().names();
|
wordList selectZones = mesh_.faceZones().names();
|
||||||
inplaceSubsetMatchingStrings
|
inplaceSubsetMatchingStrings
|
||||||
(
|
(
|
||||||
wordReListMatcher(matcher),
|
wordRes(matcher),
|
||||||
selectZones
|
selectZones
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ License
|
|||||||
|
|
||||||
#include "volFields.H"
|
#include "volFields.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
#include "wordReListMatcher.H"
|
#include "wordRes.H"
|
||||||
#include "steadyStateDdtScheme.H"
|
#include "steadyStateDdtScheme.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ bool Foam::functionObjects::ddt2::read(const dictionary& dict)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectFields_ = wordReListMatcher::uniq
|
selectFields_ = wordRes::uniq
|
||||||
(
|
(
|
||||||
wordReList(dict.lookup("fields"))
|
wordReList(dict.lookup("fields"))
|
||||||
);
|
);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ License
|
|||||||
|
|
||||||
#include "volFields.H"
|
#include "volFields.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
#include "wordReListMatcher.H"
|
#include "wordRes.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
@ -120,7 +120,7 @@ bool Foam::functionObjects::zeroGradient::read(const dictionary& dict)
|
|||||||
{
|
{
|
||||||
fvMeshFunctionObject::read(dict);
|
fvMeshFunctionObject::read(dict);
|
||||||
|
|
||||||
selectFields_ = wordReListMatcher::uniq
|
selectFields_ = wordRes::uniq
|
||||||
(
|
(
|
||||||
wordReList(dict.lookup("fields"))
|
wordReList(dict.lookup("fields"))
|
||||||
);
|
);
|
||||||
|
|||||||
@ -31,7 +31,7 @@ License
|
|||||||
#include "volPointInterpolation.H"
|
#include "volPointInterpolation.H"
|
||||||
#include "PatchTools.H"
|
#include "PatchTools.H"
|
||||||
#include "mapPolyMesh.H"
|
#include "mapPolyMesh.H"
|
||||||
#include "wordReListMatcher.H"
|
#include "wordRes.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
@ -268,7 +268,7 @@ bool Foam::surfMeshSamplers::write()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// avoid duplicate entries
|
// avoid duplicate entries
|
||||||
select = wordReListMatcher::uniq(select);
|
select = wordRes::uniq(select);
|
||||||
|
|
||||||
forAll(*this, surfI)
|
forAll(*this, surfI)
|
||||||
{
|
{
|
||||||
@ -290,7 +290,7 @@ bool Foam::surfMeshSamplers::read(const dictionary& dict)
|
|||||||
|
|
||||||
if (dict.found("surfaces"))
|
if (dict.found("surfaces"))
|
||||||
{
|
{
|
||||||
fieldSelection_ = wordReListMatcher::uniq
|
fieldSelection_ = wordRes::uniq
|
||||||
(
|
(
|
||||||
wordReList(dict.lookup("fields"))
|
wordReList(dict.lookup("fields"))
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user