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 vtkSurfaceWriter().write
( (
surface_.searchableSurface::time().constant()/"triSurface", surface_.searchableSurface::time().constant()/"triSurface",
surfaceName_.lessExt().name(), surfaceName_.nameLessExt(),
meshedSurfRef meshedSurfRef
( (
surface_.points(), surface_.points(),

View File

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

View File

@ -92,7 +92,7 @@ void Foam::dynamicCode::checkSecurity
Foam::word Foam::dynamicCode::libraryBaseName(const fileName& libPath) 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 libName.removeStart("lib"); // Remove leading 'lib' from name
return libName; return libName;
} }

View File

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

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -161,92 +161,104 @@ public:
fileName clean() const; fileName clean() const;
// Interrogation // Interrogation
//- Return the file type: FILE, DIRECTORY, UNDEFINED or //- Return the file type: FILE, DIRECTORY, UNDEFINED or
// LINK (only if followLink=false) // LINK (only if followLink=false)
Type type(const bool followLink = true) const; Type type(const bool followLink = true) const;
//- Return true if file name is absolute //- Return true if file name is absolute
bool isAbsolute() const; bool isAbsolute() const;
//- Convert from relative to absolute //- Convert from relative to absolute
fileName& toAbsolute(); fileName& toAbsolute();
// Decomposition // Decomposition
//- Return file name (part beyond last /) //- Return basename (part beyond last /), including its extension
// //
// Behaviour compared to /usr/bin/basename: // Behaviour compared to /usr/bin/basename:
// Input name() basename // \verbatim
// ----- ------ -------- // input name() basename
// "foo" "foo" "foo" // ----- ------ --------
// "/foo" "foo" "foo" // "foo" "foo" "foo"
// "foo/bar" "bar" "bar" // "/foo" "foo" "foo"
// "/foo/bar" "bar" "bar" // "foo/bar" "bar" "bar"
// "/foo/bar/" "" "bar" // "/foo/bar" "bar" "bar"
// // "/foo/bar/" "" "bar"
word name() const; // \endverbatim
word name() const;
//- Return file name, optionally without extension //- Return basename, without extension
word name(const bool noExt) const; word nameLessExt() const;
//- Return directory path name (part before last /) //- Return basename, optionally without extension
// // \deprecated in favour of name() or nameLessExt() which more
// Behaviour compared to /usr/bin/dirname: // explicitly describe their behaviour (MAR-2017).
// input path() dirname word name(const bool noExt) const
// ----- ------ ------- {
// "foo" "." "." return noExt ? this->nameLessExt() : this->name();
// "/foo" "/" "foo" }
// "foo/bar" "foo" "foo"
// "/foo/bar" "/foo" "/foo"
// "/foo/bar/" "/foo/bar/" "/foo"
//
fileName path() const;
//- Return file name without extension (part before last .) //- Return directory path name (part before last /)
fileName lessExt() const; //
// Behaviour compared to /usr/bin/dirname:
// \verbatim
// input path() dirname
// ----- ------ -------
// "foo" "." "."
// "/foo" "/" "foo"
// "foo/bar" "foo" "foo"
// "/foo/bar" "/foo" "/foo"
// "/foo/bar/" "/foo/bar/" "/foo"
// \endverbatim
fileName path() const;
//- Return file name extension (part after last .) //- Return file name without extension (part before last .)
word ext() const; fileName lessExt() const;
//- Append a '.' and the ending, and return the object. //- Return file name extension (part after last .)
// The '.' and ending will not be added when the ending is empty, word ext() const;
// or when the file name is empty or ended with a '/'.
fileName& ext(const word& ending);
//- Return true if it has an extension or simply ends with a '.' //- Append a '.' and the ending, and return the object.
bool hasExt() const; // 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);
//- Return true if the extension is the same as the given ending. //- Return true if it has an extension or simply ends with a '.'
bool hasExt(const word& ending) const; bool hasExt() const;
//- Return true if the extension matches the given ending. //- Return true if the extension is the same as the given ending.
bool hasExt(const wordRe& ending) const; bool hasExt(const word& ending) const;
//- Remove extension, returning true if string changed. //- Return true if the extension matches the given ending.
bool removeExt(); bool hasExt(const wordRe& ending) const;
//- Remove extension, returning true if string changed.
bool removeExt();
//- Return path components as wordList //- Return path components as wordList
// //
// Behaviour: // Behaviour:
// Input components() // \verbatim
// ----- ------ // Input components()
// "foo" 1("foo") // ----- ------
// "/foo" 1("foo") // "foo" 1("foo")
// "foo/bar" 2("foo", "bar") // "/foo" 1("foo")
// "/foo/bar" 2("foo", "bar") // "foo/bar" 2("foo", "bar")
// "/foo/bar/" 2("foo", "bar") // "/foo/bar" 2("foo", "bar")
wordList components(const char delimiter = '/') const; // "/foo/bar/" 2("foo", "bar")
// \endverbatim
wordList components(const char delimiter = '/') const;
//- Return a single component of the path //- Return a single component of the path
word component word component
( (
const size_type cmpt, const size_type cmpt,
const char delimiter = '/' const char delimiter = '/'
) const; ) const;
// Member operators // Member operators

View File

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

View File

@ -65,7 +65,7 @@ void Foam::fileFormats::STARCDedgeFormat::writeCase
const label nEdges 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 os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nEdges << " lines" << 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; 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 // Time and pressure history data
scalarField t, p; 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 // Output directory for graphs
fileName outDir fileName outDir

View File

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

View File

@ -87,7 +87,7 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
const UList<surfZone>& zoneLst 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 os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nFaces << " faces" << nl << "! " << pointLst.size() << " points, " << nFaces << " faces" << nl