mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: disentangle testing and quoting of regex characters
- originally had tests for regex meta characters strewn across regExp classes as well as wordRe, keyType, string. And had special-purpose quotemeta static function within string that relied on special naming convention for testing the meta characters. The regex meta character testing/handling now relegated entirely to the regExp class(es). Relocate quotemeta to stringOps, with a predicate. - avoid code duplication. Reuse some regExpCxx methods in regExpPosix
This commit is contained in:
committed by
Andrew Heather
parent
cdbc3e2de6
commit
57c1fceabf
@ -40,7 +40,7 @@ int Foam::regExpPosix::grammar(0);
|
||||
namespace
|
||||
{
|
||||
|
||||
// Verify that the entire len was matched
|
||||
// Matched entire length
|
||||
static inline bool fullMatch(const regmatch_t& m, const regoff_t len)
|
||||
{
|
||||
return (m.rm_so == 0 && m.rm_eo == len);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -57,8 +57,8 @@ SourceFiles
|
||||
#ifndef regExpPosix_H
|
||||
#define regExpPosix_H
|
||||
|
||||
#include "regExpCxx.H"
|
||||
#include <regex.h>
|
||||
#include <string>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -66,8 +66,7 @@ namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
template<class String> class SubStrings;
|
||||
|
||||
template<class StringType> class SubStrings;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class regExpPosix Declaration
|
||||
@ -77,7 +76,7 @@ class regExpPosix
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- Precompiled regular expression
|
||||
//- Compiled regular expression
|
||||
regex_t* preg_;
|
||||
|
||||
public:
|
||||
@ -96,39 +95,53 @@ public:
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Test if character appears to be a regular expression meta-character
|
||||
// \return true if character is one of the following:
|
||||
// - any character: '.' \n
|
||||
// - quantifiers: '*', '+', '?' \n
|
||||
// - grouping: '(', '|', ')' \n
|
||||
// - range: '[', ']' \n
|
||||
//
|
||||
// \note The presence of '{', '}' regex bounds is not considered
|
||||
inline static bool meta(char c);
|
||||
//- 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
|
||||
|
||||
//- Construct null
|
||||
inline regExpPosix();
|
||||
//- Default construct
|
||||
inline regExpPosix() noexcept;
|
||||
|
||||
//- Copy construct - disallowed
|
||||
regExpPosix(const regExpPosix&) = delete;
|
||||
|
||||
//- Move construct
|
||||
inline regExpPosix(regExpPosix&& rgx);
|
||||
|
||||
//- Construct from character array
|
||||
inline explicit regExpPosix(const char* pattern);
|
||||
|
||||
//- Construct from string
|
||||
inline explicit regExpPosix(const std::string& pattern);
|
||||
inline regExpPosix(regExpPosix&& rgx) noexcept;
|
||||
|
||||
//- Construct from character array, optionally ignore case
|
||||
inline regExpPosix(const char* pattern, bool ignoreCase);
|
||||
inline explicit regExpPosix
|
||||
(
|
||||
const char* pattern,
|
||||
const bool ignoreCase = false
|
||||
);
|
||||
|
||||
//- Construct from string, optionally ignore case
|
||||
inline regExpPosix(const std::string& pattern, bool ignoreCase);
|
||||
inline explicit regExpPosix
|
||||
(
|
||||
const std::string& pattern,
|
||||
const bool ignoreCase = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,61 +27,15 @@ License
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::regExpPosix::meta(char c)
|
||||
{
|
||||
return
|
||||
(
|
||||
(c == '.') // any character
|
||||
|| (c == '*' || c == '+' || c == '?') // quantifiers
|
||||
|| (c == '(' || c == ')' || c == '|') // grouping/branching
|
||||
|| (c == '[' || c == ']') // range
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::regExpPosix::regExpPosix()
|
||||
inline Foam::regExpPosix::regExpPosix() noexcept
|
||||
:
|
||||
preg_(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::regExpPosix::regExpPosix(const char* pattern)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, false);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpPosix::regExpPosix(const std::string& pattern)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, false);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpPosix::regExpPosix(const char* pattern, bool ignoreCase)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, ignoreCase);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpPosix::regExpPosix(const std::string& pattern, bool ignoreCase)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, ignoreCase);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpPosix::regExpPosix(regExpPosix&& rgx)
|
||||
inline Foam::regExpPosix::regExpPosix(regExpPosix&& rgx) noexcept
|
||||
:
|
||||
preg_(rgx.preg_)
|
||||
{
|
||||
@ -89,6 +43,30 @@ inline Foam::regExpPosix::regExpPosix(regExpPosix&& rgx)
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpPosix::regExpPosix
|
||||
(
|
||||
const char* pattern,
|
||||
const bool ignoreCase
|
||||
)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, ignoreCase);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpPosix::regExpPosix
|
||||
(
|
||||
const std::string& pattern,
|
||||
const bool ignoreCase
|
||||
)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, ignoreCase);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::regExpPosix::~regExpPosix()
|
||||
@ -143,8 +121,12 @@ inline bool Foam::regExpPosix::operator()(const std::string& text) const
|
||||
|
||||
inline void Foam::regExpPosix::operator=(regExpPosix&& rgx)
|
||||
{
|
||||
clear();
|
||||
swap(rgx);
|
||||
if (this != &rgx)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
clear();
|
||||
swap(rgx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -80,6 +80,7 @@ class regExpCxx
|
||||
//- Track if input pattern was OK - ie, has a length
|
||||
bool ok_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Select grammar based on regExpCxx optimisationSwitch
|
||||
@ -102,39 +103,67 @@ public:
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Test if character appears to be a regular expression meta-character
|
||||
// \return true if character is one of the following:
|
||||
//- Test if character is a regex meta-character
|
||||
// \return True if character is one of the following:
|
||||
// - any character: '.' \n
|
||||
// - quantifiers: '*', '+', '?' \n
|
||||
// - grouping: '(', '|', ')' \n
|
||||
// - range: '[', ']' \n
|
||||
//
|
||||
// \note The presence of '{', '}' regex bounds is not considered
|
||||
inline static bool meta(const char c);
|
||||
// \note Regex bounds '{', '}' are not considered
|
||||
inline static bool is_meta(const char c) noexcept;
|
||||
|
||||
//- Test if string contains any (unquoted) meta-characters
|
||||
inline static bool is_meta
|
||||
(
|
||||
const std::string& str,
|
||||
const char quote = '\\'
|
||||
);
|
||||
|
||||
|
||||
// Public Classes
|
||||
|
||||
//- Functor wrapper for testing meta-characters
|
||||
struct meta
|
||||
{
|
||||
//- Test if character is a regex meta-character
|
||||
bool operator()(const char c) const noexcept
|
||||
{
|
||||
return is_meta(c);
|
||||
}
|
||||
|
||||
//- Test string for meta-characters
|
||||
bool operator()(const std::string& s, const char q = '\\') const
|
||||
{
|
||||
return is_meta(s, q);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
//- Default construct
|
||||
inline regExpCxx();
|
||||
|
||||
//- Copy construct
|
||||
inline regExpCxx(const regExpCxx& rgx);
|
||||
|
||||
//- Move construct
|
||||
inline regExpCxx(regExpCxx&& rgx);
|
||||
|
||||
//- Construct from character array
|
||||
inline explicit regExpCxx(const char* pattern);
|
||||
|
||||
//- Construct from string
|
||||
inline explicit regExpCxx(const std::string& pattern);
|
||||
inline regExpCxx(regExpCxx&& rgx) noexcept;
|
||||
|
||||
//- Construct from character array, optionally ignore case
|
||||
inline regExpCxx(const char* pattern, bool ignoreCase);
|
||||
inline explicit regExpCxx
|
||||
(
|
||||
const char* pattern,
|
||||
const bool ignoreCase = false
|
||||
);
|
||||
|
||||
//- Construct from string, optionally ignore case
|
||||
inline regExpCxx(const std::string& pattern, bool ignoreCase);
|
||||
inline explicit regExpCxx
|
||||
(
|
||||
const std::string& pattern,
|
||||
const bool ignoreCase = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,7 +39,7 @@ inline std::regex::flag_type Foam::regExpCxx::syntax()
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::regExpCxx::meta(const char c)
|
||||
inline bool Foam::regExpCxx::is_meta(const char c) noexcept
|
||||
{
|
||||
return
|
||||
(
|
||||
@ -51,6 +51,32 @@ inline bool Foam::regExpCxx::meta(const char c)
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::regExpCxx::is_meta
|
||||
(
|
||||
const std::string& str,
|
||||
const char quote
|
||||
)
|
||||
{
|
||||
bool escaped = false;
|
||||
for (const char c : str)
|
||||
{
|
||||
if (quote && c == quote)
|
||||
{
|
||||
escaped = !escaped; // toggle state
|
||||
}
|
||||
else if (escaped)
|
||||
{
|
||||
escaped = false;
|
||||
}
|
||||
else if (is_meta(c))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::regExpCxx::regExpCxx()
|
||||
@ -67,7 +93,7 @@ inline Foam::regExpCxx::regExpCxx(const regExpCxx& rgx)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::regExpCxx::regExpCxx(regExpCxx&& rgx)
|
||||
inline Foam::regExpCxx::regExpCxx(regExpCxx&& rgx) noexcept
|
||||
:
|
||||
re_(std::move(rgx.re_)),
|
||||
ok_(rgx.ok_)
|
||||
@ -76,25 +102,11 @@ inline Foam::regExpCxx::regExpCxx(regExpCxx&& rgx)
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpCxx::regExpCxx(const char* pattern)
|
||||
:
|
||||
re_(),
|
||||
ok_(false)
|
||||
{
|
||||
set(pattern, false);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpCxx::regExpCxx(const std::string& pattern)
|
||||
:
|
||||
re_(),
|
||||
ok_(false)
|
||||
{
|
||||
set(pattern, false);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpCxx::regExpCxx(const char* pattern, bool ignoreCase)
|
||||
inline Foam::regExpCxx::regExpCxx
|
||||
(
|
||||
const char* pattern,
|
||||
const bool ignoreCase
|
||||
)
|
||||
:
|
||||
re_(),
|
||||
ok_(false)
|
||||
@ -103,7 +115,11 @@ inline Foam::regExpCxx::regExpCxx(const char* pattern, bool ignoreCase)
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExpCxx::regExpCxx(const std::string& pattern, bool ignoreCase)
|
||||
inline Foam::regExpCxx::regExpCxx
|
||||
(
|
||||
const std::string& pattern,
|
||||
const bool ignoreCase
|
||||
)
|
||||
:
|
||||
re_(),
|
||||
ok_(false)
|
||||
@ -208,15 +224,23 @@ inline bool Foam::regExpCxx::operator()(const std::string& text) const
|
||||
|
||||
inline void Foam::regExpCxx::operator=(const regExpCxx& rgx)
|
||||
{
|
||||
re_ = rgx.re_;
|
||||
ok_ = rgx.ok_;
|
||||
if (this != &rgx)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
re_ = rgx.re_;
|
||||
ok_ = rgx.ok_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::regExpCxx::operator=(regExpCxx&& rgx)
|
||||
{
|
||||
clear();
|
||||
swap(rgx);
|
||||
if (this != &rgx)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
clear();
|
||||
swap(rgx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -192,11 +192,6 @@ public:
|
||||
template<class String>
|
||||
static inline bool valid(const std::string& str);
|
||||
|
||||
//- Does this string contain meta-characters?
|
||||
// The meta characters can be optionally quoted.
|
||||
template<class String>
|
||||
static inline bool meta(const std::string& str, const char quote='\\');
|
||||
|
||||
//- Strip invalid characters from the given string
|
||||
template<class String>
|
||||
static inline bool stripInvalid(std::string& str);
|
||||
@ -205,14 +200,6 @@ public:
|
||||
template<class String>
|
||||
static inline String validate(const std::string& str);
|
||||
|
||||
//- Return a String with quoted meta-characters from the given string
|
||||
template<class String>
|
||||
static inline string quotemeta
|
||||
(
|
||||
const std::string& str,
|
||||
const char quote = '\\'
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
|
||||
@ -172,68 +172,6 @@ inline bool Foam::string::stripInvalid(std::string& str)
|
||||
}
|
||||
|
||||
|
||||
template<class String>
|
||||
inline bool Foam::string::meta(const std::string& str, const char quote)
|
||||
{
|
||||
int escaped = 0;
|
||||
for (auto iter = str.cbegin(); iter != str.cend(); ++iter)
|
||||
{
|
||||
const char c = *iter;
|
||||
if (quote && c == quote)
|
||||
{
|
||||
escaped ^= 1; // toggle state
|
||||
}
|
||||
else if (escaped)
|
||||
{
|
||||
escaped = 0;
|
||||
}
|
||||
else if (String::meta(c))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class String>
|
||||
inline Foam::string
|
||||
Foam::string::quotemeta(const std::string& str, const char quote)
|
||||
{
|
||||
if (!quote)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
string sQuoted;
|
||||
sQuoted.reserve(2*str.size());
|
||||
|
||||
int escaped = 0;
|
||||
for (auto iter = str.cbegin(); iter != str.cend(); ++iter)
|
||||
{
|
||||
const char c = *iter;
|
||||
if (c == quote)
|
||||
{
|
||||
escaped ^= 1; // toggle state
|
||||
}
|
||||
else if (escaped)
|
||||
{
|
||||
escaped = 0;
|
||||
}
|
||||
else if (String::meta(c))
|
||||
{
|
||||
sQuoted += quote;
|
||||
}
|
||||
|
||||
sQuoted += c;
|
||||
}
|
||||
|
||||
sQuoted.shrink_to_fit();
|
||||
|
||||
return sQuoted;
|
||||
}
|
||||
|
||||
|
||||
template<class String>
|
||||
inline String Foam::string::validate(const std::string& str)
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -77,6 +77,15 @@ namespace stringOps
|
||||
return wordRes::matcher(patterns)(text);
|
||||
}
|
||||
|
||||
//- Quote any meta-characters in given string
|
||||
template<class StringType, class UnaryPredicate>
|
||||
StringType quotemeta
|
||||
(
|
||||
const StringType& str,
|
||||
const UnaryPredicate& meta,
|
||||
const char quote = '\\'
|
||||
);
|
||||
|
||||
//- Expand occurrences of variables according to the mapping
|
||||
//- and return the expanded string.
|
||||
//
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,45 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class StringType, class UnaryPredicate>
|
||||
StringType Foam::stringOps::quotemeta
|
||||
(
|
||||
const StringType& str,
|
||||
const UnaryPredicate& meta,
|
||||
const char quote
|
||||
)
|
||||
{
|
||||
if (str.empty() || !quote)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
StringType result;
|
||||
result.reserve(1.5*str.size()); // Moderately pessimistic
|
||||
|
||||
bool escaped = false;
|
||||
for (const char c : str)
|
||||
{
|
||||
if (c == quote)
|
||||
{
|
||||
escaped = !escaped; // toggle state
|
||||
}
|
||||
else if (escaped)
|
||||
{
|
||||
escaped = false;
|
||||
}
|
||||
else if (meta(c))
|
||||
{
|
||||
result += quote;
|
||||
}
|
||||
result += c;
|
||||
}
|
||||
|
||||
result.shrink_to_fit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
Foam::SubStrings<StringType> Foam::stringOps::split
|
||||
(
|
||||
|
||||
@ -153,17 +153,11 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Is this a meta character?
|
||||
inline static bool meta(char c);
|
||||
|
||||
//- Is this character valid for a wordRe?
|
||||
// This is largely identical with what word accepts, but also
|
||||
// permit brace-brackets, which are valid for some regexs.
|
||||
inline static bool valid(char c);
|
||||
|
||||
//- Test string for regular expression meta characters
|
||||
inline static bool isPattern(const std::string& str);
|
||||
|
||||
|
||||
// Access
|
||||
|
||||
@ -211,9 +205,6 @@ public:
|
||||
|
||||
// Miscellaneous
|
||||
|
||||
//- Return a string with quoted meta-characters
|
||||
inline string quotemeta() const;
|
||||
|
||||
//- Output some basic info
|
||||
Ostream& info(Ostream& os) const;
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,24 +28,12 @@ License
|
||||
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::wordRe::meta(char c)
|
||||
{
|
||||
return regExp::meta(c);
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::wordRe::valid(char c)
|
||||
{
|
||||
return keyType::valid(c);
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::wordRe::isPattern(const std::string& str)
|
||||
{
|
||||
return string::meta<regExp>(str);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::wordRe::wordRe()
|
||||
@ -184,7 +172,7 @@ inline bool Foam::wordRe::compile(const compOption opt)
|
||||
}
|
||||
else if (opt & wordRe::DETECT)
|
||||
{
|
||||
comp = string::meta<regExp>(*this) || !string::valid<word>(*this);
|
||||
comp = regExp::is_meta(*this) || !string::valid<word>(*this);
|
||||
}
|
||||
else if (opt & wordRe::ICASE)
|
||||
{
|
||||
@ -237,12 +225,6 @@ inline bool Foam::wordRe::match(const std::string& text, bool literal) const
|
||||
}
|
||||
|
||||
|
||||
inline Foam::string Foam::wordRe::quotemeta() const
|
||||
{
|
||||
return string::quotemeta<regExp>(*this);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::wordRe::set(const std::string& str, const compOption opt)
|
||||
{
|
||||
assign(str);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,6 +26,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ddt2.H"
|
||||
#include "stringOps.H"
|
||||
#include "stringListOps.H"
|
||||
#include "volFields.H"
|
||||
#include "dictionary.H"
|
||||
@ -107,7 +108,7 @@ Foam::functionObjects::ddt2::ddt2
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
selectFields_(),
|
||||
resultName_(word::null),
|
||||
resultName_(),
|
||||
denyField_(),
|
||||
results_(),
|
||||
mag_(dict.getOrDefault("mag", false))
|
||||
@ -150,10 +151,8 @@ bool Foam::functionObjects::ddt2::read(const dictionary& dict)
|
||||
{
|
||||
denyField_.set
|
||||
(
|
||||
string::quotemeta<regExp>
|
||||
(
|
||||
resultName_
|
||||
).replace("@@", "(.+)")
|
||||
stringOps::quotemeta(resultName_, regExp::meta())
|
||||
.replace("@@", "(.+)")
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user