DEFEATURE: remove POSIX regex interface (#3343)

- compiler versions are now sufficient that only the C++ regex
  interface is now being used. Can remove the old POSIX code
  accordingly.

  This change also removes any dependency on the SubStrings class to
  manage the matching results.

ENH: remove OpenFOAM dependencies from MacOS addr2line utility
This commit is contained in:
Mark Olesen 2025-03-21 10:18:19 +01:00
parent 4de0b84c2f
commit aaa9af9ee8
14 changed files with 17 additions and 947 deletions

View File

@ -1,3 +1,3 @@
Test-regex1.C
Test-regex1.cxx
EXE = $(FOAM_USER_APPBIN)/Test-regex1

View File

@ -35,11 +35,8 @@ Description
#include "Switch.H"
#include "stringOps.H"
#include "SubStrings.H"
#include "regExp.H"
#include "regExpCxx.H"
#ifndef _WIN32
#include "regExpPosix.H"
#endif
using namespace Foam;
@ -89,20 +86,6 @@ static Ostream& operator<<(Ostream& os, const regExpCxx::results_type& sm)
}
// Simple output of match groups
#ifndef _WIN32
static Ostream& operator<<(Ostream& os, const regExpPosix::results_type& sm)
{
for (std::smatch::size_type i = 1; i < sm.size(); ++i)
{
os << " " << sm.str(i);
}
return os;
}
#endif
template<class RegexType>
void generalTests()
{
@ -299,10 +282,6 @@ int main(int argc, char *argv[])
argList::noFunctionObjects();
argList::noParallel();
argList::addBoolOption("cxx", "Test C++11 regular expressions");
#ifndef _WIN32
argList::addBoolOption("posix", "Test POSIX regular expressions");
#endif
argList::addOption
(
"regex",
@ -321,34 +300,16 @@ int main(int argc, char *argv[])
#ifdef _GLIBCXX_RELEASE
Info<< "_GLIBCXX_RELEASE = " << (_GLIBCXX_RELEASE) << nl;
#endif
if constexpr (std::is_same_v<regExp, regExpCxx>)
{
Info<< "Foam::regExp uses C++11 regex" << nl;
}
#ifndef _WIN32
if constexpr (std::is_same_v<regExp, regExpPosix>)
{
Info<< "Foam::regExp uses POSIX regex" << nl;
}
#ifdef __clang_major__
Info<< "__clang_major__ = " << (__clang_major__) << nl;
#endif
Info<< "sizeof std::regex: " << sizeof(std::regex) << nl;
Info<< "sizeof regex C++11: " << sizeof(regExpCxx) << nl;
#ifndef _WIN32
Info<< "sizeof regex POSIX: " << sizeof(regExpPosix) << nl;
#endif
Info<< "sizeof regExp: " << sizeof(Foam::regExp) << nl;
Info<< "sizeof word: " << sizeof(Foam::word) << nl;
Info<< "sizeof wordRe: " << sizeof(Foam::wordRe) << nl;
Info<< "sizeof keyType: " << sizeof(Foam::keyType) << nl;
if (!args.count({"cxx", "posix"}))
{
args.setOption("cxx");
Info<< "Assuming -cxx as default" << nl;
}
Info<< nl;
if (args.found("regex"))
{
std::string expr(args["regex"]);
@ -359,31 +320,15 @@ int main(int argc, char *argv[])
<< "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;
if (args.found("cxx"))
{
generalTests<regExpCxx>();
}
#ifndef _WIN32
if (args.found("posix"))
{
generalTests<regExpPosix>();
}
#endif
}
for (label argi = 1; argi < args.size(); ++argi)
@ -394,17 +339,9 @@ int main(int argc, char *argv[])
Info<< "Test expressions:" << tests << endl;
IOobject::writeDivider(Info) << endl;
if (args.found("cxx"))
{
testExpressions<regExpCxx>(tests);
}
#ifndef _WIN32
if (args.found("posix"))
{
testExpressions<regExpPosix>(tests);
}
#endif
}
Info<< "\nDone" << nl << endl;

View File

@ -1,3 +1,3 @@
addr2line.C
addr2line.cxx
EXE = $(FOAM_APPBIN)/addr2line

View File

@ -1,2 +1,6 @@
/* Disable normal project defaults */
PROJECT_INC =
PROJECT_LIBS =
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 Alexey Matveichev
Copyright (C) 2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,12 +34,11 @@ Description
#include <getopt.h>
#include <cstdlib>
#include <regex>
#include <string>
#include <vector>
#include <iostream>
#include "regExp.H"
#include "SubStrings.H"
static void usage();
static void version();
@ -53,7 +53,6 @@ int main(int argc, char *argv[])
int optHelp = 0, optFunctions = 0, optVersion = 0;
int ch;
std::string filename = "a.out";
std::vector<std::string> addresses;
static struct option opts[] =
{
@ -100,15 +99,9 @@ int main(int argc, char *argv[])
argc -= optind;
argv += optind;
while (argc > 0)
{
addresses.push_back(std::string(*argv));
++argv;
--argc;
}
for (const auto& addr : addresses)
for (std::string addr; argc > 0; --argc, ++argv)
{
addr.assign(*argv);
std::cout<< '\n' << getLine(filename, addr).c_str() << '\n';
}
@ -190,10 +183,10 @@ std::string getLine(const std::string& filename, const std::string& addr)
);
Foam::regExp re(".+LineEntry: .+: (.+):([0-9]+):[0-9]+");
static std::regex re(".+LineEntry: .+: (.+):([0-9]+):[0-9]+");
std::smatch groups;
Foam::regExp::results_type groups;
if (!re.match(line, groups))
if (!std::regex_match(line, groups, re))
{
line = "??:0";
}

View File

@ -12,7 +12,6 @@ signals/sigStopAtWriteNow.C
signals/sigWriteNow.C
signals/timer.C
regExp/regExpPosix.C
fileStat/fileStat.C
/*

View File

@ -1,43 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 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/>.
Typedef
Foam::regExp
Description
Selection of preferred regular expression implementation
\*---------------------------------------------------------------------------*/
#ifndef Foam_regExp_H
#define Foam_regExp_H
#include "regExpCxx.H"
#include "regExpPosix.H"
#include "regExpFwd.H"
#endif
// ************************************************************************* //

View File

@ -1,56 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 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/>.
Typedef
Foam::regExp
Description
Selection of preferred regular expression implementation
\*---------------------------------------------------------------------------*/
#ifndef Foam_regExpFwd_H
#define Foam_regExpFwd_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class regExpCxx;
class regExpPosix;
// Newer compilers support regex directly
#if (_GLIBCXX_RELEASE >= 7) || (__clang_major__ >= 7)
typedef regExpCxx regExp;
#else
typedef regExpPosix regExp;
#endif
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,284 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-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/>.
\*---------------------------------------------------------------------------*/
#include "regExpPosix.H"
#include "SubStrings.H"
#include "error.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::regExpPosix::grammar(0);
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace
{
// Matched entire length
static inline bool fullMatch(const regmatch_t& m, const regoff_t len)
{
return (m.rm_so == 0 && m.rm_eo == len);
}
} // End anonymous namespace
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::regExpPosix::set_pattern
(
const char* pattern,
size_t len,
bool ignoreCase
)
{
clear(); // Also sets ctrl_ = 0
const char* pat = pattern;
bool doNegate = false;
// Handle known embedded prefixes
if (len > 2 && pat[0] == '(' && pat[1] == '?')
{
pat += 2;
len -= 2;
for (bool done = false; !done && len; ++pat, --len)
{
switch (*pat)
{
case '!':
{
// Negated (inverted) match
doNegate = true;
break;
}
case 'i':
{
// Ignore-case
ignoreCase = true;
break;
}
case ')':
{
// End of prefix parsing
done = true;
break;
}
}
}
}
// Avoid zero-length patterns
if (len)
{
int flags = REG_EXTENDED;
if (ignoreCase)
{
flags |= REG_ICASE;
}
{
preg_ = new regex_t;
int err = regcomp(preg_, pat, flags);
if (err == 0)
{
ctrl_ = (doNegate ? ctrlType::NEGATED : ctrlType::NORMAL);
return true;
}
else
{
char errbuf[200];
regerror(err, preg_, errbuf, sizeof(errbuf));
FatalErrorInFunction
<< "Failed to compile regular expression '"
<< pattern << "'\n" << errbuf
<< exit(FatalError);
}
}
}
return false;
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::regExpPosix::clear()
{
ctrl_ = 0;
if (preg_)
{
regfree(preg_);
delete preg_;
preg_ = nullptr;
return true;
}
return false;
}
std::string::size_type Foam::regExpPosix::find(const std::string& text) const
{
// Find with negated is probably not very reliable...
if (!preg_ || !ctrl_)
{
// Undefined: never matches
return std::string::npos;
}
else if (text.empty())
{
if (ctrl_ == ctrlType::NEGATED)
{
return 0; // No match - pretend it starts at position 0
}
else
{
return std::string::npos;
}
}
else
{
const size_t nmatch = 1;
regmatch_t pmatch[1];
const bool ok = (regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0);
if (ctrl_ == ctrlType::NEGATED)
{
if (!ok)
{
return 0; // No match - claim that is starts at position 0
}
}
else if (ok)
{
return pmatch[0].rm_so;
}
}
return std::string::npos;
}
bool Foam::regExpPosix::match(const std::string& text) const
{
bool ok = false;
if (!preg_ || !ctrl_)
{
// Undefined: never matches
return false;
}
const auto len = text.length();
if (len)
{
const size_t nmatch = 1;
regmatch_t pmatch[1];
// Verify that the entire string was matched
// - [0] is the entire match result
ok =
(
regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0
&& fullMatch(pmatch[0], len)
);
}
return (ctrl_ == ctrlType::NEGATED ? !ok : ok);
}
bool Foam::regExpPosix::match
(
const std::string& text,
SubStrings<std::string>& matches
) const
{
matches.clear();
// Probably does not make sense for negated pattern...
if (negated())
{
return match(text);
}
const auto len = text.size();
if (preg_ && len)
{
const size_t nmatch = ngroups() + 1;
regmatch_t pmatch[nmatch];
// Verify that the entire string was matched
// - [0] is the entire match result
// - [1..] are the match groups (1..)
if
(
regexec(preg_, text.c_str(), nmatch, pmatch, 0) != 0
|| !fullMatch(pmatch[0], len)
)
{
return false;
}
matches.reserve(nmatch);
for (size_t matchi = 0; matchi < nmatch; ++matchi)
{
const auto& mat = pmatch[matchi];
if (mat.rm_so != -1 && mat.rm_eo != -1)
{
matches.append
(
text.cbegin() + mat.rm_so,
text.cbegin() + mat.rm_eo
);
}
else
{
// This may be misleading...
matches.append(text.cbegin(), text.cbegin());
}
}
return true;
}
return false;
}
// ************************************************************************* //

View File

@ -1,270 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-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/>.
Class
Foam::regExpPosix
Description
Wrapper around POSIX extended regular expressions
with some additional prefix-handling. The prefix-handling is
loosely oriented on PCRE regular expressions and provides a
simple means of tuning the expressions.
The prefixes are detected as \c (?...) at the beginning of
the regular expression. Any unknown/unsupported prefixes are silently
ignored.
- "(?!i)" :
one or more embedded pattern-match modifiers for the entire pattern.
- the \c 'i' indicates ignore-case
- the \c '!' (exclamation) indicates negated (inverted) matching
.
SeeAlso
The manpage regex(7) for more information about POSIX regular expressions.
These differ somewhat from \c Perl and \c sed regular expressions.
SeeAlso
Foam::regExp and Foam::regExpCxx
Warning
This class should not be used directly.
Use the Foam::regExp typedef instead.
\deprecated
This class will be superseded by Foam::regExpCxx as compiler support
for regular expressions continues to improve.
SourceFiles
regExpPosix.C
regExpPosixI.H
\*---------------------------------------------------------------------------*/
#ifndef Foam_regExpPosix_H
#define Foam_regExpPosix_H
#include "regExpCxx.H"
#include <regex.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
template<class StringType> class SubStrings;
/*---------------------------------------------------------------------------*\
Class regExpPosix Declaration
\*---------------------------------------------------------------------------*/
class regExpPosix
{
// Data Types
//- Simple control types
enum ctrlType { EMPTY = 0, NORMAL = 1, NEGATED = 2 };
// Private Data
//- Compiled regular expression
regex_t* preg_;
//- Track if input pattern is non-empty, negated etc.
unsigned char ctrl_;
// Private Member Functions
//- Assign pattern
bool set_pattern(const char* pattern, size_t len, bool ignoreCase);
public:
// Public Types
//- Type for matches - similar to std::smatch
typedef SubStrings<std::string> results_type;
// Static Member Data
//- Grammar (unused) - for compatibility with Foam::regExpCxx
static int grammar;
// Static Member Functions
//- Test if character is a regex meta-character
inline static bool is_meta(const char c) noexcept
{
return regExpCxx::is_meta(c);
}
//- Test if string contains any (unquoted) meta-characters
inline static bool is_meta
(
const std::string& str,
const char quote = '\\'
)
{
return regExpCxx::is_meta(str, quote);
}
// Public Classes
//- Functor wrapper for testing meta-characters
using meta = regExpCxx::meta;
// Constructors
//- Default construct
inline regExpPosix() noexcept;
//- Copy construct - disallowed
regExpPosix(const regExpPosix&) = delete;
//- Move construct
inline regExpPosix(regExpPosix&& rgx) noexcept;
//- Construct from character array, optionally ignore case
inline explicit regExpPosix
(
const char* pattern,
const bool ignoreCase = false
);
//- Construct from string, optionally ignore case
inline explicit regExpPosix
(
const std::string& pattern,
const bool ignoreCase = false
);
//- Destructor
inline ~regExpPosix();
// Member Functions
// Access
//- Return true if a precompiled expression does not exist
inline bool empty() const noexcept;
//- Return true if a precompiled expression exists
inline bool exists() const noexcept;
//- True if pattern matching is negated
inline bool negated() const noexcept;
//- Change pattern negation, return previous value
inline bool negate(bool on) noexcept;
//- The number of capture groups for a non-empty,
//- non-negated expressions
inline unsigned ngroups() const;
// Editing
//- Clear expression.
// \return True if expression had existed prior to the clear.
bool clear();
//- Swap contents
inline void swap(regExpPosix& rgx);
//- Compile pattern into a regular expression, optionally ignore case.
// \return True if the pattern was compiled
inline bool set(const char* pattern, bool ignoreCase=false);
//- Compile pattern into a regular expression, optionally ignore case.
// \return True if the pattern was compiled
inline bool set(const std::string& pattern, bool ignoreCase=false);
// Matching/Searching
//- Find position within the text.
// \return The index where it begins or string::npos if not found
//
// \note does not properly work with negated regex!
std::string::size_type find(const std::string& text) const;
//- True if the regex matches the entire text.
// The begin-of-line (^) and end-of-line ($) anchors are implicit
bool match(const std::string& text) const;
//- True if the regex matches the text, set the matches.
// The first group starts at index 1 (0 is the entire match).
// The begin-of-line (^) and end-of-line ($) anchors are implicit
//
// \note does not properly work with negated regex!
bool match(const std::string& text, results_type& matches) const;
//- Return true if the regex was found within the text
inline bool search(const std::string& text) const;
// Member Operators
//- Perform match on text
inline bool operator()(const std::string& text) const;
//- Copy assignment - disallowed
void operator=(const regExpPosix&) = delete;
//- Move assignment
inline void operator=(regExpPosix&& rgx);
//- Assign and compile pattern from a character array.
// Matching is case sensitive.
inline void operator=(const char* pattern);
//- Assign and compile pattern from string.
// Matching is case sensitive.
inline void operator=(const std::string& pattern);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "regExpPosixI.H"
#endif
// ************************************************************************* //

View File

@ -1,209 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-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/>.
\*---------------------------------------------------------------------------*/
#include <utility> // For std::swap
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::regExpPosix::regExpPosix() noexcept
:
preg_(nullptr),
ctrl_(0)
{}
inline Foam::regExpPosix::regExpPosix(regExpPosix&& rgx) noexcept
:
preg_(rgx.preg_),
ctrl_(rgx.ctrl_)
{
rgx.preg_ = nullptr;
rgx.ctrl_ = 0;
}
inline Foam::regExpPosix::regExpPosix
(
const char* pattern,
const bool ignoreCase
)
:
preg_(nullptr),
ctrl_(0)
{
set(pattern, ignoreCase);
}
inline Foam::regExpPosix::regExpPosix
(
const std::string& pattern,
const bool ignoreCase
)
:
preg_(nullptr),
ctrl_(0)
{
set(pattern, ignoreCase);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
inline Foam::regExpPosix::~regExpPosix()
{
clear();
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
inline bool Foam::regExpPosix::empty() const noexcept
{
return !preg_;
}
inline bool Foam::regExpPosix::exists() const noexcept
{
return preg_;
}
inline bool Foam::regExpPosix::negated() const noexcept
{
return (ctrl_ == ctrlType::NEGATED);
}
inline bool Foam::regExpPosix::negate(bool on) noexcept
{
bool old(ctrl_ == ctrlType::NEGATED);
if (on)
{
if (ctrl_)
{
ctrl_ = ctrlType::NEGATED;
}
}
else if (old)
{
ctrl_ = ctrlType::NORMAL;
}
return old;
}
inline unsigned Foam::regExpPosix::ngroups() const
{
return (preg_ && ctrl_ == ctrlType::NORMAL) ? preg_->re_nsub : 0;
}
inline bool Foam::regExpPosix::set(const char* pattern, bool ignoreCase)
{
// Silently handle nullptr
return set_pattern
(
pattern,
(pattern ? std::char_traits<char>::length(pattern) : 0),
ignoreCase
);
}
inline bool Foam::regExpPosix::set(const std::string& pattern, bool ignoreCase)
{
return set_pattern
(
pattern.data(),
pattern.length(),
ignoreCase
);
}
inline bool Foam::regExpPosix::search(const std::string& text) const
{
if (!ctrl_)
{
return false;
}
else if (text.empty())
{
return (ctrl_ == ctrlType::NEGATED);
}
return std::string::npos != find(text);
}
inline void Foam::regExpPosix::swap(regExpPosix& rgx)
{
if (this != &rgx)
{
// Self-swap is a no-op
std::swap(preg_, rgx.preg_);
std::swap(ctrl_, rgx.ctrl_);
}
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
inline bool Foam::regExpPosix::operator()(const std::string& text) const
{
return match(text);
}
inline void Foam::regExpPosix::operator=(regExpPosix&& rgx)
{
if (this != &rgx)
{
// Self-assignment is a no-op
clear();
swap(rgx);
}
}
inline void Foam::regExpPosix::operator=(const char* pattern)
{
set(pattern);
}
inline void Foam::regExpPosix::operator=(const std::string& pattern)
{
set(pattern);
}
// ************************************************************************* //

View File

@ -30,7 +30,6 @@ License
#include "clock.H"
#include "regExp.H"
#include "IFstream.H"
#include "SubStrings.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //