Skip to content
Snippets Groups Projects
Commit 0a7eb6e6 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

BUG: bad names if ensight mask contains NO placeholder (fixes #1747)

- affects ensightSurfaceReader only.

  If there are no `*` characters, protect against replacement.
  Otherwise it would attempt to replace a zero-length string with
  a single `0`, which results in prepending the name.

STYLE: ensightSurfaceReader constructor explicit
parent 013a5223
No related branches found
No related tags found
No related merge requests found
......@@ -127,16 +127,24 @@ Foam::fileName Foam::ensightSurfaceReader::replaceMask
(
const fileName& fName,
const label timeIndex
) const
)
{
fileName result(fName);
std::ostringstream oss;
label nMask = stringOps::count(fName, '*');
const std::string maskStr(nMask, '*');
oss << std::setfill('0') << std::setw(nMask) << timeIndex;
const word indexStr = oss.str();
result.replace(maskStr, indexStr);
const auto nMask = stringOps::count(fName, '*');
// If there are any '*' chars, they are assumed to be contiguous
// Eg, data/******/geometry
if (nMask)
{
std::ostringstream oss;
oss << std::setfill('0') << std::setw(nMask) << timeIndex;
const std::string maskStr(nMask, '*');
const std::string indexStr = oss.str();
result.replace(maskStr, indexStr);
}
return result;
}
......
......@@ -112,12 +112,12 @@ protected:
//- Read and check a section header
void debugSection(const word& expected, IFstream& is) const;
//- Replace the mask with an 0 padded string
fileName replaceMask
//- Replace the '*' mask chars with a 0 padded string.
static fileName replaceMask
(
const fileName& fName,
const label timeIndex
) const;
);
//- Read (and discard) geometry file header.
// \return information about node/element id handling
......@@ -158,10 +158,11 @@ public:
//- Runtime type information
TypeName("ensight");
// Constructors
//- Construct from fileName
ensightSurfaceReader(const fileName& fName);
explicit ensightSurfaceReader(const fileName& fName);
//- Destructor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment