ENH: add basic support for file extensions to word

- when a plain word is used as a directory-local name for file.
  We don't have a full blown fileName, but still want to check/remove
  extensions etc.
This commit is contained in:
Mark Olesen
2017-05-26 10:48:01 +02:00
parent ccc1ce4a25
commit 0564efb9e1
10 changed files with 265 additions and 101 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,6 +25,45 @@ License
#include <iostream>
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
inline std::string::size_type Foam::string::find_ext() const
{
const size_type i = find_last_of("./");
if (i == npos || i == 0 || operator[](i) == '/')
{
return npos;
}
else
{
return i;
}
}
inline bool Foam::string::hasExt() const
{
return (find_ext() != npos);
}
inline bool Foam::string::removeExt()
{
const size_type i = find_ext();
if (i == npos)
{
return false;
}
else
{
this->resize(i);
return true;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::string::string()