mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: ensure self-assignment and self-swapping are a no-op for string types
- simplifies their use when reordering lists etc. (word, fileName, keyType, wordRe) - "unfriend" IO operators for string types. They require no internal access - add compile/uncompile methods to keyType for symmetry with wordRe - when outputting keyType/wordRe, be more explicit about them using writeQuoted()
This commit is contained in:
committed by
Andrew Heather
parent
df35627e69
commit
60c314150c
@ -84,7 +84,7 @@ public:
|
||||
// - range: '[', ']' \n
|
||||
//
|
||||
// \note The presence of '{', '}' regex bounds is not considered
|
||||
inline static bool meta(const char c);
|
||||
inline static bool meta(char c);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
@ -28,7 +28,7 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::regExp::meta(const char c)
|
||||
inline bool Foam::regExp::meta(char c)
|
||||
{
|
||||
return
|
||||
(
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -35,9 +35,10 @@ License
|
||||
|
||||
void Foam::Ostream::decrIndent()
|
||||
{
|
||||
if (indentLevel_ == 0)
|
||||
if (!indentLevel_)
|
||||
{
|
||||
cerr<< "Ostream::decrIndent() : attempt to decrement 0 indent level"
|
||||
std::cerr
|
||||
<< "Ostream::decrIndent() : attempt to decrement 0 indent level"
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
@ -56,17 +57,17 @@ Foam::Ostream& Foam::Ostream::write(const keyType& kw)
|
||||
Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw)
|
||||
{
|
||||
indent();
|
||||
write(kw);
|
||||
writeQuoted(kw, kw.isPattern());
|
||||
|
||||
label nSpaces = entryIndentation_ - label(kw.size());
|
||||
|
||||
// pattern is surrounded by quotes
|
||||
// Account for quotes surrounding pattern
|
||||
if (kw.isPattern())
|
||||
{
|
||||
nSpaces -= 2;
|
||||
}
|
||||
|
||||
// could also increment by indentSize_ ...
|
||||
// Could also increment by indentSize_ ...
|
||||
if (nSpaces < 1)
|
||||
{
|
||||
nSpaces = 1;
|
||||
@ -81,9 +82,9 @@ Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw)
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::Ostream::beginBlock(const keyType& keyword)
|
||||
Foam::Ostream& Foam::Ostream::beginBlock(const keyType& kw)
|
||||
{
|
||||
indent(); write(keyword); write('\n');
|
||||
indent(); writeQuoted(kw, kw.isPattern()); write('\n');
|
||||
beginBlock();
|
||||
|
||||
return *this;
|
||||
|
||||
@ -185,7 +185,7 @@ public:
|
||||
|
||||
//- Write begin block group with the given name
|
||||
// Increments indentation, adds newline.
|
||||
virtual Ostream& beginBlock(const keyType& keyword);
|
||||
virtual Ostream& beginBlock(const keyType& kw);
|
||||
|
||||
//- Write begin block group without a name
|
||||
// Increments indentation, adds newline.
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -55,15 +55,6 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
class SHA1;
|
||||
class SHA1Digest;
|
||||
Ostream& operator<<(Ostream&, const SHA1&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class SHA1 Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -91,6 +82,7 @@ class SHA1
|
||||
//- The input processing buffer
|
||||
uint32_t buffer_[32];
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Process data block-wise, LEN must be a multiple of 64!
|
||||
@ -172,14 +164,13 @@ public:
|
||||
//- Convert to a SHA1Digest,
|
||||
// calculate current %digest from appended data
|
||||
inline operator SHA1Digest() const;
|
||||
};
|
||||
|
||||
|
||||
// Friend Operators
|
||||
// IOstream Operators
|
||||
|
||||
//- Output the %digest
|
||||
inline friend Ostream& operator<<(Ostream&, const SHA1&);
|
||||
|
||||
};
|
||||
inline Ostream& operator<<(Ostream& os, const SHA1& sha);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -136,7 +136,7 @@ inline Foam::SHA1::operator Foam::SHA1Digest() const
|
||||
|
||||
inline Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1& sha)
|
||||
{
|
||||
return os << sha.digest();
|
||||
return (os << sha.digest());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
@ -62,10 +62,6 @@ typedef List<word> wordList;
|
||||
class wordRe;
|
||||
class fileName;
|
||||
|
||||
Istream& operator>>(Istream&, fileName&);
|
||||
Ostream& operator<<(Ostream&, const fileName&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fileName Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -74,12 +70,6 @@ class fileName
|
||||
:
|
||||
public string
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Strip invalid characters
|
||||
inline void stripInvalid();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Enumerations to handle directory entry types.
|
||||
@ -94,7 +84,10 @@ public:
|
||||
|
||||
// Static data members
|
||||
|
||||
//- The typeName
|
||||
static const char* const typeName;
|
||||
|
||||
//- Debugging
|
||||
static int debug;
|
||||
|
||||
//- An empty fileName
|
||||
@ -161,6 +154,8 @@ public:
|
||||
//- that ignores duplicate or trailing slashes.
|
||||
static bool equals(const std::string& s1, const std::string& s2);
|
||||
|
||||
//- Strip invalid characters
|
||||
inline void stripInvalid();
|
||||
|
||||
//- Cleanup filename
|
||||
//
|
||||
@ -353,15 +348,17 @@ public:
|
||||
) const;
|
||||
|
||||
|
||||
// Member operators
|
||||
// Member Operators
|
||||
|
||||
// Assignment
|
||||
|
||||
//- Copy assignment, no character validation required
|
||||
fileName& operator=(const fileName&) = default;
|
||||
// Self-assignment is a no-op.
|
||||
inline fileName& operator=(const fileName& str);
|
||||
|
||||
//- Move assignment, no character validation required
|
||||
fileName& operator=(fileName&&) = default;
|
||||
// Self-assignment is a no-op.
|
||||
inline fileName& operator=(fileName&& str);
|
||||
|
||||
//- Copy assignment, no character validation required
|
||||
inline fileName& operator=(const word& str);
|
||||
@ -390,15 +387,18 @@ public:
|
||||
//- Append a path element with '/' separator.
|
||||
// No '/' separator is added if this or the argument are empty.
|
||||
fileName& operator/=(const string& other);
|
||||
|
||||
|
||||
// IOstream operators
|
||||
|
||||
friend Istream& operator>>(Istream& is, fileName& fn);
|
||||
friend Ostream& operator<<(Ostream& os, const fileName& fn);
|
||||
};
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
//- Read operator
|
||||
Istream& operator>>(Istream& is, fileName& val);
|
||||
|
||||
//- Write operator
|
||||
Ostream& operator<<(Ostream& os, const fileName& val);
|
||||
|
||||
|
||||
// Global Operators
|
||||
|
||||
//- Assemble words and fileNames as pathnames by adding a '/' separator.
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011 OpenFOAM Foundation
|
||||
@ -25,32 +25,7 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <iostream> // for std::cerr
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::fileName::stripInvalid()
|
||||
{
|
||||
// Skip stripping unless debug is active (to avoid costly operations)
|
||||
if (debug && string::stripInvalid<fileName>(*this))
|
||||
{
|
||||
std::cerr
|
||||
<< "fileName::stripInvalid() called for invalid fileName "
|
||||
<< this->c_str() << std::endl;
|
||||
|
||||
if (debug > 1)
|
||||
{
|
||||
std::cerr
|
||||
<< " For debug level (= " << debug
|
||||
<< ") > 1 this is considered fatal" << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
|
||||
removeRepeated('/');
|
||||
removeTrailing('/');
|
||||
}
|
||||
}
|
||||
|
||||
#include <iostream> // For std::cerr
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -134,6 +109,29 @@ inline bool Foam::fileName::valid(char c)
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::fileName::stripInvalid()
|
||||
{
|
||||
// Only strip when debug is active (potentially costly operation)
|
||||
if (debug && string::stripInvalid<fileName>(*this))
|
||||
{
|
||||
std::cerr
|
||||
<< "fileName::stripInvalid() called for invalid fileName "
|
||||
<< this->c_str() << std::endl;
|
||||
|
||||
if (debug > 1)
|
||||
{
|
||||
std::cerr
|
||||
<< " For debug level (= " << debug
|
||||
<< ") > 1 this is considered fatal" << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
|
||||
removeRepeated('/');
|
||||
removeTrailing('/');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::fileName::isAbsolute(const std::string& str)
|
||||
{
|
||||
return !str.empty() && str[0] == '/';
|
||||
@ -258,6 +256,28 @@ inline Foam::fileName& Foam::fileName::ext(const word& ending)
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(const fileName& str)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
if (this != &str)
|
||||
{
|
||||
assign(str);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(fileName&& str)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
if (this != &str)
|
||||
{
|
||||
assign(std::move(str));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(const word& str)
|
||||
{
|
||||
assign(str);
|
||||
|
||||
@ -72,9 +72,9 @@ Foam::Istream& Foam::operator>>(Istream& is, fileName& val)
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const fileName& fn)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const fileName& val)
|
||||
{
|
||||
os.write(fn);
|
||||
os.write(val);
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
@ -76,12 +76,13 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& val)
|
||||
if (t.isWord())
|
||||
{
|
||||
val = t.wordToken();
|
||||
val.uncompile(); // Non-regex
|
||||
}
|
||||
else if (t.isString())
|
||||
{
|
||||
// Assign from string, treat as regular expression
|
||||
val = t.stringToken();
|
||||
val.isPattern_ = true;
|
||||
val.compile(); // As regex
|
||||
|
||||
// Flag empty strings as an error
|
||||
if (val.empty())
|
||||
@ -108,9 +109,9 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& val)
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& kw)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& val)
|
||||
{
|
||||
os.write(kw);
|
||||
os.writeQuoted(val, val.isPattern());
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -48,13 +48,9 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class keyType;
|
||||
// Forward Declarations
|
||||
class Istream;
|
||||
class Ostream;
|
||||
Istream& operator>>(Istream& is, keyType& kw);
|
||||
Ostream& operator<<(Ostream& os, const keyType& kw);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class keyType Declaration
|
||||
@ -64,9 +60,9 @@ class keyType
|
||||
:
|
||||
public word
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Is the keyType a pattern (regular expression)
|
||||
//- Treat keyType as a pattern (regular expression)
|
||||
bool isPattern_;
|
||||
|
||||
|
||||
@ -78,13 +74,13 @@ class keyType
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
// Static Data Members
|
||||
|
||||
//- An empty keyType
|
||||
static const keyType null;
|
||||
|
||||
|
||||
// Public data types
|
||||
// Public Data Types
|
||||
|
||||
//- Enumeration for search/match modes as bitmask
|
||||
// eg, (keyType::REGEX | keyType::RECURSIVE)
|
||||
@ -142,15 +138,37 @@ public:
|
||||
// permit brace-brackets, which are valid for some regexs.
|
||||
inline static bool valid(char c);
|
||||
|
||||
|
||||
// Access
|
||||
|
||||
//- The keyType is treated as literal, not as pattern.
|
||||
inline bool isLiteral() const;
|
||||
|
||||
//- The keyType is treated as a pattern, not as literal string.
|
||||
inline bool isPattern() const;
|
||||
|
||||
//- Swap contents
|
||||
|
||||
// Infrastructure
|
||||
|
||||
//- Mark as regular expression
|
||||
inline bool compile();
|
||||
|
||||
//- Mark as literal, instead of a regular expression.
|
||||
// Optionally strip invalid word characters.
|
||||
inline void uncompile(bool doStrip = false);
|
||||
|
||||
|
||||
// Editing
|
||||
|
||||
//- Clear string and set as literal
|
||||
inline void clear();
|
||||
|
||||
//- Swap contents. Self-swapping is a no-op.
|
||||
inline void swap(keyType& s);
|
||||
|
||||
|
||||
// Matching/Searching
|
||||
|
||||
//- Smart match as regular expression or as a string.
|
||||
// Optionally force a literal match only
|
||||
bool match(const std::string& text, bool literal=false) const;
|
||||
@ -164,9 +182,11 @@ public:
|
||||
|
||||
|
||||
//- Copy assignment, retaining type (literal or regex)
|
||||
// Self-assignment is a no-op.
|
||||
inline void operator=(const keyType& s);
|
||||
|
||||
//- Move assignment, retaining type (literal or regex)
|
||||
// Self-assignment is a no-op.
|
||||
inline void operator=(keyType&& s);
|
||||
|
||||
//- Assign as word, treat as literal
|
||||
@ -177,13 +197,16 @@ public:
|
||||
|
||||
//- Assign as word, treat as literal
|
||||
inline void operator=(const char* s);
|
||||
};
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Istream& operator>>(Istream& is, keyType& kw);
|
||||
friend Ostream& operator<<(Ostream& os, const keyType& kw);
|
||||
};
|
||||
//- Read operator
|
||||
Istream& operator>>(Istream& is, keyType& val);
|
||||
|
||||
//- Write operator
|
||||
Ostream& operator<<(Ostream& os, const keyType& val);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -130,8 +130,40 @@ inline bool Foam::keyType::isPattern() const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::keyType::compile()
|
||||
{
|
||||
isPattern_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::keyType::uncompile(bool doStrip)
|
||||
{
|
||||
// Only strip when debug is active (potentially costly operation)
|
||||
if (isPattern_ && doStrip && word::debug)
|
||||
{
|
||||
string::stripInvalid<word>(*this);
|
||||
}
|
||||
|
||||
isPattern_ = false;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::keyType::clear()
|
||||
{
|
||||
word::clear();
|
||||
isPattern_ = false;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::keyType::swap(keyType& s)
|
||||
{
|
||||
// Self-swapping is a no-op
|
||||
if (this == &s)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
word::swap(static_cast<word&>(s));
|
||||
std::swap(isPattern_, s.isPattern_);
|
||||
}
|
||||
@ -147,6 +179,12 @@ inline bool Foam::keyType::operator()(const std::string& text) const
|
||||
|
||||
inline void Foam::keyType::operator=(const keyType& s)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
if (this == &s)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assign(s); // Bypasses char checking
|
||||
isPattern_ = s.isPattern_;
|
||||
}
|
||||
@ -154,6 +192,12 @@ inline void Foam::keyType::operator=(const keyType& s)
|
||||
|
||||
inline void Foam::keyType::operator=(keyType&& s)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
if (this == &s)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
clear();
|
||||
swap(s);
|
||||
}
|
||||
|
||||
@ -58,20 +58,16 @@ Description
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class Ostream;
|
||||
class CStringList;
|
||||
// Forward Declarations
|
||||
template<class String> class SubStrings;
|
||||
|
||||
Ostream& operator<<(Ostream& os, const CStringList& list);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class CStringList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class CStringList
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Number of strings
|
||||
int argc_;
|
||||
@ -127,7 +123,7 @@ public:
|
||||
inline explicit CStringList(const SubStrings<StringType>& input);
|
||||
|
||||
|
||||
//- Destructor
|
||||
//- Destructor. Invokes clear() to free memory.
|
||||
inline ~CStringList();
|
||||
|
||||
|
||||
@ -196,13 +192,13 @@ public:
|
||||
|
||||
//- Return element at the given index. No bounds checking.
|
||||
inline const char* operator[](int i) const;
|
||||
};
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Ostream& operator<<(Ostream& os, const CStringList& list);
|
||||
|
||||
};
|
||||
//- Output space-separated list
|
||||
Ostream& operator<<(Ostream& os, const CStringList& list);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -47,11 +47,6 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class hashedWordList;
|
||||
inline Istream& operator>>(Istream& is, hashedWordList& list);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class hashedWordList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -182,9 +177,6 @@ public:
|
||||
//- Move assignment from list of words. Rehashes the indices.
|
||||
inline void operator=(wordList&& list);
|
||||
|
||||
//- Read from an input stream. Rehashes the indices.
|
||||
inline friend Istream& operator>>(Istream& is, hashedWordList& list);
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
@ -198,6 +190,10 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//- Read from an input stream. Rehashes the indices.
|
||||
inline Istream& operator>>(Istream& is, hashedWordList& list);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -63,13 +63,8 @@ namespace Foam
|
||||
// Forward Declarations
|
||||
class word;
|
||||
class wordRe;
|
||||
class string;
|
||||
class Istream;
|
||||
class Ostream;
|
||||
Istream& operator>>(Istream& is, string& s);
|
||||
Ostream& operator<<(Ostream& os, const string& s);
|
||||
Ostream& operator<<(Ostream& os, const std::string& s);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class string Declaration
|
||||
@ -294,18 +289,30 @@ public:
|
||||
bool endsWith(const std::string& text) const;
|
||||
|
||||
|
||||
// Editing
|
||||
|
||||
//- Swap contents. Self-swapping is a no-op.
|
||||
inline void swap(std::string& str);
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Test for equality. Allows use as a predicate.
|
||||
// \return True when strings match literally.
|
||||
inline bool operator()(const std::string& text) const;
|
||||
};
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Istream& operator>>(Istream& is, string& s);
|
||||
friend Ostream& operator<<(Ostream& os, const string& s);
|
||||
};
|
||||
//- Read operator
|
||||
Istream& operator>>(Istream& is, string& val);
|
||||
|
||||
//- Write operator
|
||||
Ostream& operator<<(Ostream& os, const string& val);
|
||||
|
||||
//- Write operator
|
||||
Ostream& operator<<(Ostream& os, const std::string& val);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
@ -262,6 +262,16 @@ inline bool Foam::string::match(const std::string& text) const
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::string::swap(std::string& str)
|
||||
{
|
||||
// Self-swapping is a no-op
|
||||
if (this != &str)
|
||||
{
|
||||
std::string::swap(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::string::operator()(const std::string& text) const
|
||||
|
||||
@ -70,17 +70,17 @@ Foam::Istream& Foam::operator>>(Istream& is, string& val)
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const string& s)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const string& val)
|
||||
{
|
||||
os.write(s);
|
||||
os.write(val);
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& s)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& val)
|
||||
{
|
||||
os.write(string(s));
|
||||
os.write(string(val));
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -63,18 +63,14 @@ class word
|
||||
:
|
||||
public string
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Strip invalid characters from this word
|
||||
// Trips an abort on invalid characters for debug 2 or greater
|
||||
inline void stripInvalid();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
// Static Data Members
|
||||
|
||||
//- The typeName
|
||||
static const char* const typeName;
|
||||
|
||||
//- Debugging
|
||||
static int debug;
|
||||
|
||||
//- An empty word
|
||||
@ -136,7 +132,6 @@ public:
|
||||
const PrimitiveType& val
|
||||
);
|
||||
|
||||
|
||||
//- Is this character valid for a word?
|
||||
inline static bool valid(char c);
|
||||
|
||||
@ -155,6 +150,10 @@ public:
|
||||
const bool prefix=false
|
||||
);
|
||||
|
||||
//- Strip invalid characters from this word
|
||||
// Trips an abort on invalid characters for debug 2 or greater
|
||||
inline void stripInvalid();
|
||||
|
||||
|
||||
// File-like Functions
|
||||
|
||||
@ -182,15 +181,17 @@ public:
|
||||
inline bool removeExt();
|
||||
|
||||
|
||||
// Member operators
|
||||
// Member Operators
|
||||
|
||||
// Assignment
|
||||
|
||||
//- Copy assignment, no character validation required
|
||||
word& operator=(const word&) = default;
|
||||
//- Copy assignment, no character validation required.
|
||||
// Self-assignment is a no-op
|
||||
inline word& operator=(const word& s);
|
||||
|
||||
//- Move assignment, no character validation required
|
||||
word& operator=(word&& w) = default;
|
||||
// Self-assignment is a no-op
|
||||
inline word& operator=(word&& s);
|
||||
|
||||
//- Copy assignment from Foam::string, stripping invalid characters
|
||||
inline word& operator=(const string& s);
|
||||
@ -206,15 +207,18 @@ public:
|
||||
|
||||
//- Copy, stripping invalid characters
|
||||
inline word& operator=(const char* s);
|
||||
|
||||
|
||||
// IOstream operators
|
||||
|
||||
friend Istream& operator>>(Istream& is, word& w);
|
||||
friend Ostream& operator<<(Ostream& os, const word& w);
|
||||
};
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
//- Read operator
|
||||
Istream& operator>>(Istream& is, word& val);
|
||||
|
||||
//- Write operator
|
||||
Ostream& operator<<(Ostream& os, const word& val);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
|
||||
|
||||
//- Join words as camelCase, capitalizing the first letter of b.
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
@ -56,28 +56,6 @@ inline Foam::word Foam::word::printf
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::word::stripInvalid()
|
||||
{
|
||||
// Skip stripping unless debug is active (to avoid costly operations)
|
||||
if (debug && string::stripInvalid<word>(*this))
|
||||
{
|
||||
std::cerr
|
||||
<< "word::stripInvalid() called for word "
|
||||
<< this->c_str() << std::endl;
|
||||
|
||||
if (debug > 1)
|
||||
{
|
||||
std::cerr
|
||||
<< " For debug level (= " << debug
|
||||
<< ") > 1 this is considered fatal" << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::word::word(const string& s, bool doStrip)
|
||||
@ -163,6 +141,26 @@ inline bool Foam::word::valid(char c)
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::word::stripInvalid()
|
||||
{
|
||||
// Only strip when debug is active (potentially costly operation)
|
||||
if (debug && string::stripInvalid<word>(*this))
|
||||
{
|
||||
std::cerr
|
||||
<< "word::stripInvalid() called for word "
|
||||
<< this->c_str() << std::endl;
|
||||
|
||||
if (debug > 1)
|
||||
{
|
||||
std::cerr
|
||||
<< " For debug level (= " << debug
|
||||
<< ") > 1 this is considered fatal" << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::word::hasExt() const
|
||||
{
|
||||
return string::hasExt();
|
||||
@ -177,6 +175,28 @@ inline bool Foam::word::removeExt()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::word& Foam::word::operator=(const word& s)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
if (this != &s)
|
||||
{
|
||||
assign(s);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word& Foam::word::operator=(word&& s)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
if (this != &s)
|
||||
{
|
||||
assign(std::move(s));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word& Foam::word::operator=(const string& s)
|
||||
{
|
||||
assign(s);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
@ -87,9 +87,9 @@ Foam::Istream& Foam::operator>>(Istream& is, word& val)
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const word& w)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const word& val)
|
||||
{
|
||||
os.write(w);
|
||||
os.write(val);
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -47,6 +47,21 @@ Foam::wordRe::wordRe(Istream& is)
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::wordRe::info(Ostream& os) const
|
||||
{
|
||||
if (isPattern())
|
||||
{
|
||||
os << "wordRe(regex) " << *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "wordRe(plain) \"" << *this << '"';
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::operator>>(Istream& is, wordRe& val)
|
||||
{
|
||||
token t(is);
|
||||
@ -94,27 +109,12 @@ Foam::Istream& Foam::operator>>(Istream& is, wordRe& val)
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const wordRe& w)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const wordRe& val)
|
||||
{
|
||||
os.writeQuoted(w, w.isPattern());
|
||||
os.writeQuoted(val, val.isPattern());
|
||||
os.check(FUNCTION_NAME);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::wordRe::info(Ostream& os) const
|
||||
{
|
||||
if (isPattern())
|
||||
{
|
||||
os << "wordRe(regex) " << *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "wordRe(plain) \"" << *this << '"';
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -61,15 +61,10 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class wordRe;
|
||||
// Forward Declarations
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
Istream& operator>>(Istream& is, wordRe& w);
|
||||
Ostream& operator<<(Ostream& os, const wordRe& w);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class wordRe Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -78,21 +73,21 @@ class wordRe
|
||||
:
|
||||
public word
|
||||
{
|
||||
// Private member data
|
||||
// Private Member Data
|
||||
|
||||
//- The regular expression
|
||||
mutable regExp re_;
|
||||
regExp re_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
// Static Data Members
|
||||
|
||||
//- An empty wordRe
|
||||
static const wordRe null;
|
||||
|
||||
|
||||
// Public data types
|
||||
// Public Data Types
|
||||
|
||||
//- Enumeration with compile options
|
||||
// Note that 'REGEX' is implicit if 'ICASE' is specified alone.
|
||||
@ -109,18 +104,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//- Is this a meta character?
|
||||
inline static bool meta(const 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);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
@ -169,9 +152,21 @@ 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
|
||||
|
||||
//- The wordRe is treated as literal, not as pattern.
|
||||
//- The wordRe is treated as literal string, not as pattern.
|
||||
inline bool isLiteral() const;
|
||||
|
||||
//- The wordRe is treated as a pattern, not as literal string.
|
||||
@ -181,14 +176,14 @@ public:
|
||||
// Infrastructure
|
||||
|
||||
//- Compile the regular expression
|
||||
inline bool compile() const;
|
||||
inline bool compile();
|
||||
|
||||
//- Possibly compile the regular expression, with greater control
|
||||
inline bool compile(const compOption opt) const;
|
||||
inline bool compile(const compOption opt);
|
||||
|
||||
//- Make wordRe a literal again, instead of a regular expression.
|
||||
// Optionally strip invalid word characters.
|
||||
inline void uncompile(bool doStrip = false) const;
|
||||
inline void uncompile(bool doStrip = false);
|
||||
|
||||
|
||||
// Editing
|
||||
@ -202,7 +197,7 @@ public:
|
||||
//- Clear string and regular expression
|
||||
inline void clear();
|
||||
|
||||
//- Swap contents
|
||||
//- Swap contents. Self-swapping is a no-op
|
||||
inline void swap(wordRe& str);
|
||||
|
||||
|
||||
@ -230,6 +225,7 @@ public:
|
||||
|
||||
|
||||
//- Copy assignment, retaining type (literal or regex)
|
||||
// Self-assignment is a no-op.
|
||||
inline void operator=(const wordRe& str);
|
||||
|
||||
//- Copy word, never a regular expression
|
||||
@ -252,14 +248,18 @@ public:
|
||||
inline void operator=(const char* str);
|
||||
|
||||
//- Move assignment.
|
||||
// Self-assignment is a no-op.
|
||||
inline void operator=(wordRe&& str);
|
||||
};
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Istream& operator>>(Istream& is, wordRe& w);
|
||||
friend Ostream& operator<<(Ostream& os, const wordRe& w);
|
||||
};
|
||||
//- Read operator
|
||||
Istream& operator>>(Istream& is, wordRe& val);
|
||||
|
||||
//- Write operator
|
||||
Ostream& operator<<(Ostream& os, const wordRe& val);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -27,7 +27,7 @@ License
|
||||
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::wordRe::meta(const char c)
|
||||
inline bool Foam::wordRe::meta(char c)
|
||||
{
|
||||
return regExp::meta(c);
|
||||
}
|
||||
@ -171,7 +171,7 @@ inline bool Foam::wordRe::isPattern() const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::wordRe::compile(const compOption opt) const
|
||||
inline bool Foam::wordRe::compile(const compOption opt)
|
||||
{
|
||||
if (opt)
|
||||
{
|
||||
@ -202,24 +202,18 @@ inline bool Foam::wordRe::compile(const compOption opt) const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::wordRe::compile() const
|
||||
inline bool Foam::wordRe::compile()
|
||||
{
|
||||
return re_.set(*this);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::wordRe::uncompile(bool doStrip) const
|
||||
inline void Foam::wordRe::uncompile(bool doStrip)
|
||||
{
|
||||
if (re_.clear() && doStrip)
|
||||
// Only strip when debug is active (potentially costly operation)
|
||||
if (re_.clear() && doStrip && word::debug)
|
||||
{
|
||||
// Skip stripping unless debug is active to avoid costly operations
|
||||
if (word::debug)
|
||||
{
|
||||
string::stripInvalid<word>
|
||||
(
|
||||
const_cast<word&>(static_cast<const word&>(*this))
|
||||
);
|
||||
}
|
||||
string::stripInvalid<word>(*this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,6 +258,12 @@ inline void Foam::wordRe::set(const char* str, const compOption opt)
|
||||
|
||||
inline void Foam::wordRe::swap(wordRe& str)
|
||||
{
|
||||
// Self-swapping is a no-op
|
||||
if (this == &str)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
word::swap(static_cast<word&>(str));
|
||||
re_.swap(str.re_);
|
||||
}
|
||||
@ -279,6 +279,12 @@ inline bool Foam::wordRe::operator()(const std::string& text) const
|
||||
|
||||
inline void Foam::wordRe::operator=(const wordRe& str)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
if (this == &str)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assign(str);
|
||||
if (str.isPattern())
|
||||
{
|
||||
@ -335,6 +341,12 @@ inline void Foam::wordRe::operator=(const char* str)
|
||||
|
||||
inline void Foam::wordRe::operator=(wordRe&& str)
|
||||
{
|
||||
// Self-assignment is a no-op
|
||||
if (this == &str)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
clear();
|
||||
swap(str);
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -56,11 +56,6 @@ class FileName
|
||||
:
|
||||
public fileName
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Strip invalid characters
|
||||
inline void stripInvalid();
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
@ -80,6 +75,9 @@ public:
|
||||
//- Is this character valid for an ensight file-name
|
||||
inline static bool valid(char c);
|
||||
|
||||
//- Strip invalid characters
|
||||
inline void stripInvalid();
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -53,6 +53,17 @@ inline Foam::ensight::FileName::FileName(const std::string& s)
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::ensight::FileName::valid(char c)
|
||||
{
|
||||
return
|
||||
(
|
||||
fileName::valid(c) // includes space, quotes
|
||||
&& c != '*' // wild-card
|
||||
&& c != '%' // structured block continuation
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::ensight::FileName::stripInvalid()
|
||||
{
|
||||
string::stripInvalid<FileName>(*this);
|
||||
@ -69,15 +80,4 @@ inline void Foam::ensight::FileName::stripInvalid()
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::ensight::FileName::valid(char c)
|
||||
{
|
||||
return
|
||||
(
|
||||
fileName::valid(c) // includes space, quotes
|
||||
&& c != '*' // wild-card
|
||||
&& c != '%' // structured block continuation
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -58,11 +58,6 @@ class VarName
|
||||
:
|
||||
public word
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Strip invalid characters
|
||||
inline void stripInvalid();
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
@ -82,6 +77,9 @@ public:
|
||||
//- Is this character valid for an ensight var-name
|
||||
inline static bool valid(char c);
|
||||
|
||||
//- Strip invalid characters
|
||||
inline void stripInvalid();
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -51,29 +51,8 @@ inline Foam::ensight::VarName::VarName(const std::string& s)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::ensight::VarName::stripInvalid()
|
||||
{
|
||||
string::stripInvalid<VarName>(*this);
|
||||
|
||||
if (empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "ensight::VarName empty after stripping" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// prefix with '_' to avoid starting with leading digits
|
||||
std::string::iterator iter = begin();
|
||||
if (isdigit(*iter))
|
||||
{
|
||||
insert(iter, '_');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::ensight::VarName::valid(char c)
|
||||
{
|
||||
return
|
||||
@ -97,4 +76,24 @@ inline bool Foam::ensight::VarName::valid(char c)
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::ensight::VarName::stripInvalid()
|
||||
{
|
||||
string::stripInvalid<VarName>(*this);
|
||||
|
||||
if (empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "ensight::VarName empty after stripping" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Prefix with '_' to avoid starting with leading digits
|
||||
std::string::iterator iter = begin();
|
||||
if (isdigit(*iter))
|
||||
{
|
||||
insert(iter, '_');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user