mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: fileName hasPath(), removePath() methods
- improved move constructors/assignments for fileName, string, etc
This commit is contained in:
@ -621,12 +621,18 @@ int main(int argc, char *argv[])
|
||||
<< "pathName.name() = >" << pathName.name() << "<\n"
|
||||
<< "pathName.path() = " << pathName.path() << nl
|
||||
<< "pathName.ext() = >" << pathName.ext() << "<\n"
|
||||
<< "pathName.name(true) = >" << pathName.name(true) << "<\n";
|
||||
<< "pathName.nameLessExt= >" << pathName.nameLessExt() << "<\n";
|
||||
|
||||
Info<< "pathName.components() = " << pathName.components() << nl
|
||||
<< "pathName.component(2) = " << pathName.component(2) << nl
|
||||
<< endl;
|
||||
|
||||
Info<< "hasPath = " << Switch(pathName.hasPath()) << nl;
|
||||
pathName.removePath();
|
||||
Info<< "removed path = " << pathName << nl;
|
||||
|
||||
Info<< nl << nl;
|
||||
|
||||
// try with different combination
|
||||
// The final one should emit warnings
|
||||
for (label start = 0; start <= wrdList.size(); ++start)
|
||||
|
||||
@ -36,6 +36,7 @@ Description
|
||||
#include "uint.H"
|
||||
#include "scalar.H"
|
||||
#include "Switch.H"
|
||||
#include "fileName.H"
|
||||
#include "stringList.H"
|
||||
|
||||
using namespace Foam;
|
||||
@ -64,6 +65,34 @@ int main(int argc, char *argv[])
|
||||
subDict.add("value2", "test2");
|
||||
dict.add("FOAM_RUN", subDict);
|
||||
|
||||
if (false)
|
||||
{
|
||||
typedef std::string inputType;
|
||||
typedef string outputType;
|
||||
|
||||
inputType in1("move-construct-from");
|
||||
|
||||
Info<<"move construct from " << in1.length() << nl;
|
||||
|
||||
outputType out1(std::move(in1));
|
||||
|
||||
Info<<"after move construct "
|
||||
<< out1.size() << ", " << in1.size() << nl;
|
||||
|
||||
in1 = "move-assign-from";
|
||||
out1 = "some-text-rubbish";
|
||||
out1.resize(10);
|
||||
|
||||
Info<<"move assign from " << in1.length() << nl;
|
||||
|
||||
out1 = std::move(in1);
|
||||
|
||||
Info<<"after move assign "
|
||||
<< out1.size() << ", " << in1.size() << nl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// basic expansions
|
||||
{
|
||||
|
||||
@ -24,10 +24,10 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fileName.H"
|
||||
#include "wordRe.H"
|
||||
#include "wordList.H"
|
||||
#include "DynamicList.H"
|
||||
#include "OSspecific.H"
|
||||
#include "wordRe.H"
|
||||
#include "fileOperation.H"
|
||||
#include "stringOps.H"
|
||||
|
||||
@ -142,7 +142,7 @@ bool Foam::fileName::isBackup(const std::string& str)
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string ending = str.substr(dot+1, npos);
|
||||
const std::string ending = str.substr(dot+1);
|
||||
|
||||
if (ending.empty())
|
||||
{
|
||||
@ -159,44 +159,40 @@ bool Foam::fileName::isBackup(const std::string& str)
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileName::fileName(const UList<word>& lst)
|
||||
Foam::fileName::fileName(const UList<word>& list)
|
||||
{
|
||||
// Estimate overall size
|
||||
size_type sz = lst.size(); // Approx number of '/' needed
|
||||
for (const word& item : lst)
|
||||
size_type len = 0;
|
||||
for (const word& item : list)
|
||||
{
|
||||
sz += item.size();
|
||||
len += 1 + item.length(); // Include space for '/' needed
|
||||
}
|
||||
reserve(sz);
|
||||
reserve(len);
|
||||
|
||||
sz = 0;
|
||||
for (const word& item : lst)
|
||||
for (const word& item : list)
|
||||
{
|
||||
if (item.size())
|
||||
if (item.length())
|
||||
{
|
||||
if (sz++) operator+=('/');
|
||||
if (length()) operator+=('/');
|
||||
operator+=(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName::fileName(std::initializer_list<word> lst)
|
||||
Foam::fileName::fileName(std::initializer_list<word> list)
|
||||
{
|
||||
// Estimate overall size
|
||||
size_type sz = lst.size(); // Approx number of '/' needed
|
||||
for (const word& item : lst)
|
||||
size_type len = 0;
|
||||
for (const word& item : list)
|
||||
{
|
||||
sz += item.size();
|
||||
len += 1 + item.length(); // Include space for '/' needed
|
||||
}
|
||||
reserve(sz);
|
||||
reserve(len);
|
||||
|
||||
sz = 0;
|
||||
for (const word& item : lst)
|
||||
for (const word& item : list)
|
||||
{
|
||||
if (item.size())
|
||||
if (item.length())
|
||||
{
|
||||
if (sz++) operator+=('/');
|
||||
if (length()) operator+=('/');
|
||||
operator+=(item);
|
||||
}
|
||||
}
|
||||
@ -238,11 +234,11 @@ bool Foam::fileName::clean(std::string& str)
|
||||
}
|
||||
|
||||
// Number of output characters
|
||||
std::string::size_type nChar = top+1;
|
||||
auto nChar = top+1;
|
||||
|
||||
const string::size_type maxLen = str.size();
|
||||
const auto maxLen = str.size();
|
||||
|
||||
for (string::size_type src = nChar; src < maxLen; /*nil*/)
|
||||
for (auto src = nChar; src < maxLen; /*nil*/)
|
||||
{
|
||||
const char c = str[src++];
|
||||
|
||||
@ -329,29 +325,10 @@ Foam::fileName Foam::fileName::clean() const
|
||||
}
|
||||
|
||||
|
||||
std::string Foam::fileName::name(const std::string& str)
|
||||
{
|
||||
const auto beg = str.rfind('/');
|
||||
|
||||
if (beg == npos)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return str.substr(beg+1);
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::fileName::name() const
|
||||
{
|
||||
return fileName::name(*this);
|
||||
}
|
||||
|
||||
|
||||
std::string Foam::fileName::nameLessExt(const std::string& str)
|
||||
{
|
||||
size_type beg = str.rfind('/');
|
||||
size_type dot = str.rfind('.');
|
||||
auto beg = str.rfind('/');
|
||||
auto dot = str.rfind('.');
|
||||
|
||||
if (beg == npos)
|
||||
{
|
||||
@ -376,35 +353,6 @@ std::string Foam::fileName::nameLessExt(const std::string& str)
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::fileName::nameLessExt() const
|
||||
{
|
||||
return nameLessExt(*this);
|
||||
}
|
||||
|
||||
|
||||
std::string Foam::fileName::path(const std::string& str)
|
||||
{
|
||||
const auto i = str.rfind('/');
|
||||
|
||||
if (i == npos)
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
else if (i)
|
||||
{
|
||||
return str.substr(0, i);
|
||||
}
|
||||
|
||||
return "/";
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::fileName::path() const
|
||||
{
|
||||
return path(*this);
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::fileName::relative(const fileName& parent) const
|
||||
{
|
||||
const auto top = parent.size();
|
||||
@ -424,38 +372,6 @@ Foam::fileName Foam::fileName::relative(const fileName& parent) const
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::fileName::lessExt() const
|
||||
{
|
||||
const auto i = find_ext();
|
||||
|
||||
if (i == npos)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
return substr(0, i);
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::fileName::ext() const
|
||||
{
|
||||
return string::ext();
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName& Foam::fileName::ext(const word& ending)
|
||||
{
|
||||
string::ext(ending);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileName::hasExt(const word& ending) const
|
||||
{
|
||||
return string::hasExt(ending);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileName::hasExt(const wordRe& ending) const
|
||||
{
|
||||
return string::hasExt(ending);
|
||||
@ -500,39 +416,6 @@ Foam::word Foam::fileName::component
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileName::operator=(const fileName& str)
|
||||
{
|
||||
assign(str);
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileName::operator=(const word& str)
|
||||
{
|
||||
assign(str);
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileName::operator=(const string& str)
|
||||
{
|
||||
assign(str);
|
||||
stripInvalid();
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileName::operator=(const std::string& str)
|
||||
{
|
||||
assign(str);
|
||||
stripInvalid();
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileName::operator=(const char* str)
|
||||
{
|
||||
assign(str);
|
||||
stripInvalid();
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName& Foam::fileName::operator/=(const string& other)
|
||||
{
|
||||
fileName& s = *this;
|
||||
|
||||
@ -102,28 +102,40 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline fileName();
|
||||
fileName() = default;
|
||||
|
||||
//- Construct as copy
|
||||
inline fileName(const fileName& fn);
|
||||
//- Copy construct
|
||||
fileName(const fileName&) = default;
|
||||
|
||||
//- Construct as copy of word
|
||||
inline fileName(const word& w);
|
||||
//- Move construct
|
||||
fileName(fileName&&) = default;
|
||||
|
||||
//- Construct as copy of string
|
||||
inline fileName(const string& s, const bool doStripInvalid=true);
|
||||
//- Copy construct from word
|
||||
inline fileName(const word& s);
|
||||
|
||||
//- Construct as copy of std::string
|
||||
inline fileName(const std::string& s, const bool doStripInvalid=true);
|
||||
//- Move construct from word
|
||||
inline fileName(word&& s);
|
||||
|
||||
//- Construct as copy of character array
|
||||
inline fileName(const char* s, const bool doStripInvalid=true);
|
||||
//- Copy construct from string
|
||||
inline fileName(const string& s, bool doStrip=true);
|
||||
|
||||
//- Move construct from string
|
||||
inline fileName(string&& s, bool doStrip=true);
|
||||
|
||||
//- Copy construct from std::string
|
||||
inline fileName(const std::string& s, bool doStrip=true);
|
||||
|
||||
//- Move construct from std::string
|
||||
inline fileName(std::string&& s, bool doStrip=true);
|
||||
|
||||
//- Copy construct from character array
|
||||
inline fileName(const char* s, bool doStrip=true);
|
||||
|
||||
//- Construct by concatenating elements of wordList separated by '/'
|
||||
explicit fileName(const UList<word>& lst);
|
||||
explicit fileName(const UList<word>& list);
|
||||
|
||||
//- Construct by concatenating words separated by '/'
|
||||
explicit fileName(std::initializer_list<word> lst);
|
||||
explicit fileName(std::initializer_list<word> list);
|
||||
|
||||
|
||||
//- Construct from Istream
|
||||
@ -226,17 +238,17 @@ public:
|
||||
// "/foo/bar" "bar" "bar"
|
||||
// "/foo/bar/" "" "bar"
|
||||
// \endverbatim
|
||||
static std::string name(const std::string& str);
|
||||
inline static std::string name(const std::string& str);
|
||||
|
||||
//- Return basename (part beyond last /), including its extension
|
||||
word name() const;
|
||||
inline word name() const;
|
||||
|
||||
//- Return basename, without extension
|
||||
// The result normally corresponds to a Foam::word
|
||||
static std::string nameLessExt(const std::string& str);
|
||||
|
||||
//- Return basename, without extension
|
||||
word nameLessExt() const;
|
||||
inline word nameLessExt() const;
|
||||
|
||||
//- Return basename, optionally without extension
|
||||
// \deprecated in favour of name() or nameLessExt() which describe
|
||||
@ -260,30 +272,36 @@ public:
|
||||
// "/foo/bar" "/foo" "/foo"
|
||||
// "/foo/bar/" "/foo/bar/" "/foo"
|
||||
// \endverbatim
|
||||
static std::string path(const std::string& str);
|
||||
inline static std::string path(const std::string& str);
|
||||
|
||||
//- Return directory path name (part before last /)
|
||||
fileName path() const;
|
||||
inline fileName path() const;
|
||||
|
||||
//- Return true if it contains a '/' character
|
||||
inline bool hasPath() const;
|
||||
|
||||
//- Remove leading path, returning true if string changed.
|
||||
inline bool removePath();
|
||||
|
||||
//- Return name after stripping off the parent directory
|
||||
fileName relative(const fileName& parent) const;
|
||||
|
||||
//- Return file name without extension (part before last .)
|
||||
fileName lessExt() const;
|
||||
inline fileName lessExt() const;
|
||||
|
||||
//- Return file name extension (part after last .)
|
||||
word ext() const;
|
||||
inline word ext() const;
|
||||
|
||||
//- Append a '.' and the ending, and return the object.
|
||||
// The '.' and ending will not be added when the ending is empty,
|
||||
// or when the file name is empty or ended with a '/'.
|
||||
fileName& ext(const word& ending);
|
||||
inline fileName& ext(const word& ending);
|
||||
|
||||
//- Return true if it has an extension or simply ends with a '.'
|
||||
inline bool hasExt() const;
|
||||
|
||||
//- Return true if the extension is the same as the given ending.
|
||||
bool hasExt(const word& ending) const;
|
||||
inline bool hasExt(const word& ending) const;
|
||||
|
||||
//- Return true if the extension matches the given ending.
|
||||
bool hasExt(const wordRe& ending) const;
|
||||
@ -318,20 +336,32 @@ public:
|
||||
|
||||
// Assignment
|
||||
|
||||
//- Copy, no character validation required
|
||||
void operator=(const fileName& str);
|
||||
//- Copy assignment, no character validation required
|
||||
fileName& operator=(const fileName&) = default;
|
||||
|
||||
//- Copy, no character validation required
|
||||
void operator=(const word& str);
|
||||
//- Move assignment, no character validation required
|
||||
fileName& operator=(fileName&&) = default;
|
||||
|
||||
//- Copy assignment, no character validation required
|
||||
inline fileName& operator=(const word& str);
|
||||
|
||||
//- Move assignment, no character validation required
|
||||
inline fileName& operator=(word&& str);
|
||||
|
||||
//- Copy assignment, stripping invalid characters
|
||||
inline fileName& operator=(const string& str);
|
||||
|
||||
//- Move assignment, stripping invalid characters
|
||||
inline fileName& operator=(string&& str);
|
||||
|
||||
//- Copy assignment, stripping invalid characters
|
||||
inline fileName& operator=(const std::string& str);
|
||||
|
||||
//- Move assignment, stripping invalid characters
|
||||
inline fileName& operator=(std::string&& str);
|
||||
|
||||
//- Copy, stripping invalid characters
|
||||
void operator=(const string& str);
|
||||
|
||||
//- Copy, stripping invalid characters
|
||||
void operator=(const std::string& str);
|
||||
|
||||
//- Copy, stripping invalid characters
|
||||
void operator=(const char* str);
|
||||
inline fileName& operator=(const char* str);
|
||||
|
||||
|
||||
// Other operators
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -52,51 +52,67 @@ inline void Foam::fileName::stripInvalid()
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::fileName::fileName()
|
||||
inline Foam::fileName::fileName(const word& s)
|
||||
:
|
||||
string()
|
||||
string(s)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::fileName::fileName(const fileName& fn)
|
||||
inline Foam::fileName::fileName(word&& s)
|
||||
:
|
||||
string(fn)
|
||||
string(std::move(s))
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::fileName::fileName(const word& w)
|
||||
:
|
||||
string(w)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::fileName::fileName(const string& s, const bool doStripInvalid)
|
||||
inline Foam::fileName::fileName(const string& s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
{
|
||||
if (doStripInvalid)
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName::fileName(const std::string& s, const bool doStripInvalid)
|
||||
inline Foam::fileName::fileName(string&& s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
string(std::move(s))
|
||||
{
|
||||
if (doStripInvalid)
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName::fileName(const char* s, const bool doStripInvalid)
|
||||
inline Foam::fileName::fileName(const std::string& s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
{
|
||||
if (doStripInvalid)
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName::fileName(std::string&& s, bool doStrip)
|
||||
:
|
||||
string(std::move(s))
|
||||
{
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName::fileName(const char* s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
{
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
@ -134,16 +150,164 @@ inline bool Foam::fileName::isBackup() const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::fileName::hasPath() const
|
||||
{
|
||||
return string::hasPath();
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::fileName::hasExt() const
|
||||
{
|
||||
return string::hasExt();
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::fileName::hasExt(const word& ending) const
|
||||
{
|
||||
return string::hasExt(ending);
|
||||
}
|
||||
|
||||
|
||||
inline std::string Foam::fileName::path(const std::string& str)
|
||||
{
|
||||
const auto i = str.rfind('/');
|
||||
|
||||
if (i == npos)
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
else if (i)
|
||||
{
|
||||
return str.substr(0, i);
|
||||
}
|
||||
|
||||
return "/";
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName Foam::fileName::path() const
|
||||
{
|
||||
return path(*this);
|
||||
}
|
||||
|
||||
|
||||
inline std::string Foam::fileName::name(const std::string& str)
|
||||
{
|
||||
const auto i = str.rfind('/');
|
||||
|
||||
if (npos == i)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return str.substr(i+1);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word Foam::fileName::name() const
|
||||
{
|
||||
return fileName::name(*this);
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::fileName::ext() const
|
||||
{
|
||||
return string::ext();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word Foam::fileName::nameLessExt() const
|
||||
{
|
||||
return nameLessExt(*this);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName Foam::fileName::lessExt() const
|
||||
{
|
||||
const auto i = find_ext();
|
||||
|
||||
if (i == npos)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
return substr(0, i);
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::fileName::removePath()
|
||||
{
|
||||
return string::removePath();
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::fileName::removeExt()
|
||||
{
|
||||
return string::removeExt();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::ext(const word& ending)
|
||||
{
|
||||
string::ext(ending);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(const word& str)
|
||||
{
|
||||
assign(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(word&& str)
|
||||
{
|
||||
assign(std::move(str));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(const string& str)
|
||||
{
|
||||
assign(str);
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(string&& str)
|
||||
{
|
||||
assign(std::move(str));
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(const std::string& str)
|
||||
{
|
||||
assign(str);
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(std::string&& str)
|
||||
{
|
||||
assign(std::move(str));
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::fileName::operator=(const char* str)
|
||||
{
|
||||
assign(str);
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -75,6 +75,7 @@ class keyType
|
||||
//- No assignment where we cannot determine string/word type
|
||||
void operator=(const std::string&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
@ -91,14 +92,13 @@ public:
|
||||
//- Copy construct, retaining type (literal or regex)
|
||||
inline keyType(const keyType& s);
|
||||
|
||||
//- Copy construct from word. Not treated as a regular expression
|
||||
//- Copy construct from word, treat as literal.
|
||||
inline keyType(const word& s);
|
||||
|
||||
//- Copy construct from string. Treat as regular expression.
|
||||
//- Copy construct from string, treat as regular expression.
|
||||
inline keyType(const string& s);
|
||||
|
||||
//- Construct as copy of character array.
|
||||
// Not treated as a regular expression
|
||||
//- Construct as copy of character array, treat as literal.
|
||||
inline keyType(const char* s);
|
||||
|
||||
//- Copy construct from std::string with specified treatment
|
||||
@ -149,18 +149,18 @@ public:
|
||||
//- Copy assignment, retaining type (literal or regex)
|
||||
inline void operator=(const keyType& s);
|
||||
|
||||
//- Assign as word, not treated as a regular expression.
|
||||
inline void operator=(const word& s);
|
||||
|
||||
//- Assign from Foam::string as regular expression
|
||||
inline void operator=(const string& s);
|
||||
|
||||
//- Assign as word, not treated as a regular expression.
|
||||
inline void operator=(const char* s);
|
||||
|
||||
//- Move assignment, retaining type (literal or regex)
|
||||
inline void operator=(keyType&& s);
|
||||
|
||||
//- Assign as word, treat as literal
|
||||
inline void operator=(const word& s);
|
||||
|
||||
//- Assign from Foam::string, treat as regular expression
|
||||
inline void operator=(const string& s);
|
||||
|
||||
//- Assign as word, treat as literal
|
||||
inline void operator=(const char* s);
|
||||
|
||||
|
||||
// IOstream operators
|
||||
|
||||
|
||||
@ -145,6 +145,13 @@ inline void Foam::keyType::operator=(const keyType& s)
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::keyType::operator=(keyType&& s)
|
||||
{
|
||||
clear();
|
||||
swap(s);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::keyType::operator=(const word& s)
|
||||
{
|
||||
assign(s); // Bypasses char checking
|
||||
@ -166,11 +173,4 @@ inline void Foam::keyType::operator=(const char* s)
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::keyType::operator=(keyType&& s)
|
||||
{
|
||||
clear();
|
||||
swap(s);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -58,14 +58,12 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
// Forward Declarations
|
||||
class word;
|
||||
class wordRe;
|
||||
class string;
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
class string;
|
||||
Istream& operator>>(Istream& is, string& s);
|
||||
Ostream& operator<<(Ostream& os, const string& s);
|
||||
Ostream& operator<<(Ostream& os, const std::string& s);
|
||||
@ -119,6 +117,9 @@ protected:
|
||||
// \return True if append occurred.
|
||||
bool ext(const word& ending);
|
||||
|
||||
//- Return true if it contains a '/' character
|
||||
inline bool hasPath() const;
|
||||
|
||||
//- Return true if it has an extension or simply ends with a '.'
|
||||
inline bool hasExt() const;
|
||||
|
||||
@ -131,6 +132,9 @@ protected:
|
||||
//- Remove extension, returning true if string changed.
|
||||
inline bool removeExt();
|
||||
|
||||
//- Remove leading path, returning true if string changed.
|
||||
inline bool removePath();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -157,11 +161,14 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline string();
|
||||
string() = default;
|
||||
|
||||
//- Construct from std::string
|
||||
//- Copy construct from std::string
|
||||
inline string(const std::string& str);
|
||||
|
||||
//- Move construct from std::string
|
||||
inline string(std::string&& str);
|
||||
|
||||
//- Construct as copy of character array
|
||||
inline string(const char* str);
|
||||
|
||||
@ -174,9 +181,6 @@ public:
|
||||
//- Construct fill copies of a single character
|
||||
inline string(const size_type len, const char c);
|
||||
|
||||
//- Move construct from std::string
|
||||
inline string(std::string&& str);
|
||||
|
||||
//- Construct from Istream
|
||||
string(Istream& is);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -44,9 +44,29 @@ inline std::string::size_type Foam::string::find_ext() const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::string::hasPath() const
|
||||
{
|
||||
return (npos != find('/'));
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::string::hasExt() const
|
||||
{
|
||||
return (find_ext() != npos);
|
||||
return (npos != find_ext());
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::string::removePath()
|
||||
{
|
||||
const auto i = rfind('/');
|
||||
|
||||
if (npos == i)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this->erase(0, i+1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +74,7 @@ inline bool Foam::string::removeExt()
|
||||
{
|
||||
const auto i = find_ext();
|
||||
|
||||
if (i == npos)
|
||||
if (npos == i)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -64,20 +84,21 @@ inline bool Foam::string::removeExt()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::string::string()
|
||||
:
|
||||
std::string()
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::string::string(const std::string& str)
|
||||
:
|
||||
std::string(str)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::string::string(std::string&& str)
|
||||
:
|
||||
std::string(std::move(str))
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::string::string(const char* str)
|
||||
:
|
||||
std::string(str)
|
||||
@ -102,12 +123,6 @@ inline Foam::string::string(const size_type len, const char c)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::string::string(std::string&& str)
|
||||
:
|
||||
std::string(std::move(str))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class String>
|
||||
|
||||
@ -30,7 +30,9 @@ License
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* const Foam::word::typeName = "word";
|
||||
|
||||
int Foam::word::debug(Foam::debug::debugSwitch(word::typeName, 0));
|
||||
|
||||
const Foam::word Foam::word::null;
|
||||
|
||||
|
||||
|
||||
@ -82,36 +82,31 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline word();
|
||||
word() = default;
|
||||
|
||||
//- Copy construct
|
||||
inline word(const word& w);
|
||||
|
||||
//- Construct as copy of character array
|
||||
inline word(const char* s, const bool doStripInvalid=true);
|
||||
|
||||
//- Construct as copy with a maximum number of characters
|
||||
inline word
|
||||
(
|
||||
const char* s,
|
||||
const size_type len,
|
||||
const bool doStripInvalid
|
||||
);
|
||||
|
||||
//- Construct as copy of Foam::string
|
||||
inline word(const string& s, const bool doStripInvalid=true);
|
||||
|
||||
//- Construct as copy of std::string
|
||||
inline word(const std::string& s, const bool doStripInvalid=true);
|
||||
word(const word&) = default;
|
||||
|
||||
//- Move construct
|
||||
inline word(word&& w);
|
||||
word(word&& w) = default;
|
||||
|
||||
//- Copy construct from Foam::string
|
||||
inline word(const string& s, bool doStrip=true);
|
||||
|
||||
//- Move construct from Foam::string
|
||||
inline word(string&& s, const bool doStripInvalid=true);
|
||||
inline word(string&& s, bool doStrip=true);
|
||||
|
||||
//- Copy construct from std::string
|
||||
inline word(const std::string& s, bool doStrip=true);
|
||||
|
||||
//- Move construct from std::string
|
||||
inline word(std::string&& s, const bool doStripInvalid=true);
|
||||
inline word(std::string&& s, bool doStrip=true);
|
||||
|
||||
//- Copy from character array
|
||||
inline word(const char* s, bool doStrip=true);
|
||||
|
||||
//- Copy from buffer for a maximum number of characters
|
||||
inline word(const char* s, size_type len, bool doStrip);
|
||||
|
||||
//- Construct from Istream
|
||||
word(Istream& is);
|
||||
@ -190,25 +185,25 @@ public:
|
||||
// Assignment
|
||||
|
||||
//- Copy assignment, no character validation required
|
||||
inline void operator=(const word& w);
|
||||
word& operator=(const word&) = default;
|
||||
|
||||
//- Move assignment, no character validation required
|
||||
word& operator=(word&& w) = default;
|
||||
|
||||
//- Copy assignment from Foam::string, stripping invalid characters
|
||||
inline void operator=(const string& s);
|
||||
|
||||
//- Copy assignment from std::string, stripping invalid characters
|
||||
inline void operator=(const std::string& s);
|
||||
|
||||
//- Copy, stripping invalid characters
|
||||
inline void operator=(const char* s);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(word&& w);
|
||||
inline word& operator=(const string& s);
|
||||
|
||||
//- Move assignment from Foam::string, stripping invalid characters
|
||||
inline void operator=(string&& s);
|
||||
inline word& operator=(string&& s);
|
||||
|
||||
//- Copy assignment from std::string, stripping invalid characters
|
||||
inline word& operator=(const std::string& s);
|
||||
|
||||
//- Move assignment from std::string, stripping invalid characters
|
||||
inline void operator=(std::string&& s);
|
||||
inline word& operator=(std::string&& s);
|
||||
|
||||
//- Copy, stripping invalid characters
|
||||
inline word& operator=(const char* s);
|
||||
|
||||
|
||||
// IOstream operators
|
||||
|
||||
@ -24,7 +24,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <cctype>
|
||||
#include <iostream> // for std::cerr
|
||||
#include <iostream> // For std::cerr
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
@ -78,89 +78,66 @@ inline void Foam::word::stripInvalid()
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::word::word()
|
||||
:
|
||||
string()
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::word::word(const word& w)
|
||||
:
|
||||
string(w)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::word::word(const string& s, const bool doStripInvalid)
|
||||
inline Foam::word::word(const string& s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
{
|
||||
if (doStripInvalid)
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word::word(const std::string& s, const bool doStripInvalid)
|
||||
inline Foam::word::word(string&& s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
string(std::move(s))
|
||||
{
|
||||
if (doStripInvalid)
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word::word(const char* s, const bool doStripInvalid)
|
||||
inline Foam::word::word(std::string&& s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
string(std::move(s))
|
||||
{
|
||||
if (doStripInvalid)
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word::word
|
||||
(
|
||||
const char* s,
|
||||
const size_type len,
|
||||
const bool doStripInvalid
|
||||
)
|
||||
inline Foam::word::word(const std::string& s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
{
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word::word(const char* s, bool doStrip)
|
||||
:
|
||||
string(s)
|
||||
{
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word::word(const char* s, size_type len, bool doStrip)
|
||||
:
|
||||
string(s, len)
|
||||
{
|
||||
if (doStripInvalid)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word::word(word&& w)
|
||||
:
|
||||
string(std::move(w))
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::word::word(string&& s, const bool doStripInvalid)
|
||||
:
|
||||
string(std::move(s))
|
||||
{
|
||||
if (doStripInvalid)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word::word(std::string&& s, const bool doStripInvalid)
|
||||
:
|
||||
string(std::move(s))
|
||||
{
|
||||
if (doStripInvalid)
|
||||
if (doStrip)
|
||||
{
|
||||
stripInvalid();
|
||||
}
|
||||
@ -198,50 +175,43 @@ inline bool Foam::word::removeExt()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::word::operator=(const word& w)
|
||||
{
|
||||
assign(w);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::word::operator=(word&& w)
|
||||
{
|
||||
assign(std::move(w));
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::word::operator=(const string& s)
|
||||
inline Foam::word& Foam::word::operator=(const string& s)
|
||||
{
|
||||
assign(s);
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::word::operator=(string&& s)
|
||||
inline Foam::word& Foam::word::operator=(string&& s)
|
||||
{
|
||||
assign(std::move(s));
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::word::operator=(const std::string& s)
|
||||
inline Foam::word& Foam::word::operator=(const std::string& s)
|
||||
{
|
||||
assign(s);
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::word::operator=(std::string&& s)
|
||||
inline Foam::word& Foam::word::operator=(std::string&& s)
|
||||
{
|
||||
assign(std::move(s));
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::word::operator=(const char* s)
|
||||
inline Foam::word& Foam::word::operator=(const char* s)
|
||||
{
|
||||
assign(s);
|
||||
stripInvalid();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -52,17 +52,17 @@ Foam::Istream& Foam::operator>>(Istream& is, word& w)
|
||||
}
|
||||
else if (t.isString())
|
||||
{
|
||||
// try a bit harder and convert string to word
|
||||
// Try a bit harder and convert string to word
|
||||
w = t.stringToken();
|
||||
string::stripInvalid<word>(w);
|
||||
|
||||
// flag empty strings and bad chars as an error
|
||||
// Flag empty strings and bad chars as an error
|
||||
if (w.empty() || w.size() != t.stringToken().size())
|
||||
{
|
||||
is.setBad();
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "wrong token type - expected word, found "
|
||||
"non-word characters "
|
||||
<< "wrong token type - expected word,"
|
||||
" found non-word characters "
|
||||
<< t.info()
|
||||
<< exit(FatalIOError);
|
||||
return is;
|
||||
|
||||
@ -122,42 +122,42 @@ public:
|
||||
//- Construct null
|
||||
inline wordRe();
|
||||
|
||||
//- Construct as copy
|
||||
//- Copy construct
|
||||
inline wordRe(const wordRe& str);
|
||||
|
||||
//- Move construct
|
||||
inline wordRe(wordRe&& str);
|
||||
|
||||
//- Construct from keyType, using its compile information
|
||||
inline explicit wordRe(const keyType& str);
|
||||
|
||||
//- Construct as copy of character array, treat as a literal
|
||||
//- Copy from character array, treat as a literal
|
||||
inline explicit wordRe(const char* str);
|
||||
|
||||
//- Construct as copy of std::string, treat as a literal
|
||||
//- Copy from std::string, treat as a literal
|
||||
inline explicit wordRe(const std::string& str);
|
||||
|
||||
//- Construct as copy of string, treat as a literal
|
||||
//- Copy from string, treat as a literal
|
||||
inline explicit wordRe(const string& str);
|
||||
|
||||
//- Construct as copy of word, treat as a literal
|
||||
//- Copy from word, treat as a literal
|
||||
inline explicit wordRe(const word& str);
|
||||
|
||||
//- Construct from keyType, use specified compile option
|
||||
//- Copy from keyType, use specified compile option
|
||||
inline wordRe(const keyType& str, const compOption opt);
|
||||
|
||||
//- Construct as copy of character array, use specified compile option
|
||||
//- Copy from character array, use specified compile option
|
||||
inline wordRe(const char* str, const compOption opt);
|
||||
|
||||
//- Construct as copy of std::string, use specified compile option
|
||||
//- Copy from std::string, use specified compile option
|
||||
inline wordRe(const std::string& str, const compOption opt);
|
||||
|
||||
//- Construct as copy of string, use specified compile option
|
||||
//- Copy from string, use specified compile option
|
||||
inline wordRe(const string& str, const compOption opt);
|
||||
|
||||
//- Construct as copy of word, use specified compile option
|
||||
//- Copy from word, use specified compile option
|
||||
inline wordRe(const word& str, const compOption opt);
|
||||
|
||||
//- Move construct
|
||||
inline wordRe(wordRe&& str);
|
||||
|
||||
//- Construct from Istream
|
||||
// Words are treated as literals, strings with an auto-test
|
||||
wordRe(Istream& is);
|
||||
@ -181,7 +181,7 @@ public:
|
||||
|
||||
//- Make wordRe a literal again, instead of a regular expression.
|
||||
// Optionally strip invalid word characters.
|
||||
inline void uncompile(const bool doStripInvalid = false) const;
|
||||
inline void uncompile(bool doStrip = false) const;
|
||||
|
||||
|
||||
// Editing
|
||||
|
||||
@ -64,6 +64,13 @@ inline Foam::wordRe::wordRe(const wordRe& str)
|
||||
}
|
||||
|
||||
|
||||
inline Foam::wordRe::wordRe(wordRe&& str)
|
||||
:
|
||||
word(std::move(static_cast<word&>(str))),
|
||||
re_(std::move(str.re_))
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::wordRe::wordRe(const keyType& str)
|
||||
:
|
||||
word(str, false),
|
||||
@ -148,13 +155,6 @@ inline Foam::wordRe::wordRe(const word& str, const compOption opt)
|
||||
}
|
||||
|
||||
|
||||
inline Foam::wordRe::wordRe(wordRe&& str)
|
||||
:
|
||||
word(std::move(static_cast<word&>(str))),
|
||||
re_(std::move(str.re_))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::wordRe::isPattern() const
|
||||
@ -200,9 +200,9 @@ inline bool Foam::wordRe::compile() const
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::wordRe::uncompile(const bool doStripInvalid) const
|
||||
inline void Foam::wordRe::uncompile(bool doStrip) const
|
||||
{
|
||||
if (re_.clear() && doStripInvalid)
|
||||
if (re_.clear() && doStrip)
|
||||
{
|
||||
// Skip stripping unless debug is active to avoid costly operations
|
||||
if (word::debug)
|
||||
|
||||
Reference in New Issue
Block a user