diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C index 9b69ae120e..ccaff192aa 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C @@ -288,7 +288,7 @@ Foam::tmp Foam::automatic::load() vtkSurfaceWriter().write ( surface_.searchableSurface::time().constant()/"triSurface", - surfaceName_.lessExt().name(), + surfaceName_.nameLessExt(), meshedSurfRef ( surface_.points(), diff --git a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C index e4d09ce779..abc3d321d2 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C +++ b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C @@ -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 ); diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C index 2a96a9dafb..836f47500e 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C @@ -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; } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index d0dfa2c074..258167fc1e 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -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,50 +223,44 @@ 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) { - size_type beg = rfind('/'); - 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); - } + beg = 0; } 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 { - 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; diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 5580ffa3f7..a8f17cf6b0 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -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. @@ -161,92 +161,104 @@ public: fileName clean() const; - // Interrogation + // Interrogation - //- Return the file type: FILE, DIRECTORY, UNDEFINED or - // LINK (only if followLink=false) - Type type(const bool followLink = true) const; + //- Return the file type: FILE, DIRECTORY, UNDEFINED or + // LINK (only if followLink=false) + Type type(const bool followLink = true) const; - //- Return true if file name is absolute - bool isAbsolute() const; + //- Return true if file name is absolute + bool isAbsolute() const; - //- Convert from relative to absolute - fileName& toAbsolute(); + //- Convert from relative to absolute + fileName& toAbsolute(); - // Decomposition + // Decomposition - //- Return file name (part beyond last /) - // - // Behaviour compared to /usr/bin/basename: - // Input name() basename - // ----- ------ -------- - // "foo" "foo" "foo" - // "/foo" "foo" "foo" - // "foo/bar" "bar" "bar" - // "/foo/bar" "bar" "bar" - // "/foo/bar/" "" "bar" - // - word name() const; + //- Return basename (part beyond last /), including its extension + // + // Behaviour compared to /usr/bin/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 directory path name (part before last /) - // - // Behaviour compared to /usr/bin/dirname: - // input path() dirname - // ----- ------ ------- - // "foo" "." "." - // "/foo" "/" "foo" - // "foo/bar" "foo" "foo" - // "/foo/bar" "/foo" "/foo" - // "/foo/bar/" "/foo/bar/" "/foo" - // - fileName path() 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 file name without extension (part before last .) - fileName lessExt() const; + //- Return directory path name (part before last /) + // + // 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 .) - word ext() const; + //- Return file name without extension (part before last .) + fileName lessExt() 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 '/'. - fileName& ext(const word& ending); + //- Return file name extension (part after last .) + word ext() const; - //- Return true if it has an extension or simply ends with a '.' - bool hasExt() 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 '/'. + fileName& ext(const word& ending); - //- Return true if the extension is the same as the given ending. - bool hasExt(const word& ending) const; + //- Return true if it has an extension or simply ends with a '.' + bool hasExt() const; - //- Return true if the extension matches the given ending. - bool hasExt(const wordRe& ending) const; + //- Return true if the extension is the same as the given ending. + bool hasExt(const word& ending) const; - //- Remove extension, returning true if string changed. - bool removeExt(); + //- Return true if the extension matches the given ending. + bool hasExt(const wordRe& ending) const; + + //- Remove extension, returning true if string changed. + bool removeExt(); - //- Return path components as wordList - // - // Behaviour: - // Input components() - // ----- ------ - // "foo" 1("foo") - // "/foo" 1("foo") - // "foo/bar" 2("foo", "bar") - // "/foo/bar" 2("foo", "bar") - // "/foo/bar/" 2("foo", "bar") - wordList components(const char delimiter = '/') const; + //- Return path components as wordList + // + // Behaviour: + // \verbatim + // Input components() + // ----- ------ + // "foo" 1("foo") + // "/foo" 1("foo") + // "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 - word component - ( - const size_type cmpt, - const char delimiter = '/' - ) const; + //- Return a single component of the path + word component + ( + const size_type cmpt, + const char delimiter = '/' + ) const; // Member operators diff --git a/src/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C b/src/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C index af52b56c59..9f423b0e6b 100644 --- a/src/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C +++ b/src/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C @@ -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; diff --git a/src/edgeMesh/edgeMeshFormats/starcd/STARCDedgeFormat.C b/src/edgeMesh/edgeMeshFormats/starcd/STARCDedgeFormat.C index 2d6e658d88..f575a60a2a 100644 --- a/src/edgeMesh/edgeMeshFormats/starcd/STARCDedgeFormat.C +++ b/src/edgeMesh/edgeMeshFormats/starcd/STARCDedgeFormat.C @@ -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 diff --git a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C index b711a55bac..88b245b62c 100644 --- a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C +++ b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C @@ -70,7 +70,7 @@ void pointNoise::processData(const Function1Types::CSV& 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; diff --git a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C index faed14eea6..051f016969 100644 --- a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C +++ b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C @@ -572,7 +572,7 @@ void surfaceNoise::calculate() } } - const word& fNameBase = fName.name(true); + const word fNameBase = fName.nameLessExt(); // Output directory for graphs fileName outDir diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C index 04274c775a..395e2bacb7 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C @@ -237,7 +237,7 @@ void Foam::fileFormats::OBJsurfaceFormat::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 diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C index 8200a5b58b..1894f293af 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C @@ -87,7 +87,7 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase const UList& 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