mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: regExp with explicit constructor
- use separate constructor for ignore-case option (cf. wordRe treatment) - constructors/destructor now inline.
This commit is contained in:
@ -77,38 +77,6 @@ bool Foam::regExp::matchGrouping
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::regExp::regExp()
|
||||
:
|
||||
preg_(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
Foam::regExp::regExp(const char* pattern, bool ignoreCase)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, ignoreCase);
|
||||
}
|
||||
|
||||
|
||||
Foam::regExp::regExp(const std::string& pattern, bool ignoreCase)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern.c_str(), ignoreCase);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::regExp::~regExp()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::regExp::set(const char* pattern, bool ignoreCase)
|
||||
|
||||
@ -77,7 +77,7 @@ class regExp
|
||||
//- Return true if it matches and sets the sub-groups matched.
|
||||
bool matchGrouping
|
||||
(
|
||||
const std::string&,
|
||||
const std::string& text,
|
||||
List<std::string>& groups
|
||||
) const;
|
||||
|
||||
@ -99,17 +99,23 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
regExp();
|
||||
inline regExp();
|
||||
|
||||
//- Construct from character array
|
||||
inline explicit regExp(const char* pattern);
|
||||
|
||||
//- Construct from string
|
||||
inline explicit regExp(const std::string& pattern);
|
||||
|
||||
//- Construct from character array, optionally ignore case
|
||||
regExp(const char* pattern, bool ignoreCase=false);
|
||||
inline regExp(const char* pattern, bool ignoreCase);
|
||||
|
||||
//- Construct from string, optionally ignore case
|
||||
regExp(const std::string& pattern, bool ignoreCase=false);
|
||||
inline regExp(const std::string& pattern, bool ignoreCase);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~regExp();
|
||||
inline ~regExp();
|
||||
|
||||
|
||||
// Member functions
|
||||
@ -143,20 +149,20 @@ public:
|
||||
|
||||
// Matching/Searching
|
||||
|
||||
//- Find position within string.
|
||||
// \Return The index where it begins or string::npos if not found
|
||||
//- Find position within the text.
|
||||
// \return The index where it begins or string::npos if not found
|
||||
std::string::size_type find(const std::string& text) const;
|
||||
|
||||
//- Return true if it matches the entire string
|
||||
//- 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;
|
||||
|
||||
//- Return true if it matches and sets the sub-groups matched
|
||||
//- True if the regex matches the text, set the sub-groups matched.
|
||||
// The begin-of-line (^) and end-of-line ($) anchors are implicit
|
||||
bool match(const std::string& text, List<std::string>& groups) const;
|
||||
|
||||
//- Return true if the regex was found within string
|
||||
bool search(const std::string& text) const;
|
||||
//- Return true if the regex was found within the text
|
||||
inline bool search(const std::string& text) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
@ -38,6 +38,54 @@ inline bool Foam::regExp::meta(const char c)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::regExp::regExp()
|
||||
:
|
||||
preg_(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::regExp::regExp(const char* pattern)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, false);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExp::regExp(const std::string& pattern)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, false);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExp::regExp(const char* pattern, bool ignoreCase)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, ignoreCase);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::regExp::regExp(const std::string& pattern, bool ignoreCase)
|
||||
:
|
||||
preg_(nullptr)
|
||||
{
|
||||
set(pattern, ignoreCase);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::regExp::~regExp()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::regExp::empty() const
|
||||
|
||||
@ -26,7 +26,7 @@ License
|
||||
#include "STARCDsurfaceFormatCore.H"
|
||||
#include "clock.H"
|
||||
#include "regExp.H"
|
||||
#include "IStringStream.H"
|
||||
#include "IFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
@ -47,7 +47,7 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
|
||||
return lookup;
|
||||
}
|
||||
|
||||
regExp ctnameRE
|
||||
const regExp ctnameRE
|
||||
(
|
||||
" *CTNA[^ ]*" // keyword - min 4 chars
|
||||
"[[:space:]]+" // space delimited
|
||||
@ -64,13 +64,11 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
|
||||
if (ctnameRE.match(line, groups))
|
||||
{
|
||||
const label tableId = atoi(groups[0].c_str());
|
||||
const word tableName = word::validated(groups[1]);
|
||||
|
||||
// strip bad chars
|
||||
string::stripInvalid<word>(groups[1]);
|
||||
|
||||
if (!groups[1].empty())
|
||||
if (!tableName.empty())
|
||||
{
|
||||
lookup.insert(tableId, groups[1]);
|
||||
lookup.insert(tableId, tableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user