STYLE: simplify stringOps::expand names

This commit is contained in:
Mark Olesen
2011-02-23 14:42:51 +01:00
parent 67fc6a171a
commit 97a15a8b06
5 changed files with 46 additions and 51 deletions

View File

@ -84,7 +84,7 @@ bool Foam::functionEntries::codeStream::execute
}
// get code dictionary
// must reference parent for stringOps::expandDict to work nicely
// must reference parent for stringOps::expand to work nicely
dictionary codeDict("#codeStream", parentDict, is);
@ -97,7 +97,7 @@ bool Foam::functionEntries::codeStream::execute
if (codeDict.found("codeInclude"))
{
codeInclude = stringOps::trim(codeDict["codeInclude"]);
stringOps::inplaceExpandDict(codeInclude, codeDict);
stringOps::inplaceExpand(codeInclude, codeDict);
}
// "codeOptions" is optional
@ -105,12 +105,12 @@ bool Foam::functionEntries::codeStream::execute
if (codeDict.found("codeOptions"))
{
codeOptions = stringOps::trim(codeDict["codeOptions"]);
stringOps::inplaceExpandDict(codeOptions, codeDict);
stringOps::inplaceExpand(codeOptions, codeDict);
}
// "code" is mandatory
string code = stringOps::trim(codeDict["code"]);
stringOps::inplaceExpandDict(code, codeDict);
stringOps::inplaceExpand(code, codeDict);
// Create SHA1 digest from the contents

View File

@ -51,28 +51,25 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
Foam::fileName Foam::codeStreamTools::baseDir()
{
return stringOps::expandEnv("$FOAM_CASE/codeStream");
return stringOps::expand("$FOAM_CASE/codeStream");
}
Foam::fileName Foam::codeStreamTools::libSubDir()
{
return stringOps::expandEnv("platforms/$WM_OPTIONS/lib");
return stringOps::expand("platforms/$WM_OPTIONS/lib");
}
Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName)
{
return stringOps::expandEnv
(
"$FOAM_CASE/codeStream/" + subDirName
);
return stringOps::expand("$FOAM_CASE/codeStream/" + subDirName);
}
Foam::fileName Foam::codeStreamTools::libPath(const word& codeName)
{
return stringOps::expandEnv
return stringOps::expand
(
"$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib"
+ codeName + ".so"

View File

@ -143,7 +143,7 @@ Foam::string& Foam::stringOps::inplaceExpand
}
Foam::string Foam::stringOps::expandDict
Foam::string Foam::stringOps::expand
(
const string& original,
const dictionary& dict,
@ -151,11 +151,11 @@ Foam::string Foam::stringOps::expandDict
)
{
string s(original);
return inplaceExpandDict(s, dict, sigil);
return inplaceExpand(s, dict, sigil);
}
Foam::string& Foam::stringOps::inplaceExpandDict
Foam::string& Foam::stringOps::inplaceExpand
(
string& s,
const dictionary& dict,
@ -218,11 +218,11 @@ Foam::string& Foam::stringOps::inplaceExpandDict
);
// lookup the variable name in the given dictionary
// lookup in the dictionary
const entry* ePtr = dict.lookupEntryPtr(varName, true, true);
// if defined - copy its entries
if (ePtr != NULL)
if (ePtr)
{
OStringStream buf;
if (ePtr->isDict())
@ -248,7 +248,7 @@ Foam::string& Foam::stringOps::inplaceExpandDict
}
else
{
// not defined - leave untouched.
// not defined - leave original string untouched
begVar = endVar;
}
}
@ -267,24 +267,21 @@ Foam::string& Foam::stringOps::inplaceExpandDict
}
Foam::string Foam::stringOps::expandEnv
Foam::string Foam::stringOps::expand
(
const string& original,
const bool recurse,
const bool allowEmptyVar
const bool allowEmpty
)
{
string s(original);
return inplaceExpandEnv(s, recurse, allowEmptyVar);
return inplaceExpand(s, allowEmpty);
}
// Expand all occurences of environment variables and initial tilde sequences
Foam::string& Foam::stringOps::inplaceExpandEnv
Foam::string& Foam::stringOps::inplaceExpand
(
string& s,
const bool recurse,
const bool allowEmptyVar
const bool allowEmpty
)
{
string::size_type begVar = 0;
@ -325,20 +322,19 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
if (endVar != string::npos && endVar != begVar)
{
string varName = s.substr
const word varName
(
s.substr
(
begVar + 1 + delim,
endVar - begVar - 2*delim
),
false
);
string varValue = getEnv(varName);
const string varValue = getEnv(varName);
if (varValue.size())
{
if (recurse)
{
varValue.expand(recurse, allowEmptyVar);
}
s.std::string::replace
(
begVar,
@ -347,7 +343,7 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
);
begVar += varValue.size();
}
else if (allowEmptyVar)
else if (allowEmpty)
{
s.std::string::replace
(
@ -358,7 +354,10 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
}
else
{
FatalErrorIn("string::expand(const bool, const bool)")
FatalErrorIn
(
"stringOps::inplaceExpand(string&, const bool)"
)
<< "Unknown variable name " << varName << '.'
<< exit(FatalError);
}
@ -431,7 +430,7 @@ Foam::string Foam::stringOps::trimLeft(const string& s)
if (!s.empty())
{
string::size_type beg = 0;
while (isspace(s[beg]))
while (beg < s.size() && isspace(s[beg]))
{
++beg;
}
@ -451,7 +450,7 @@ Foam::string& Foam::stringOps::inplaceTrimLeft(string& s)
if (!s.empty())
{
string::size_type beg = 0;
while (isspace(s[beg]))
while (beg < s.size() && isspace(s[beg]))
{
++beg;
}
@ -517,4 +516,5 @@ Foam::string& Foam::stringOps::inplaceTrim(string& s)
return s;
}
// ************************************************************************* //

View File

@ -92,7 +92,7 @@ namespace stringOps
//
// \note the leading sigil can be changed to avoid conflicts with other
// string expansions
string expandDict
string expand
(
const string&,
const dictionary& dict,
@ -109,7 +109,7 @@ namespace stringOps
//
// \note the leading sigil can be changed to avoid conflicts with other
// string expansions
string& inplaceExpandDict
string& inplaceExpand
(
string&,
const dictionary& dict,
@ -128,14 +128,13 @@ namespace stringOps
// - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
//
// Any unknown entries are removed silently if allowEmptyVar is true
// Any unknown entries are removed silently if allowEmpty is true
// \sa
// Foam::findEtcFile
string expandEnv
string expand
(
const string&,
const bool recurse=false,
const bool allowEmptyVar = false
const bool allowEmpty = false
);
@ -150,14 +149,13 @@ namespace stringOps
// - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
//
// Any unknown entries are removed silently if allowEmptyVar is true
// Any unknown entries are removed silently if allowEmpty is true
// \sa
// Foam::findEtcFile
string& inplaceExpandEnv
string& inplaceExpand
(
string&,
const bool recurse=false,
const bool allowEmptyVar = false
const bool allowEmpty = false
);

View File

@ -96,7 +96,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
if (dict.found("codeInclude"))
{
codeInclude = stringOps::trim(dict["codeInclude"]);
stringOps::inplaceExpandDict(codeInclude, dict);
stringOps::inplaceExpand(codeInclude, dict);
}
// "codeOptions" is optional
@ -104,12 +104,12 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
if (dict.found("codeOptions"))
{
codeOptions = stringOps::trim(dict["codeOptions"]);
stringOps::inplaceExpandDict(codeOptions, dict);
stringOps::inplaceExpand(codeOptions, dict);
}
// "code" is mandatory
string code = stringOps::trim(dict["code"]);
stringOps::inplaceExpandDict(code, dict);
stringOps::inplaceExpand(code, dict);
// Create SHA1 digest from the contents