ENH: add fileName::isBackup() method

- previously part of POSIX.C
This commit is contained in:
Mark Olesen
2018-01-10 10:22:57 +01:00
parent c093095444
commit 2b0eaf2d38
7 changed files with 80 additions and 59 deletions

View File

@ -39,16 +39,14 @@ const Foam::string Foam::string::null;
Foam::word Foam::string::ext() const
{
const size_type i = find_ext();
const auto i = find_ext();
if (i == npos)
{
return word::null;
}
else
{
return substr(i+1, npos);
}
return substr(i+1, npos);
}
@ -68,7 +66,7 @@ bool Foam::string::ext(const Foam::word& ending)
bool Foam::string::hasExt(const word& ending) const
{
size_type i = find_ext();
auto i = find_ext();
if (i == npos)
{
return false;
@ -86,7 +84,7 @@ bool Foam::string::hasExt(const word& ending) const
bool Foam::string::hasExt(const wordRe& ending) const
{
const size_type i = find_ext();
const auto i = find_ext();
if (i == npos)
{
return false;

View File

@ -84,7 +84,11 @@ protected:
//- Find position of a file extension dot, return npos on failure.
// A wrapped version of find_last_of("./") with additional logic.
inline size_type find_ext() const;
inline static std::string::size_type find_ext(const std::string& str);
//- Find position of a file extension dot, return npos on failure.
// A wrapped version of find_last_of("./") with additional logic.
inline std::string::size_type find_ext() const;
//- Return file name extension (part after last .)
word ext() const;

View File

@ -26,18 +26,22 @@ License
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
inline std::string::size_type Foam::string::find_ext() const
inline std::string::size_type Foam::string::find_ext(const std::string& str)
{
const size_type i = find_last_of("./");
const auto i = str.find_last_of("./");
if (i == npos || i == 0 || operator[](i) == '/')
if (i == npos || i == 0 || str[i] == '/')
{
return npos;
}
else
{
return i;
}
return i;
}
inline std::string::size_type Foam::string::find_ext() const
{
return find_ext(*this);
}
@ -49,17 +53,15 @@ inline bool Foam::string::hasExt() const
inline bool Foam::string::removeExt()
{
const size_type i = find_ext();
const auto i = find_ext();
if (i == npos)
{
return false;
}
else
{
this->resize(i);
return true;
}
this->resize(i);
return true;
}