ENH: string: allow empty string substitution in expand

This commit is contained in:
mattijs
2011-02-18 18:08:05 +00:00
parent 6d0c6483eb
commit 596430d35d
2 changed files with 12 additions and 6 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -94,7 +94,7 @@ Foam::string& Foam::string::replaceAll
// Expand all occurences of environment variables and initial tilde sequences // Expand all occurences of environment variables and initial tilde sequences
Foam::string& Foam::string::expand(const bool recurse) Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
{ {
size_type startEnvar = 0; size_type startEnvar = 0;
@ -152,11 +152,13 @@ Foam::string& Foam::string::expand(const bool recurse)
); );
startEnvar += enVarString.size(); startEnvar += enVarString.size();
} }
else if (allowEmptyVar)
{
startEnvar = endEnvar;
}
else else
{ {
//startEnvar = endEnvar; FatalErrorIn("string::expand(const bool, const bool)")
FatalErrorIn("string::expand()")
<< "Unknown variable name " << enVar << '.' << "Unknown variable name " << enVar << '.'
<< exit(FatalError); << exit(FatalError);
} }

View File

@ -182,7 +182,11 @@ public:
// //
// \sa // \sa
// Foam::findEtcFile // Foam::findEtcFile
string& expand(const bool recurse=false); string& expand
(
const bool recurse=false,
const bool allowEmptyVar = false
);
//- Remove repeated characters returning true if string changed //- Remove repeated characters returning true if string changed
bool removeRepeated(const char); bool removeRepeated(const char);