ENH: use fileName::nameLessExt() instead of fileName::name(bool)

- the purpose is more explicit, without needing to check documentation
  about what the bool parameter means.

STYLE: improve formatting of fileName documentation
This commit is contained in:
Mark Olesen
2017-03-10 11:49:56 +01:00
parent 9077098935
commit aa6b835104
11 changed files with 119 additions and 113 deletions

View File

@ -288,7 +288,7 @@ Foam::tmp<Foam::triSurfacePointScalarField> Foam::automatic::load()
vtkSurfaceWriter().write
(
surface_.searchableSurface::time().constant()/"triSurface",
surfaceName_.lessExt().name(),
surfaceName_.nameLessExt(),
meshedSurfRef
(
surface_.points(),

View File

@ -1657,9 +1657,9 @@ int main(int argc, char *argv[])
const fileName sFeatFileName
(
fileName(surf1Name).lessExt().name()
fileName(surf1Name).nameLessExt()
+ "_"
+ fileName(surf2Name).lessExt().name()
+ fileName(surf2Name).nameLessExt()
+ "_"
+ action
);

View File

@ -92,7 +92,7 @@ void Foam::dynamicCode::checkSecurity
Foam::word Foam::dynamicCode::libraryBaseName(const fileName& libPath)
{
word libName(libPath.name(true));
word libName(libPath.nameLessExt());
libName.removeStart("lib"); // Remove leading 'lib' from name
return libName;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -215,7 +215,7 @@ Foam::fileName Foam::fileName::clean() const
Foam::word Foam::fileName::name() const
{
size_type i = rfind('/');
const size_type i = rfind('/');
if (i == npos)
{
@ -223,16 +223,15 @@ Foam::word Foam::fileName::name() const
}
else
{
return substr(i+1, npos);
return substr(i+1);
}
}
Foam::word Foam::fileName::name(const bool noExt) const
Foam::word Foam::fileName::nameLessExt() const
{
if (noExt)
{
size_type beg = rfind('/');
if (beg == npos)
{
beg = 0;
@ -256,17 +255,12 @@ Foam::word Foam::fileName::name(const bool noExt) const
{
return substr(beg, dot - beg);
}
}
else
{
return this->name();
}
}
Foam::fileName Foam::fileName::path() const
{
size_type i = rfind('/');
const size_type i = rfind('/');
if (i == npos)
{
@ -285,7 +279,7 @@ Foam::fileName Foam::fileName::path() const
Foam::fileName Foam::fileName::lessExt() const
{
size_type i = find_ext();
const size_type i = find_ext();
if (i == npos)
{
@ -300,7 +294,7 @@ Foam::fileName Foam::fileName::lessExt() const
Foam::word Foam::fileName::ext() const
{
size_type i = find_ext();
const size_type i = find_ext();
if (i == npos)
{
@ -351,7 +345,7 @@ bool Foam::fileName::hasExt(const word& ending) const
bool Foam::fileName::hasExt(const wordRe& ending) const
{
size_type i = find_ext();
const size_type i = find_ext();
if (i == npos)
{
return false;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -176,25 +176,35 @@ public:
// Decomposition
//- Return file name (part beyond last /)
//- Return basename (part beyond last /), including its extension
//
// Behaviour compared to /usr/bin/basename:
// Input name() basename
// \verbatim
// input name() basename
// ----- ------ --------
// "foo" "foo" "foo"
// "/foo" "foo" "foo"
// "foo/bar" "bar" "bar"
// "/foo/bar" "bar" "bar"
// "/foo/bar/" "" "bar"
//
// \endverbatim
word name() const;
//- Return file name, optionally without extension
word name(const bool noExt) const;
//- Return basename, without extension
word nameLessExt() const;
//- Return basename, optionally without extension
// \deprecated in favour of name() or nameLessExt() which more
// explicitly describe their behaviour (MAR-2017).
word name(const bool noExt) const
{
return noExt ? this->nameLessExt() : this->name();
}
//- Return directory path name (part before last /)
//
// Behaviour compared to /usr/bin/dirname:
// \verbatim
// input path() dirname
// ----- ------ -------
// "foo" "." "."
@ -202,7 +212,7 @@ public:
// "foo/bar" "foo" "foo"
// "/foo/bar" "/foo" "/foo"
// "/foo/bar/" "/foo/bar/" "/foo"
//
// \endverbatim
fileName path() const;
//- Return file name without extension (part before last .)
@ -232,6 +242,7 @@ public:
//- Return path components as wordList
//
// Behaviour:
// \verbatim
// Input components()
// ----- ------
// "foo" 1("foo")
@ -239,6 +250,7 @@ public:
// "foo/bar" 2("foo", "bar")
// "/foo/bar" 2("foo", "bar")
// "/foo/bar/" 2("foo", "bar")
// \endverbatim
wordList components(const char delimiter = '/') const;
//- Return a single component of the path

View File

@ -245,7 +245,7 @@ void Foam::fileFormats::OBJedgeFormat::write
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
<< "o " << os.name().lessExt().name() << nl
<< "o " << os.name().nameLessExt() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# lines : " << edgeLst.size() << nl;

View File

@ -65,7 +65,7 @@ void Foam::fileFormats::STARCDedgeFormat::writeCase
const label nEdges
)
{
word caseName = os.name().lessExt().name();
const word caseName = os.name().nameLessExt();
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nEdges << " lines" << nl

View File

@ -70,7 +70,7 @@ void pointNoise::processData(const Function1Types::CSV<scalar>& data)
{
Info<< "Reading data file " << data.fName() << endl;
const fileName fNameBase = data.fName().name(true);
const word fNameBase = data.fName().nameLessExt();
// Time and pressure history data
scalarField t, p;

View File

@ -572,7 +572,7 @@ void surfaceNoise::calculate()
}
}
const word& fNameBase = fName.name(true);
const word fNameBase = fName.nameLessExt();
// Output directory for graphs
fileName outDir

View File

@ -237,7 +237,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
<< "o " << os.name().lessExt().name() << nl
<< "o " << os.name().nameLessExt() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << faceLst.size() << nl

View File

@ -87,7 +87,7 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
const UList<surfZone>& zoneLst
)
{
word caseName = os.name().lessExt().name();
const word caseName = os.name().nameLessExt();
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nFaces << " faces" << nl