ENH: adjust fileName methods for similarity to std::filesystem::path

- stem(), replace_name(), replace_ext(), remove_ext() etc

- string::contains() method - similar to C++23 method

  Eg,
      if (keyword.contains('/')) ...
  vs
      if (keyword.find('/') != std::string::npos) ...
This commit is contained in:
Mark Olesen 2022-10-06 11:33:07 +02:00
parent 98a510c317
commit 779a2ca084
89 changed files with 686 additions and 580 deletions

View File

@ -28,11 +28,6 @@ License
#include "DirLister.H"
#include <dirent.h>
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
static const Foam::word extgz("gz");
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::DirLister::const_iterator::open(const fileName& dir)
@ -110,9 +105,9 @@ Foam::word Foam::DirLister::next(DIR* dirPtr) const
if (ok)
{
if (fType == fileName::FILE && stripgz_ && name.hasExt(extgz))
if (fType == fileName::FILE && stripgz_ && name.has_ext("gz"))
{
name = name.lessExt();
name.remove_ext();
}
if (!name.empty() && accept(name))

View File

@ -83,9 +83,9 @@ int main(int argc, char *argv[])
{
IOstreamOption streamOpt;
if (outputName.hasExt("gz"))
if (outputName.has_ext("gz"))
{
outputName.removeExt();
outputName.remove_ext();
streamOpt.compression(IOstreamOption::COMPRESSED);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -260,7 +260,7 @@ int main(int argc, char *argv[])
"hello1",
"hello2",
"hello3",
"hello4.hmm"
"hello4.ext"
};
Info<< file1 << nl;
@ -270,7 +270,7 @@ int main(int argc, char *argv[])
{
file1,
"some",
"more/things.hmm"
"more/things.ext"
};
Info<< file2 << nl;
@ -281,7 +281,7 @@ int main(int argc, char *argv[])
{
std::string("ffO"),
"some",
"more/things.hmm"
"more/things.ext"
};
Info<< file3 << nl;
@ -295,7 +295,7 @@ int main(int argc, char *argv[])
{
"some",
file3,
"more/things.hmm",
"more/things.ext",
file1
};
Info<< "All ==> " << file4 << nl;
@ -328,26 +328,26 @@ int main(int argc, char *argv[])
fileName input1("path.to/media/image.png");
Info<<"File : " << input0 << " ext: "
<< Switch(input0.hasExt())
<< Switch(input0.has_ext())
<< " = " << input0.ext() << nl;
Info<<"File : " << input1 << " ext: "
<< Switch(input1.hasExt())
<< Switch(input1.has_ext())
<< " = " << input1.ext() << nl;
Info<<"File : " << endWithDot << " ext: "
<< Switch(endWithDot.hasExt())
<< Switch(endWithDot.has_ext())
<< " = " << endWithDot.ext() << " <-- perhaps return false?" << nl;
Info<<"File : " << endWithSlash << " ext: "
<< Switch(endWithSlash.hasExt())
<< Switch(endWithSlash.has_ext())
<< " = " << endWithSlash.ext() << nl;
Info<<"Remove extension " << (input0.removeExt());
Info<<"Remove extension " << (input0.remove_ext());
Info<< " now: " << input0 << nl;
Info<<"Remove extension " << (input1.removeExt());
Info<< " now: " << input1 << nl;
Info<<"Remove extension " << (endWithSlash.removeExt());
Info<<"Remove extension " << (endWithSlash.remove_ext());
Info<< " now: " << endWithSlash << nl;
wordList exts{ "jpg", "png", "txt", word::null };
@ -359,14 +359,14 @@ int main(int argc, char *argv[])
Info<< nl;
Info<<"Test hasExt(word)" << nl
Info<<"Test has_ext(word)" << nl
<<"~~~~~~~~~~~~~~~~~" << nl;
Info<<"Has extension(s):" << nl
<< "input: " << input1 << nl;
for (const word& e : exts)
{
Info<<" '" << e << "' -> "
<< Switch(input1.hasExt(e)) << nl;
<< Switch(input1.has_ext(e)) << nl;
}
Info<< nl;
@ -375,12 +375,12 @@ int main(int argc, char *argv[])
for (const word& e : exts)
{
Info<<" '" << e << "' -> "
<< Switch(endWithDot.hasExt(e)) << nl;
<< Switch(endWithDot.has_ext(e)) << nl;
}
Info<< nl;
Info<<"Test hasExt(wordRe)" << nl
Info<<"Test has_ext(wordRe)" << nl
<<"~~~~~~~~~~~~~~~~~~~" << nl;
// A regex with a zero length matcher doesn't work at all:
@ -393,25 +393,25 @@ int main(int argc, char *argv[])
Info<<"Has extension(s):" << nl
<< "input: " << endWithDot << nl;
Info<<" " << matcher0 << " -> "
<< Switch(endWithDot.hasExt(matcher0)) << nl;
<< Switch(endWithDot.has_ext(matcher0)) << nl;
Info<<" " << matcher1 << " -> "
<< Switch(endWithDot.hasExt(matcher1)) << nl;
<< Switch(endWithDot.has_ext(matcher1)) << nl;
Info<<" " << matcher2 << " -> "
<< Switch(endWithDot.hasExt(matcher2)) << nl;
<< Switch(endWithDot.has_ext(matcher2)) << nl;
Info<< "input: " << input1 << nl;
Info<<" " << matcher0 << " -> "
<< Switch(input1.hasExt(matcher0)) << nl;
<< Switch(input1.has_ext(matcher0)) << nl;
Info<<" " << matcher1 << " -> "
<< Switch(input1.hasExt(matcher1)) << nl;
<< Switch(input1.has_ext(matcher1)) << nl;
Info<<" " << matcher2 << " -> "
<< Switch(input1.hasExt(matcher2)) << nl;
<< Switch(input1.has_ext(matcher2)) << nl;
Info<< nl;
Info<<"Remove extension(s):" << nl << "input: " << input1 << nl;
while (!input1.empty())
{
if (input1.removeExt())
if (input1.remove_ext())
{
Info<< " -> " << input1 << nl;
}
@ -708,7 +708,7 @@ int main(int argc, char *argv[])
"hello1",
"hello2",
"hello3",
"hello4.hmm"
"hello4.ext"
};
fileName pathName(wrdList);
@ -718,14 +718,28 @@ int main(int argc, char *argv[])
<< "pathName.name() = >" << pathName.name() << "<\n"
<< "pathName.path() = " << pathName.path() << nl
<< "pathName.ext() = >" << pathName.ext() << "<\n"
<< "pathName.nameLessExt= >" << pathName.nameLessExt() << "<\n";
<< "pathName.stem = >" << pathName.stem() << "<\n";
Info<< "pathName.components() = " << pathName.components() << nl
<< "pathName.component(2) = " << pathName.component(2) << nl
<< endl;
Info<< "hasPath = " << Switch(pathName.hasPath()) << nl;
pathName.removePath();
pathName.replace_name("newName.ext");
Info<< "new name = " << pathName << nl;
Info<< "has ext = " << Switch::name(pathName.has_ext()) << nl;
Info<< "has ext('') = " << Switch::name(pathName.has_ext("")) << nl;
Info<< "has ext(foo) = " << Switch::name(pathName.has_ext("foo")) << nl;
Info<< "has ext(ext) = " << Switch::name(pathName.has_ext("ext")) << nl;
pathName.replace_ext("png");
Info<< "new ext = " << pathName << nl;
pathName.replace_ext(""); // Same as remove_ext
Info<< "new ext = " << pathName << nl;
Info<< "has path = " << Switch::name(pathName.has_path()) << nl;
pathName.remove_path();
pathName.removePath(); // second type should be a no-op
Info<< "removed path = " << pathName << nl;
Info<< nl << nl;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -61,10 +61,10 @@ int main(int argc, char *argv[])
InfoErr<< "output: " << outputName;
IOstreamOption::compressionType comp(IOstreamOption::UNCOMPRESSED);
if (outputName.hasExt("gz"))
if (outputName.has_ext("gz"))
{
comp = IOstreamOption::COMPRESSED;
outputName.removeExt();
outputName.remove_ext();
InfoErr<< " [compress]";
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -91,15 +91,15 @@ int main(int argc, char *argv[])
const auto importName = args.get<fileName>(1);
word ext;
if (!args.readIfPresent("ext", ext))
{
ext = importName.ext();
if (ext == "gz")
{
ext = importName.lessExt().ext();
}
}
word ext =
(
importName.has_ext("gz")
? importName.stem().ext()
: importName.ext()
);
// Allow override of extension
args.readIfPresent("ext", ext);
args.readIfPresent("stl-parser", fileFormats::STLReader::parserType);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -175,7 +175,7 @@ int main(int argc, char *argv[])
// strip erroneous extension (.ccm, .ccmg, .ccmp)
if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
{
exportName = exportName.lessExt();
exportName.remove_ext();
}
}
else if (args.found("export"))

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -137,7 +137,7 @@ int main(int argc, char *argv[])
// strip erroneous extension (.ccm, .ccmg, .ccmp)
if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
{
exportName = exportName.lessExt();
exportName.remove_ext();
}
}
else if (args.found("case"))

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -87,8 +87,8 @@ int main(int argc, char *argv[])
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 0);
const bool doTriangulate = args.found("tri");
fileName exportBase = exportName.lessExt();
word exportExt = exportName.ext();
const fileName exportBase = exportName.lessExt();
const word exportExt = exportName.ext();
if (!meshedSurface::canWriteType(exportExt, true))
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -298,7 +298,7 @@ Foam::tmp<Foam::triSurfacePointScalarField> Foam::automatic::load()
(
surface_.searchableSurface::time().constant()
/ "triSurface"
/ surfaceName_.nameLessExt() + "_cellSize"
/ surfaceName_.stem() + "_cellSize"
)
);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -144,11 +144,7 @@ using namespace Foam;
// but leave anything with '/' delimiters untouched
bool upgradeScope(word& entryName)
{
if
(
entryName.find('/') == string::npos
&& entryName.find(':') != string::npos
)
if (!entryName.contains('/') && entryName.contains(':'))
{
const wordList names(fileName(entryName).components(':'));

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -134,7 +134,7 @@ void writeZoning
const labelList& faceZone,
const word& fieldName,
const fileName& surfFilePath,
const fileName& surfFileNameBase
const word& surfFileStem
)
{
// Transcribe faces
@ -145,7 +145,7 @@ void writeZoning
(
surf.points(),
faces,
(surfFilePath / surfFileNameBase),
(surfFilePath / surfFileStem),
false // serial - already merged
);
@ -163,7 +163,7 @@ void writeParts
const label nFaceZones,
const labelList& faceZone,
const fileName& surfFilePath,
const fileName& surfFileNameBase
const word& surfFileStem
)
{
for (label zone = 0; zone < nFaceZones; zone++)
@ -183,7 +183,7 @@ void writeParts
fileName subName
(
surfFilePath
/ surfFileNameBase + "_" + name(zone) + ".obj"
/ surfFileStem + "_" + name(zone) + ".obj"
);
Info<< "writing part " << zone << " size " << subSurf.size()
@ -334,7 +334,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const auto surfFileName = args.get<fileName>(1);
const auto surfName = args.get<fileName>(1);
const bool checkSelfIntersect = args.found("checkSelfIntersection");
const bool splitNonManifold = args.found("splitNonManifold");
const label outputThreshold =
@ -360,12 +360,13 @@ int main(int argc, char *argv[])
}
Info<< "Reading surface from " << surfFileName << " ..." << nl << endl;
Info<< "Reading surface from "
<< args.relativePath(surfName) << " ..." << nl << endl;
// Read
// ~~~~
triSurface surf(surfFileName);
triSurface surf(surfName);
Info<< "Statistics:" << endl;
@ -373,17 +374,15 @@ int main(int argc, char *argv[])
Info<< endl;
// Determine path and extension
fileName surfFileNameBase(surfFileName.name());
const word fileType = surfFileNameBase.ext();
// Strip extension
surfFileNameBase = surfFileNameBase.lessExt();
// If extension was .gz strip original extension
if (fileType == "gz")
// Split into path and stem (no extension)
const fileName surfFilePath(surfName.path());
word surfFileStem(surfName.stem());
// If originally ".gz", need to strip extension again
if (surfName.has_ext("gz"))
{
surfFileNameBase = surfFileNameBase.lessExt();
surfFileStem.remove_ext();
}
const fileName surfFilePath(surfFileName.path());
// write bounding box corners
@ -484,7 +483,7 @@ int main(int argc, char *argv[])
(
subSurf.points(),
faces,
(surfFilePath / surfFileNameBase),
(surfFilePath / surfFileStem),
false // serial - already merged
);
@ -607,7 +606,7 @@ int main(int argc, char *argv[])
(
surf.points(),
faces,
(surfFilePath / surfFileNameBase),
(surfFilePath / surfFileStem),
false // serial - already merged
);
@ -810,26 +809,27 @@ int main(int argc, char *argv[])
if (!edgeFormat.empty() && openEdges.size())
{
const fileName openName
const fileName outputName
(
surfFileName.lessExt()
surfName.lessExt()
+ "_open."
+ edgeFormat
);
Info<< "Writing open edges to " << openName << " ..." << endl;
writeEdgeSet(openName, surf, openEdges);
Info<< "Writing open edges to "
<< args.relativePath(outputName) << " ..." << endl;
writeEdgeSet(outputName, surf, openEdges);
}
if (!edgeFormat.empty() && multipleEdges.size())
{
const fileName multName
const fileName outputName
(
surfFileName.lessExt()
surfName.lessExt()
+ "_multiply."
+ edgeFormat
);
Info<< "Writing multiply connected edges to "
<< multName << " ..." << endl;
writeEdgeSet(multName, surf, multipleEdges);
<< args.relativePath(outputName) << " ..." << endl;
writeEdgeSet(outputName, surf, multipleEdges);
}
}
else
@ -878,7 +878,7 @@ int main(int argc, char *argv[])
faceZone,
"zone",
surfFilePath,
surfFileNameBase
surfFileStem
);
if (numZones > outputThreshold)
@ -892,7 +892,7 @@ int main(int argc, char *argv[])
min(outputThreshold, numZones),
faceZone,
surfFilePath,
surfFileNameBase
surfFileStem
);
}
}
@ -944,7 +944,7 @@ int main(int argc, char *argv[])
normalZone,
"normal",
surfFilePath,
surfFileNameBase
surfFileStem
);
if (numNormalZones > outputThreshold)
@ -958,7 +958,7 @@ int main(int argc, char *argv[])
min(outputThreshold, numNormalZones),
normalZone,
surfFilePath,
surfFileNameBase + "_normal"
surfFileStem + "_normal"
);
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -68,13 +68,12 @@ using namespace Foam;
static word getExtension(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return ext;
return
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -44,13 +44,12 @@ using namespace Foam;
static word getExtension(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return ext;
return
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
}

View File

@ -291,7 +291,7 @@ int main(int argc, char *argv[])
// (ie, probably not a surface filename at all).
// If it is missing, this will fail nicely with an appropriate error
// message.
if (surfaceDict.found("surfaces") || !dictName.hasExt())
if (surfaceDict.found("surfaces") || !dictName.has_ext())
{
loader.select(surfaceDict.get<wordRes>("surfaces"));
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -81,15 +81,15 @@ using namespace Foam;
static word getExtension(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return ext;
return
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
}
// Non-short-circuiting check to get all warnings
static bool hasReadWriteTypes(const word& readType, const word& writeType)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -79,13 +79,12 @@ using namespace Foam;
static word getExtension(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return ext;
return
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
}

View File

@ -157,7 +157,7 @@ int main(int argc, char *argv[])
const auto userOutFileName = args.get<fileName>(1);
if (!userOutFileName.hasExt())
if (!userOutFileName.has_ext())
{
FatalErrorInFunction
<< "Missing extension on output name " << userOutFileName

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -79,13 +79,12 @@ using namespace Foam;
static word getExtension(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return ext;
return
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -156,10 +156,10 @@ int main(int argc, char *argv[])
if (changed)
{
const fileName name(surf.name());
surf.rename(name.lessExt() + "_patched." + name.ext());
const word oldName(surf.name());
surf.rename(oldName.lessExt() + "_patched." + oldName.ext());
Info<< "Writing repatched surface " << name << " to "
Info<< "Writing repatched surface " << oldName << " to "
<< surf.name() << nl << endl;
surf.write();

View File

@ -64,13 +64,12 @@ using namespace Foam::coordinateRotations;
static word getExtension(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return ext;
return
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
}

View File

@ -725,7 +725,6 @@ Foam::fileNameList Foam::readDir
// Basic sanity: cannot strip '.gz' from directory names
const bool stripgz = filtergz && (type != fileName::DIRECTORY);
const word extgz("gz");
fileNameList dirEntries;
@ -762,7 +761,7 @@ Foam::fileNameList Foam::readDir
// Validate filename without quotes, etc in the name.
// No duplicate slashes to strip - dirent will not have them anyhow.
const fileName name(fileName::validate(item));
fileName name(fileName::validate(item));
if (name != item)
{
++nFailed;
@ -780,14 +779,13 @@ Foam::fileNameList Foam::readDir
dirEntries.resize(dirEntries.size() + maxNnames);
}
if (stripgz && name.hasExt(extgz))
if (stripgz && name.has_ext("gz"))
{
dirEntries[nEntries++] = name.lessExt();
}
else
{
dirEntries[nEntries++] = name;
name.remove_ext();
}
dirEntries[nEntries] = std::move(name);
++nEntries;
}
}
}
@ -1238,7 +1236,7 @@ void* Foam::dlOpen(const fileName& libName, const bool check)
if
(
!handle
&& libName.find('/') == std::string::npos
&& !libName.has_path()
&& !libso.starts_with("lib")
)
{

View File

@ -901,7 +901,6 @@ Foam::fileNameList Foam::readDir
// Basic sanity: cannot strip '.gz' from directory names
const bool stripgz = filtergz && (type != fileName::DIRECTORY);
const word extgz("gz");
fileNameList dirEntries;
@ -941,7 +940,7 @@ Foam::fileNameList Foam::readDir
// Validate filename without spaces, quotes, etc in the name.
// No duplicate slashes to strip - dirent will not have them anyhow.
const fileName name(fileName::validate(item));
fileName name(fileName::validate(item));
if (name != item)
{
++nFailed;
@ -959,14 +958,13 @@ Foam::fileNameList Foam::readDir
dirEntries.resize(dirEntries.size() + maxNnames);
}
if (stripgz && name.hasExt(extgz))
if (stripgz && name.has_ext("gz"))
{
dirEntries[nEntries++] = name.lessExt();
}
else
{
dirEntries[nEntries++] = name;
name.remove_ext();
}
dirEntries[nEntries] = std::move(name);
++nEntries;
}
}
}
@ -1696,11 +1694,7 @@ void* Foam::dlOpen(const fileName& libName, const bool check)
{
fileName libso;
if
(
libName.find('/') == std::string::npos
&& !libName.starts_with("lib")
)
if (!libName.has_path() && !libName.starts_with("lib"))
{
// Try with 'lib' prefix
libso = "lib" + libName;
@ -1720,9 +1714,9 @@ void* Foam::dlOpen(const fileName& libName, const bool check)
// With canonical library extension ("so" or "dylib"), which remaps
// "libXX" to "libXX.so" as well as "libXX.so" -> "libXX.dylib"
if (!handle && !libso.hasExt(EXT_SO))
if (!handle && !libso.has_ext(EXT_SO))
{
libso = libso.lessExt().ext(EXT_SO);
libso.replace_ext(EXT_SO);
handle = ::dlopen(libso.c_str(), ldflags);
if (POSIX::debug)

View File

@ -140,7 +140,7 @@ void printSourceFileAndLine
// On other systems (Linux), only use relative addresses for libraries.
#ifndef __APPLE__
if (filename.hasExt("so"))
if (filename.has_ext("so"))
#endif
{
// Convert address into offset into dynamic library

View File

@ -327,7 +327,7 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchScoped
enum keyType::option matchOpt
) const
{
if (keyword.find('/') != string::npos)
if (keyword.contains('/'))
{
return csearchSlashScoped(keyword, matchOpt);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -295,7 +295,7 @@ bool Foam::entry::New
const bool scoped =
(
!disableFunctionEntries
&& (keyword.find('/') != string::npos)
&& keyword.contains('/')
);
// See (using exact match) if entry already present

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -61,7 +61,7 @@ bool Foam::functionEntries::removeEntry::execute
for (const wordRe& key : patterns)
{
if (key.isLiteral() && key.find('/') != string::npos)
if (key.isLiteral() && key.contains('/'))
{
// Remove scoped keyword, or keyword in the local scope
auto finder(parentDict.searchScoped(key, keyType::LITERAL));

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,7 +59,7 @@ std::unique_ptr<Foam::dlLibraryTable> Foam::dlLibraryTable::global_(nullptr);
Foam::word Foam::dlLibraryTable::basename(const fileName& libPath)
{
word libName(libPath.nameLessExt());
word libName(libPath.stem());
libName.removeStart("lib"); // Remove leading 'lib' from name
return libName;
}

View File

@ -174,7 +174,7 @@ Foam::expressions::exprString::toExpr
inline bool Foam::expressions::exprString::valid() const
{
const bool ok = (std::string::npos == find('$'));
const bool ok = !contains('$');
#ifdef FULLDEBUG
if (!ok)

View File

@ -1924,7 +1924,7 @@ void Foam::argList::displayDoc(bool source) const
}
// Can use FOAM_DOC_BROWSER='application file://%f' if required
if (docBrowser.find("%f") != std::string::npos)
if (docBrowser.contains("%f"))
{
docBrowser.replace("%f", url);
}

View File

@ -43,8 +43,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef Hasher_H
#define Hasher_H
#ifndef Foam_Hasher_H
#define Foam_Hasher_H
#include <cstddef>

View File

@ -211,25 +211,19 @@ bool Foam::SHA1Digest::operator==(const SHA1Digest& rhs) const
bool Foam::SHA1Digest::operator==(const std::string& hexdigits) const
{
// Null or empty string is not an error - interpret as '0000..'
if (hexdigits.empty())
{
return empty();
}
// Interpret empty string as '0000..'
size_t len = hexdigits.length();
return isEqual(hexdigits.data(), hexdigits.length());
return len ? isEqual(hexdigits.data(), len) : empty();
}
bool Foam::SHA1Digest::operator==(const char* hexdigits) const
{
// Null or empty string is not an error - interpret as '0000..'
if (!hexdigits || !*hexdigits)
{
return empty();
}
// Interpret nullptr or empty string as '0000..'
size_t len = (hexdigits ? strlen(hexdigits) : 0);
return isEqual(hexdigits, std::char_traits<char>::length(hexdigits));
return len ? isEqual(hexdigits, len) : empty();
}

View File

@ -393,7 +393,7 @@ bool Foam::fileName::clean()
}
std::string Foam::fileName::nameLessExt(const std::string& str)
std::string Foam::fileName::stem(const std::string& str)
{
auto beg = str.rfind('/');
auto dot = str.rfind('.');
@ -421,6 +421,29 @@ std::string Foam::fileName::nameLessExt(const std::string& str)
}
Foam::fileName& Foam::fileName::replace_name(const word& newName)
{
const auto len = newName.length();
if (len)
{
auto beg = rfind('/');
if (beg == npos)
{
fileName::assign(newName);
}
else
{
++beg;
replace(beg, length()-beg, newName);
}
}
return *this;
}
Foam::fileName Foam::fileName::relative
(
const fileName& parent,

View File

@ -254,42 +254,6 @@ public:
// Decomposition
//- Return basename (part beyond last /), including its extension
// The result normally corresponds to a Foam::word
//
// Behaviour compared to /usr/bin/basename:
// \verbatim
// input name() basename
// ----- ------ --------
// "" "" ""
// "abc" "abc" "abc"
// "/" "" "/"
// "/abc" "abc" "abc"
// "abc/def" "def" "def"
// "/abc/def" "def" "def"
// "/abc/def/" "" "def"
// "/abc/../def" "def" "def"
// \endverbatim
inline static std::string name(const std::string& str);
//- Return basename (part beyond last /), including its extension
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
inline word nameLessExt() const;
//- Deprecated(2017-03) return basename, optionally without extension
// \deprecated(2017-03) - use name() or nameLessExt() methods
// which describe their behaviour explicitly
word name(const bool noExt) const
{
return noExt ? this->nameLessExt() : this->name();
}
//- Return directory path name (part before last /)
// The result normally corresponds to a Foam::fileName
//
@ -311,11 +275,65 @@ public:
//- Return directory path name (part before last /)
inline fileName path() const;
//- Return true if it contains a '/' character
inline bool hasPath() const;
//- Remove leading path, return true if string changed.
using string::remove_path;
//- True if it contains a '/' character
inline bool has_path() const;
//- Return basename (part beyond last /), including its extension
// The result normally corresponds to a Foam::word
//
// Behaviour compared to /usr/bin/basename:
// \verbatim
// input name() basename
// ----- ------ --------
// "" "" ""
// "abc" "abc" "abc"
// "/" "" "/"
// "/abc" "abc" "abc"
// "abc/def" "def" "def"
// "/abc/def" "def" "def"
// "/abc/def/" "" "def"
// "/abc/../def" "def" "def"
// \endverbatim
inline static std::string name(const std::string& str);
//- Return basename (part beyond last /), including its extension
inline word name() const;
//- Replace basename (part beyond last /) with a new name
fileName& replace_name(const word& newName);
//- Return the basename, without extension
// The result normally corresponds to a Foam::word
static std::string stem(const std::string& str);
//- Return basename, without extension
inline word stem() const;
//- Return file name extension (part after last .)
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 '/'.
inline fileName& ext(const word& ending);
//- Remove extension (if any) and append a new one
inline fileName& replace_ext(const word& ending);
//- Return file name without extension (part before last .)
inline fileName lessExt() const;
//- Remove extension, returning true if string changed.
using string::remove_ext;
//- Various checks for extensions
using string::has_ext;
//- Remove leading path, returning true if string changed.
inline bool removePath();
//- Return a relative name by stripping off the parent directory
//- where possible.
@ -330,23 +348,6 @@ public:
const bool caseTag = false
) const;
//- Return file name without extension (part before last .)
inline fileName lessExt() const;
//- Return file name extension (part after last .)
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 '/'.
inline fileName& ext(const word& ending);
//- Various checks for extensions
using string::hasExt;
//- Remove extension, returning true if string changed.
using string::removeExt;
//- Return path components as wordList
//
@ -408,8 +409,44 @@ public:
//- Append a path element with '/' separator.
// No '/' separator is added if this or the argument are empty.
fileName& operator/=(const string& other);
// Housekeeping
//- Same as has_path()
bool hasPath() const { return has_path(); }
//- Same as remove_path()
bool removePath() { return remove_path(); }
//- Same as has_ext()
bool hasExt() const { return has_ext(); }
//- Same as has_ext()
bool hasExt(const std::string& s) const { return has_ext(s); }
//- Same as remove_ext()
bool removeExt() { return remove_ext(); }
//- Same as stem()
static std::string nameLessExt(const std::string& s)
{
return fileName::stem(s);
}
//- Same as stem()
word nameLessExt() const { return stem(); }
//- Deprecated(2017-03) return basename, optionally without extension
// \deprecated(2017-03) - use name() or stem() methods
// which describe their behaviour explicitly
word name(const bool noExt) const
{
return noExt ? stem() : name();
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// IOstream Operators

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -157,7 +157,7 @@ inline bool Foam::fileName::isAbsolute(const std::string& str)
inline bool Foam::fileName::isAbsolute() const
{
return isAbsolute(*this);
return fileName::isAbsolute(*this);
}
@ -167,9 +167,9 @@ inline bool Foam::fileName::isBackup() const
}
inline bool Foam::fileName::hasPath() const
inline bool Foam::fileName::has_path() const
{
return string::hasPath();
return contains('/');
}
@ -177,7 +177,7 @@ inline std::string Foam::fileName::path(const std::string& str)
{
const auto i = str.rfind('/');
if (i == npos)
if (i == std::string::npos)
{
return ".";
}
@ -192,7 +192,7 @@ inline std::string Foam::fileName::path(const std::string& str)
inline Foam::fileName Foam::fileName::path() const
{
return path(*this);
return fileName::path(*this);
}
@ -200,7 +200,7 @@ inline std::string Foam::fileName::name(const std::string& str)
{
const auto i = str.rfind('/');
if (npos == i)
if (i == std::string::npos)
{
return str;
}
@ -221,28 +221,9 @@ Foam::word Foam::fileName::ext() const
}
inline Foam::word Foam::fileName::nameLessExt() const
inline Foam::word Foam::fileName::stem() 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();
return fileName::stem(*this);
}
@ -253,6 +234,27 @@ inline Foam::fileName& Foam::fileName::ext(const word& ending)
}
inline Foam::fileName& Foam::fileName::replace_ext(const word& ending)
{
string::remove_ext();
string::ext(ending);
return *this;
}
inline Foam::fileName Foam::fileName::lessExt() const
{
const auto i = find_ext();
if (i == std::string::npos)
{
return *this;
}
return substr(0, i);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline Foam::fileName& Foam::fileName::operator=(const fileName& str)

View File

@ -235,7 +235,7 @@ public:
// Matching/Searching
//- Find position within the text.
// \return The index where it begins or string::npos if not found
// \return The index where it begins or std::string::npos if not found
//
// \note does not properly work with negated regex!
inline std::string::size_type find(const std::string& text) const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -48,7 +48,7 @@ Foam::word Foam::string::ext() const
if (i == npos)
{
return word::null;
return word();
}
return substr(i+1);
@ -78,11 +78,11 @@ bool Foam::string::ext(const word& ending)
}
bool Foam::string::hasExt(const wordRe& ending) const
bool Foam::string::has_ext(const wordRe& ending) const
{
if (ending.isLiteral() || ending.empty())
if (ending.empty() || ending.isLiteral())
{
return hasExt(static_cast<const std::string&>(ending));
return has_ext(static_cast<const std::string&>(ending));
}
const auto i = find_ext();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -47,8 +47,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef string_H
#define string_H
#ifndef Foam_string_H
#define Foam_string_H
#include "char.H"
#include "Hasher.H"
@ -118,26 +118,24 @@ 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;
inline bool has_ext() const;
//- Return true if the extension is the same as the given ending.
inline bool hasExt(const char* ending) const;
// No proper nullptr protection.
inline bool has_ext(const char* ending) const;
//- Return true if the extension is the same as the given ending.
inline bool hasExt(const std::string& ending) const;
inline bool has_ext(const std::string& ending) const;
//- Return true if the extension matches the given ending.
bool hasExt(const wordRe& ending) const;
bool has_ext(const wordRe& ending) const;
//- Remove extension, returning true if string changed.
inline bool removeExt();
//- Remove leading path, return true if string changed.
inline bool remove_path();
//- Remove leading path, returning true if string changed.
inline bool removePath();
//- Remove extension, return true if string changed.
inline bool remove_ext();
public:
@ -294,28 +292,60 @@ public:
// Housekeeping
//- True if string starts with the given prefix (cf. C++20)
//- True if string contains given character (cf. C++23)
bool contains(char c) const noexcept
{
return (find(c) != std::string::npos);
}
//- True if string contains given [string view] substring (cf. C++23)
bool contains(const std::string& s) const noexcept
{
return (find(s) != std::string::npos);
}
//- True if string contains given substring (cf. C++23)
bool contains(const char* s) const
{
return (find(s) != std::string::npos);
}
//- True if string starts with given character (cf. C++20)
bool starts_with(char c) const
{
return (!empty() && front() == c);
}
//- True if string starts with given [string view] prefix (C++20)
bool starts_with(const std::string& s) const
{
return (size() >= s.size() && !compare(0, s.size(), s));
}
//- True if string starts with the given character (cf. C++20)
bool starts_with(const char c) const
//- True if string starts with given prefix (C++20)
bool starts_with(const char* s) const
{
return (!empty() && front() == c);
const auto len = strlen(s);
return (size() >= len && !compare(0, len, s, len));
}
//- True if string ends with the given suffix (cf. C++20)
//- True if string ends with given character (cf. C++20)
bool ends_with(char c) const
{
return (!empty() && back() == c);
}
//- True if string ends with given [string view] suffix (cf. C++20)
bool ends_with(const std::string& s) const
{
return (size() >= s.size() && !compare(size()-s.size(), npos, s));
}
//- True if string ends with the given character (cf. C++20)
bool ends_with(const char c) const
//- True if string ends with given suffix (cf. C++20)
bool ends_with(const char* s) const
{
return (!empty() && back() == c);
const auto len = strlen(s);
return (size() >= len && !compare(size()-len, npos, s, len));
}
//- Count the number of occurrences of the specified character

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -47,39 +47,43 @@ inline std::string::size_type Foam::string::find_ext() const
}
inline bool Foam::string::hasPath() const
inline bool Foam::string::has_ext() const
{
return (npos != find('/'));
return (std::string::npos != find_ext());
}
inline bool Foam::string::hasExt() const
inline bool Foam::string::has_ext(const char* ending) const
{
return (npos != find_ext());
const auto n1 = size();
const auto n2 = strlen(ending);
// Like ends_with with extra check for dot
return
(
n1 > n2
&& operator[](n1-n2-1) == '.' // Require a dot separator
&& !compare(n1-n2, npos, ending, n2)
);
}
inline bool Foam::string::hasExt(const char* ending) const
inline bool Foam::string::has_ext(const std::string& ending) const
{
return (ending && string::hasExt(std::string(ending)));
const auto n1 = size();
const auto n2 = ending.size();
// Like ends_with with extra check for dot
return
(
n1 > n2
&& operator[](n1-n2-1) == '.' // Require a dot separator
&& !compare(n1-n2, npos, ending)
);
}
inline bool Foam::string::hasExt(const std::string& ending) const
{
const auto len = ending.size();
auto i = find_ext();
if (i == npos || !len)
{
return false;
}
++i; // Compare *after* the dot
return ((size() - i) == len) && !compare(i, npos, ending);
}
inline bool Foam::string::removePath()
inline bool Foam::string::remove_path()
{
const auto i = rfind('/');
@ -93,7 +97,7 @@ inline bool Foam::string::removePath()
}
inline bool Foam::string::removeExt()
inline bool Foam::string::remove_ext()
{
const auto i = find_ext();

View File

@ -704,12 +704,8 @@ std::string::size_type Foam::stringOps::count
std::string::size_type Foam::stringOps::count(const char* s, const char c)
{
return
(
s == nullptr
? 0
: std::count(s, (s + std::char_traits<char>::length(s)), c)
);
size_t len = (s ? strlen(s) : 0);
return len ? std::count(s, (s + len), c) : 0;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -108,34 +108,6 @@ Foam::word Foam::word::validate
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::word Foam::word::lessExt() const
{
const auto i = find_ext();
if (i == npos)
{
return *this;
}
return substr(0, i);
}
Foam::word Foam::word::ext() const
{
return string::ext();
}
Foam::word& Foam::word::ext(const word& ending)
{
string::ext(ending);
return *this;
}
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
Foam::word Foam::operator&(const word& a, const word& b)

View File

@ -161,22 +161,25 @@ public:
// File-like Functions
//- Return word without extension (part before last .)
word 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 '/'.
word& ext(const word& ending);
inline word& ext(const word& ending);
//- Remove extension (if any) and append a new one
inline word& replace_ext(const word& ending);
//- Return word without extension (part before last .)
inline word lessExt() const;
//- Remove extension, return true if string changed.
using string::remove_ext;
//- Various checks for extensions
using string::hasExt;
//- Remove extension, returning true if string changed.
using string::removeExt;
using string::has_ext;
// Member Operators
@ -205,6 +208,18 @@ public:
//- Copy, stripping invalid characters
inline word& operator=(const char* s);
// Housekeeping
//- Same as has_ext()
bool hasExt() const { return has_ext(); }
//- Same as has_ext()
bool hasExt(const std::string& s) const { return has_ext(s); }
//- Same as remove_ext()
bool removeExt() { return remove_ext(); }
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -161,6 +161,54 @@ inline void Foam::word::stripInvalid()
}
// FUTURE?
// inline Foam::word Foam::word::stem() const
// {
// const auto i = find_ext(); // Or just rfind('.')
//
// if (i == std::string::npos)
// {
// return *this;
// }
//
// return substr(0, i);
// }
inline Foam::word Foam::word::ext() const
{
return string::ext();
}
inline Foam::word& Foam::word::ext(const word& ending)
{
string::ext(ending);
return *this;
}
inline Foam::word& Foam::word::replace_ext(const word& ending)
{
string::remove_ext();
string::ext(ending);
return *this;
}
inline Foam::word Foam::word::lessExt() const
{
const auto i = find_ext(); // Or just rfind('.')
if (i == std::string::npos)
{
return *this;
}
return substr(0, i);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline Foam::word& Foam::word::operator=(const word& s)

View File

@ -323,7 +323,7 @@ bool Foam::fileFormats::FIREMeshWriter::write(const fileName& meshName) const
}
}
baseName = baseName.lessExt();
baseName.remove_ext();
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -201,11 +201,11 @@ Foam::fileFormats::ABAQUSCore::abaqusToFoamFaceAddr()
Foam::fileFormats::ABAQUSCore::shapeType
Foam::fileFormats::ABAQUSCore::getElementType(const std::string& elemTypeName)
Foam::fileFormats::ABAQUSCore::getElementType(const string& elemTypeName)
{
// Check for element-type
#undef checkElemType
#define checkElemType(test) (elemTypeName.find(test) != std::string::npos)
// Check for element-type.
#undef checkElemType
#define checkElemType(Name) elemTypeName.contains(Name)
if
(

View File

@ -76,8 +76,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef ABAQUSCore_H
#define ABAQUSCore_H
#ifndef Foam_ABAQUSCore_H
#define Foam_ABAQUSCore_H
#include "Fstream.H"
#include "Enum.H"
@ -121,7 +121,7 @@ public:
//- Classify named element type (eg, S4R) to known/supported
//- element types.
// The input string must be Uppercase!
static shapeType getElementType(const std::string& elemTypeName);
static shapeType getElementType(const string& elemTypeName);
//- The number of points associated with the element type
inline static int nPoints(shapeType tag)

View File

@ -48,7 +48,7 @@ Foam::ensightReadFile::detectBinaryHeader(const fileName& pathname)
istream& iss = is.stdStream();
// Binary string is *exactly* 80 characters
std::string buf(size_t(80), '\0');
string buf(size_t(80), '\0');
iss.read(&buf[0], 80);
if (!iss)
@ -64,12 +64,8 @@ Foam::ensightReadFile::detectBinaryHeader(const fileName& pathname)
buf.erase(endp);
}
// Contains "C Binary" ?
if
(
(buf.find("Binary") == std::string::npos)
&& (buf.find("binary") == std::string::npos)
)
// ASCII if it does not contain "C Binary"
if (!buf.contains("Binary") && !buf.contains("binary"))
{
fmt = IOstreamOption::ASCII;
}

View File

@ -161,8 +161,8 @@ void Foam::glTF::scene::addToAnimation
void Foam::glTF::scene::write(const fileName& outputFile)
{
fileName jsonFile(outputFile.lessExt());
jsonFile.ext("gltf");
fileName jsonFile(outputFile);
jsonFile.replace_ext("gltf");
// Note: called on master only
@ -178,8 +178,8 @@ void Foam::glTF::scene::write(const fileName& outputFile)
void Foam::glTF::scene::write(Ostream& os)
{
fileName binFile(os.name().lessExt());
binFile.ext("bin");
fileName binFile(os.name());
binFile.replace_ext("bin");
// Write binary file
// Note: using stdStream

View File

@ -78,8 +78,8 @@ void Foam::glTF::sceneWriter::open(const fileName& outputFile)
{
close();
fileName jsonFile(outputFile.lessExt());
jsonFile.ext("gltf");
fileName jsonFile(outputFile);
jsonFile.replace_ext("gltf");
// Note: called on master only
if (!isDir(jsonFile.path()))

View File

@ -72,7 +72,7 @@ bool Foam::fileFormats::STLCore::isBinaryName
return
(
format == STLFormat::UNKNOWN
? filename.hasExt("stlb")
? filename.has_ext("stlb")
: format == STLFormat::BINARY
);
}
@ -236,7 +236,7 @@ void Foam::fileFormats::STLCore::writeBinaryHeader
char header[STLHeaderSize];
sprintf(header, "STL binary file %u facets", nTris);
// avoid trailing junk
// Fill trailing with zeroes (to avoid writing junk)
for (size_t i = strlen(header); i < STLHeaderSize; ++i)
{
header[i] = 0;

View File

@ -334,16 +334,15 @@ bool Foam::vtk::fileWriter::open(const fileName& file, bool parallel)
if
(
legacy()
? outputFile_.hasExt(vtk::fileExtension[contentType_])
: outputFile_.hasExt(vtk::legacy::fileExtension)
? outputFile_.has_ext(vtk::fileExtension[contentType_])
: outputFile_.has_ext(vtk::legacy::fileExtension)
)
{
// Inappropriate extension. Legacy instead of xml, or vice versa.
outputFile_.removeExt();
outputFile_.remove_ext();
}
if (!outputFile_.hasExt(ext()))
if (!outputFile_.has_ext(ext()))
{
// Add extension if required
outputFile_.ext(ext());

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -162,7 +162,7 @@ Foam::Ostream& Foam::vtk::seriesWriter::print
// stem = "file"
// ext = ".vtm"
const word stem = base.nameLessExt();
const word stem = base.stem();
const word ext = "." + base.ext();
// Begin file-series (JSON)
@ -240,7 +240,7 @@ void Foam::vtk::seriesWriter::write
autoPtr<OFstream> osPtr =
(
seriesName.hasExt("series")
seriesName.has_ext("series")
? autoPtr<OFstream>::New(seriesName)
: autoPtr<OFstream>::New(seriesName + ".series")
);
@ -260,7 +260,7 @@ void Foam::vtk::seriesWriter::write
autoPtr<OFstream> osPtr =
(
seriesName.hasExt("series")
seriesName.has_ext("series")
? autoPtr<OFstream>::New(seriesName)
: autoPtr<OFstream>::New(seriesName + ".series")
);
@ -372,7 +372,7 @@ Foam::label Foam::vtk::seriesWriter::load
clear();
fileName seriesFile(seriesName);
if (!seriesFile.hasExt("series"))
if (!seriesFile.has_ext("series"))
{
seriesFile.ext("series");
}
@ -597,12 +597,12 @@ Foam::label Foam::vtk::seriesWriter::scan
fileName seriesFile(seriesName);
if (seriesName.hasExt("series"))
if (seriesName.has_ext("series"))
{
seriesFile.removeExt();
seriesFile.remove_ext();
}
const word stem = seriesFile.nameLessExt();
const word stem = seriesFile.stem();
const word ext = seriesFile.ext();
// Accept "fileN.ext", "fileNN.ext", but reject "file.ext"
@ -614,7 +614,7 @@ Foam::label Foam::vtk::seriesWriter::scan
return
(
minLen < file.length()
&& file.hasExt(ext) && file.starts_with(stem)
&& file.has_ext(ext) && file.starts_with(stem)
);
};

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -56,7 +56,7 @@ inline bool Foam::vtk::seriesWriter::append(const fileNameInstant& inst)
inline bool Foam::vtk::seriesWriter::append(fileNameInstant&& inst)
{
// Strip out path before saving
inst.name().removePath();
inst.name().remove_path();
return appendCheck(inst);
}
@ -80,7 +80,7 @@ inline bool Foam::vtk::seriesWriter::append
)
{
// Strip out path before saving
file.removePath();
file.remove_path();
return appendCheck(fileNameInstant(timeValue, std::move(file)));
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -421,7 +421,7 @@ bool Foam::vtk::vtmWriter::append(const fileName& file)
{
if (autoName_)
{
return append(fileName::nameLessExt(file), file);
return append(fileName::stem(file), file);
}
return append(word::null, file);
@ -436,7 +436,7 @@ bool Foam::vtk::vtmWriter::append
{
if (autoName_)
{
return append(fileName::nameLessExt(file), file, contentType);
return append(fileName::stem(file), file, contentType);
}
return append(word::null, file, contentType);
@ -471,7 +471,7 @@ bool Foam::vtk::vtmWriter::append
return false;
}
if (file.hasExt(vtk::fileExtension[contentType]))
if (file.has_ext(vtk::fileExtension[contentType]))
{
entries_.append(vtmEntry::entry(name, file));
}
@ -582,7 +582,7 @@ Foam::label Foam::vtk::vtmWriter::write(const fileName& file)
mkDir(file.path());
if (file.hasExt(ext()))
if (file.has_ext(ext()))
{
os_.open(file);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -256,7 +256,7 @@ Foam::vtk::formatter& Foam::vtk::formatter::DataSet
{
if (autoName)
{
xmlAttr("name", fileName::nameLessExt(file));
xmlAttr("name", fileName::stem(file));
}
xmlAttr("file", file);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -45,11 +45,7 @@ void Foam::solutionControl::storePrevIter() const
const word& fldName = fld.name();
if
(
(fldName.find("PrevIter") == std::string::npos)
&& mesh_.relaxField(fldName)
)
if (!fldName.contains("PrevIter") && mesh_.relaxField(fldName))
{
DebugInfo
<< algorithmName_ << ": storing previous iter for "

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -45,14 +45,16 @@ namespace functionObjects
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::ddt2::checkFormatName
(
const std::string& str
)
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
if (std::string::npos == str.find("@@"))
// Check that string contains the appropriate substitution token(s)
static bool checkFormatName(const word& str)
{
if (!str.contains("@@"))
{
WarningInFunction
<< "Bad result naming (no '@@' token found)."
@ -72,6 +74,10 @@ bool Foam::functionObjects::ddt2::checkFormatName
return true;
}
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::ddt2::accept(const word& fieldName) const
{

View File

@ -150,10 +150,6 @@ class ddt2
// Private Member Functions
//- Check that string contains the appropriate substitution token(s)
static bool checkFormatName(const std::string& str);
//- Accept unless field name appears to have already been processed
bool accept(const word& fieldName) const;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -43,14 +43,16 @@ namespace functionObjects
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::zeroGradient::checkFormatName
(
const std::string& str
)
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
if (std::string::npos == str.find("@@"))
// Check that string contains the appropriate substitution token(s)
static bool checkFormatName(const word& str)
{
if (!str.contains("@@"))
{
WarningInFunction
<< "Bad result naming (no '@@' token found)."
@ -70,6 +72,10 @@ bool Foam::functionObjects::zeroGradient::checkFormatName
return true;
}
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
int Foam::functionObjects::zeroGradient::process(const word& fieldName)
{
@ -95,7 +101,7 @@ Foam::functionObjects::zeroGradient::zeroGradient
:
fvMeshFunctionObject(name, runTime, dict),
selectFields_(),
resultName_(string::null),
resultName_(),
results_()
{
read(dict);

View File

@ -137,10 +137,6 @@ class zeroGradient
// Private Member Functions
//- Check that string contains the appropriate substitution token(s)
static bool checkFormatName(const std::string& str);
//- Accept unless field only has constraint patches
// (ie, empty/zero-gradient/processor)
// This should also avoid fields that were already processed by

View File

@ -156,7 +156,7 @@ bool Foam::functionObjects::vtkCloud::writeCloud
std::ofstream os;
autoPtr<vtk::formatter> format;
if (!file.hasExt("vtp"))
if (!file.has_ext("vtp"))
{
FatalErrorInFunction
<< type() << " File missing .vtp extension!" << nl << endl

View File

@ -158,7 +158,7 @@ bool Foam::coordSetWriters::gnuplotWriter::writeBuffered()
os.precision(precision_);
os << "set term pngcairo" << nl
<< "set output \"" << outputFile.nameLessExt() << ".png\"" << nl;
<< "set output \"" << outputFile.stem() << ".png\"" << nl;
label nplots = 0;
do

View File

@ -71,7 +71,7 @@ Foam::fileName Foam::coordSetWriters::gnuplotWriter::writeTemplate
os.precision(precision_);
os << "set term pngcairo" << nl
<< "set output \"" << outputFile.nameLessExt() << ".png\"" << nl;
<< "set output \"" << outputFile.stem() << ".png\"" << nl;
// Header
{

View File

@ -258,7 +258,7 @@ Foam::fileName Foam::coordSetWriters::nastranWriter::writeTemplate
OFstream os(outputFile);
fileFormats::NASCore::setPrecision(os, writeFormat_);
os << "TITLE=OpenFOAM " << outputFile.nameLessExt()
os << "TITLE=OpenFOAM " << outputFile.stem()
<< " geometry" << nl
<< "BEGIN BULK" << nl;
@ -301,7 +301,7 @@ Foam::fileName Foam::coordSetWriters::nastranWriter::writeTemplate
OFstream os(outputFile);
fileFormats::NASCore::setPrecision(os, writeFormat_);
os << "TITLE=OpenFOAM " << outputFile.nameLessExt()
os << "TITLE=OpenFOAM " << outputFile.stem()
<< " geometry" << nl
<< "BEGIN BULK" << nl;

View File

@ -231,7 +231,7 @@ Foam::fileName Foam::coordSetWriters::vtkWriter::write()
else
{
// Set name in title
writer_->beginFile(outputPath_.nameLessExt());
writer_->beginFile(outputPath_.stem());
}
writer_->writeGeometry();

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -60,12 +60,12 @@ namespace Foam
static enum Time::stopAtControls getStopAction(const std::string& filename)
{
// Slurp entire input file (must exist) as a single string
std::string fileContent;
string fileContent;
std::ifstream is(filename);
std::getline(is, fileContent, '\0');
if (fileContent.find("done") != std::string::npos)
if (fileContent.contains("done"))
{
return Time::stopAtControls::saEndTime;
}

View File

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

View File

@ -69,7 +69,7 @@ void Foam::fileFormats::STARCDedgeFormat::writeCase
const label nEdges
)
{
const word caseName = os.name().nameLessExt();
const word caseName = os.name().stem();
os << "! STARCD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nEdges << " lines" << nl
@ -114,7 +114,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
{
clear();
fileName baseName = filename.lessExt();
const fileName prefix(filename.lessExt());
// STARCD index of points
List<label> pointId;
@ -122,7 +122,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
// Read points from .vrt file
readPoints
(
IFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
IFstream(starFileName(prefix, STARCDCore::VRT_FILE))(),
storedPoints(),
pointId
);
@ -141,7 +141,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
// Read .cel file
// ~~~~~~~~~~~~~~
IFstream is(starFileName(baseName, STARCDCore::CEL_FILE));
IFstream is(starFileName(prefix, STARCDCore::CEL_FILE));
if (!is.good())
{
FatalErrorInFunction
@ -245,17 +245,17 @@ void Foam::fileFormats::STARCDedgeFormat::write
const pointField& pointLst = mesh.points();
const edgeList& edgeLst = mesh.edges();
fileName baseName = filename.lessExt();
const fileName prefix(filename.lessExt());
// The .vrt file
{
OFstream os(starFileName(baseName, STARCDCore::VRT_FILE), streamOpt);
OFstream os(starFileName(prefix, STARCDCore::VRT_FILE), streamOpt);
writePoints(os, pointLst);
}
// The .cel file
{
OFstream os(starFileName(baseName, STARCDCore::CEL_FILE), streamOpt);
OFstream os(starFileName(prefix, STARCDCore::CEL_FILE), streamOpt);
writeHeader(os, STARCDCore::HEADER_CEL);
writeLines(os, edgeLst);
}
@ -263,7 +263,7 @@ void Foam::fileFormats::STARCDedgeFormat::write
// Write a simple .inp file. Never compressed
writeCase
(
OFstream(starFileName(baseName, STARCDCore::INP_FILE))(),
OFstream(starFileName(prefix, STARCDCore::INP_FILE))(),
pointLst,
edgeLst.size()
);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -84,11 +84,13 @@ bool Foam::edgeMesh::canWriteType(const word& fileType, bool verbose)
bool Foam::edgeMesh::canRead(const fileName& name, bool verbose)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return canReadType(ext, verbose);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -60,14 +60,12 @@ Foam::edgeMesh::edgeMesh(const fileName& name)
bool Foam::edgeMesh::read(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
if (name.has_ext("gz"))
{
fileName unzipName = name.lessExt();
return read(unzipName, unzipName.ext());
return read(name.lessExt(), name.stem().ext());
}
return read(name, ext);
return read(name, name.ext());
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -54,11 +54,13 @@ Foam::autoPtr<Foam::edgeMesh> Foam::edgeMesh::New
Foam::autoPtr<Foam::edgeMesh> Foam::edgeMesh::New(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return New(name, ext);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -136,11 +136,13 @@ bool Foam::extendedEdgeMesh::canWriteType(const word& fileType, bool verbose)
bool Foam::extendedEdgeMesh::canRead(const fileName& name, bool verbose)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return canReadType(ext, verbose);
}
@ -626,14 +628,12 @@ Foam::extendedEdgeMesh::extendedEdgeMesh(const fileName& name)
bool Foam::extendedEdgeMesh::read(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
if (name.has_ext("gz"))
{
fileName unzipName = name.lessExt();
return read(unzipName, unzipName.ext());
return read(name.lessExt(), name.stem().ext());
}
return read(name, ext);
return read(name, name.ext());
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2017 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -65,11 +65,13 @@ Foam::autoPtr<Foam::extendedEdgeMesh> Foam::extendedEdgeMesh::New
const fileName& name
)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return New(name, ext);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -69,7 +69,7 @@ bool Foam::vtk::writePointSet
// Extension is inappropriate. Legacy instead of xml, or vice versa.
const word ext = vtk::fileExtension[vtk::fileTag::POLY_DATA];
if (file.hasExt(ext))
if (file.has_ext(ext))
{
// Extension is correct
os_.open(file);
@ -77,8 +77,8 @@ bool Foam::vtk::writePointSet
else if
(
legacy
? file.hasExt(ext)
: file.hasExt(vtk::legacy::fileExtension)
? file.has_ext(ext)
: file.has_ext(vtk::legacy::fileExtension)
)
{
// Extension is inappropriate. Legacy instead of xml, or vice versa.

View File

@ -76,7 +76,7 @@ void pointNoise::processData
{
Info<< "Reading data file " << data.fName() << endl;
const word fNameBase(data.fName().nameLessExt());
const word fNameBase(data.fName().stem());
// Time and pressure history data
scalarField t, p;

View File

@ -651,7 +651,7 @@ void surfaceNoise::calculate()
}
}
const word fNameBase = fName.nameLessExt();
const word fNameBase = fName.stem();
// Output directory
fileName outDirBase(baseFileDir(filei)/fNameBase);

View File

@ -96,11 +96,13 @@ bool Foam::MeshedSurface<Face>::canRead
bool verbose
)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return canReadType(ext, verbose);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -60,8 +60,7 @@ Foam::MeshedSurface<Face>::New
else if (fileType == "gz")
{
// Degenerate call
fileName unzipName(name.lessExt());
return New(unzipName, unzipName.ext(), mandatory);
return New(name.lessExt(), name.stem().ext(), mandatory);
}
else if (ext == "gz")
{
@ -117,16 +116,13 @@ template<class Face>
Foam::autoPtr<Foam::MeshedSurface<Face>>
Foam::MeshedSurface<Face>::New(const fileName& name)
{
const word ext(name.ext());
if (ext == "gz")
if (name.has_ext("gz"))
{
// Handle trailing "gz" on file name
fileName unzipName(name.lessExt());
return New(unzipName, unzipName.ext());
return New(name.lessExt(), name.stem().ext());
}
return New(name, ext);
return New(name, name.ext());
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -92,11 +92,13 @@ bool Foam::UnsortedMeshedSurface<Face>::canRead
bool verbose
)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return canReadType(ext, verbose);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,8 +59,7 @@ Foam::UnsortedMeshedSurface<Face>::New
else if (fileType == "gz")
{
// Degenerate call
fileName unzipName(name.lessExt());
return New(unzipName, unzipName.ext(), mandatory);
return New(name.lessExt(), name.stem().ext(), mandatory);
}
else if (ext == "gz")
{
@ -115,16 +114,13 @@ template<class Face>
Foam::autoPtr<Foam::UnsortedMeshedSurface<Face>>
Foam::UnsortedMeshedSurface<Face>::New(const fileName& name)
{
const word ext(name.ext());
if (ext == "gz")
if (name.has_ext("gz"))
{
// Handle trailing "gz" on file name
fileName unzipName(name.lessExt());
return New(unzipName, unzipName.ext());
return New(name.lessExt(), name.stem().ext());
}
return New(name, ext);
return New(name, name.ext());
}

View File

@ -171,11 +171,11 @@ Foam::ensightSurfaceReader::readGeometryHeader(ensightReadFile& is) const
is.read(buffer);
DebugInfo<< "buffer [" << buffer.length() << "] " << buffer << nl;
if (buffer.find("ignore") != std::string::npos)
if (buffer.contains("ignore"))
{
idHandling.first() = idTypes::IGNORE;
}
else if (buffer.find("given") != std::string::npos)
else if (buffer.contains("given"))
{
idHandling.first() = idTypes::GIVEN;
}
@ -184,11 +184,11 @@ Foam::ensightSurfaceReader::readGeometryHeader(ensightReadFile& is) const
is.read(buffer);
DebugInfo<< "buffer [" << buffer.length() << "] " << buffer << nl;
if (buffer.find("ignore") != std::string::npos)
if (buffer.contains("ignore"))
{
idHandling.second() = idTypes::IGNORE;
}
else if (buffer.find("given") != std::string::npos)
else if (buffer.contains("given"))
{
idHandling.second() = idTypes::GIVEN;
}
@ -198,7 +198,7 @@ Foam::ensightSurfaceReader::readGeometryHeader(ensightReadFile& is) const
is.read(buffer);
DebugInfo<< "buffer [" << buffer.length() << "] " << buffer << nl;
if (buffer.find("extents") != std::string::npos)
if (buffer.contains("extents"))
{
// Optional extents - read and discard 6 floats
// (xmin, xmax, ymin, ymax, zmin, zmax)
@ -278,7 +278,7 @@ void Foam::ensightSurfaceReader::readCase(ISstream& is)
const auto parsed = stringOps::splitSpace(buffer);
if (buffer.find(':') == string::npos || parsed.size() < 4)
if (!buffer.contains(':') || parsed.size() < 4)
{
WarningInFunction
<< "Error reading field file name. Current buffer: "

View File

@ -133,7 +133,7 @@ Foam::tmp<Foam::Field<Type>> Foam::ensightSurfaceReader::readField
// The element type, optionally with 'undef'
is.read(strValue);
if (strValue.find("undef") != std::string::npos)
if (strValue.contains("undef"))
{
// Skip undef entry
scalar value;

View File

@ -185,7 +185,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// HYPERMESH extension
// $HMNAME COMP 1"partName"
if (line.starts_with("$HMNAME COMP") && line.find('"') != string::npos)
if (line.starts_with("$HMNAME COMP") && line.contains('"'))
{
label groupId = readLabel(line.substr(16, 16));
@ -493,7 +493,7 @@ void Foam::fileFormats::NASsurfaceFormat<Face>::write
fileFormats::NASCore::setPrecision(os, fieldFormat::FREE);
os << "CEND" << nl
<< "TITLE = " << os.name().nameLessExt() << nl;
<< "TITLE = " << os.name().stem() << nl;
// Print zone names as comment
forAll(zones, zonei)

View File

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

View File

@ -86,12 +86,12 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
// Clear everything
this->clear();
fileName baseName = filename.lessExt();
const fileName prefix(filename.lessExt());
// Read cellTable names (if possible)
Map<word> cellTableLookup = readInpCellTable
(
IFstream(starFileName(baseName, STARCDCore::INP_FILE))()
IFstream(starFileName(prefix, STARCDCore::INP_FILE))()
);
@ -101,7 +101,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
// read points from .vrt file
readPoints
(
IFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
IFstream(starFileName(prefix, STARCDCore::VRT_FILE))(),
this->storedPoints(),
pointId
);
@ -117,7 +117,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
// Read .cel file
// ~~~~~~~~~~~~~~
IFstream is(starFileName(baseName, STARCDCore::CEL_FILE));
IFstream is(starFileName(prefix, STARCDCore::CEL_FILE));
if (!is.good())
{
FatalErrorInFunction
@ -293,16 +293,16 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
);
fileName baseName = filename.lessExt();
const fileName prefix(filename.lessExt());
// The .vrt file
{
OFstream os(starFileName(baseName, STARCDCore::VRT_FILE), streamOpt);
OFstream os(starFileName(prefix, STARCDCore::VRT_FILE), streamOpt);
writePoints(os, pointLst);
}
// The .cel file
OFstream os(starFileName(baseName, STARCDCore::CEL_FILE), streamOpt);
OFstream os(starFileName(prefix, STARCDCore::CEL_FILE), streamOpt);
writeHeader(os, STARCDCore::HEADER_CEL);
label faceIndex = 0;
@ -331,7 +331,7 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
// Simple .inp file - always UNCOMPRESSED
{
OFstream os(starFileName(baseName, STARCDCore::INP_FILE));
OFstream os(starFileName(prefix, STARCDCore::INP_FILE));
writeCase
(

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -87,7 +87,7 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
const UList<surfZone>& zoneLst
)
{
const word caseName = os.name().nameLessExt();
const word caseName = os.name().stem();
os << "! STARCD file written " << clock::dateTime().c_str() << nl
<< "! " << pts.size() << " points, " << nFaces << " faces" << nl

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -98,11 +98,13 @@ bool Foam::triSurface::canWriteType(const word& fileType, bool verbose)
bool Foam::triSurface::canRead(const fileName& name, bool verbose)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return canReadType(ext, verbose);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -58,8 +58,7 @@ Foam::triSurface::New
else if (fileType == "gz")
{
// Degenerate call
fileName unzipName(name.lessExt());
return New(unzipName, unzipName.ext());
return New(name.lessExt(), name.stem().ext());
}
else if (ext == "gz")
{
@ -140,16 +139,13 @@ Foam::triSurface::New
Foam::autoPtr<Foam::triSurface>
Foam::triSurface::New(const fileName& name)
{
const word ext(name.ext());
if (ext == "gz")
if (name.has_ext("gz"))
{
// Handle trailing "gz" on file name
fileName unzipName(name.lessExt());
return New(unzipName, unzipName.ext());
return New(name.lessExt(), name.stem().ext());
}
return New(name, ext);
return New(name, name.ext());
}

View File

@ -238,7 +238,7 @@ Foam::fileName Foam::surfaceWriters::vtkWriter::write()
else
{
// Surface name in title
writer_->beginFile(outputPath_.nameLessExt());
writer_->beginFile(outputPath_.stem());
}
writer_->writeGeometry();