mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: simplify stringOps::expand names
This commit is contained in:
@ -84,7 +84,7 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get code dictionary
|
// 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);
|
dictionary codeDict("#codeStream", parentDict, is);
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
if (codeDict.found("codeInclude"))
|
if (codeDict.found("codeInclude"))
|
||||||
{
|
{
|
||||||
codeInclude = stringOps::trim(codeDict["codeInclude"]);
|
codeInclude = stringOps::trim(codeDict["codeInclude"]);
|
||||||
stringOps::inplaceExpandDict(codeInclude, codeDict);
|
stringOps::inplaceExpand(codeInclude, codeDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "codeOptions" is optional
|
// "codeOptions" is optional
|
||||||
@ -105,12 +105,12 @@ bool Foam::functionEntries::codeStream::execute
|
|||||||
if (codeDict.found("codeOptions"))
|
if (codeDict.found("codeOptions"))
|
||||||
{
|
{
|
||||||
codeOptions = stringOps::trim(codeDict["codeOptions"]);
|
codeOptions = stringOps::trim(codeDict["codeOptions"]);
|
||||||
stringOps::inplaceExpandDict(codeOptions, codeDict);
|
stringOps::inplaceExpand(codeOptions, codeDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "code" is mandatory
|
// "code" is mandatory
|
||||||
string code = stringOps::trim(codeDict["code"]);
|
string code = stringOps::trim(codeDict["code"]);
|
||||||
stringOps::inplaceExpandDict(code, codeDict);
|
stringOps::inplaceExpand(code, codeDict);
|
||||||
|
|
||||||
|
|
||||||
// Create SHA1 digest from the contents
|
// Create SHA1 digest from the contents
|
||||||
|
|||||||
@ -51,28 +51,25 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
|
|||||||
|
|
||||||
Foam::fileName Foam::codeStreamTools::baseDir()
|
Foam::fileName Foam::codeStreamTools::baseDir()
|
||||||
{
|
{
|
||||||
return stringOps::expandEnv("$FOAM_CASE/codeStream");
|
return stringOps::expand("$FOAM_CASE/codeStream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName Foam::codeStreamTools::libSubDir()
|
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)
|
Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName)
|
||||||
{
|
{
|
||||||
return stringOps::expandEnv
|
return stringOps::expand("$FOAM_CASE/codeStream/" + subDirName);
|
||||||
(
|
|
||||||
"$FOAM_CASE/codeStream/" + subDirName
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName Foam::codeStreamTools::libPath(const word& codeName)
|
Foam::fileName Foam::codeStreamTools::libPath(const word& codeName)
|
||||||
{
|
{
|
||||||
return stringOps::expandEnv
|
return stringOps::expand
|
||||||
(
|
(
|
||||||
"$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib"
|
"$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib"
|
||||||
+ codeName + ".so"
|
+ codeName + ".so"
|
||||||
|
|||||||
@ -143,7 +143,7 @@ Foam::string& Foam::stringOps::inplaceExpand
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::string Foam::stringOps::expandDict
|
Foam::string Foam::stringOps::expand
|
||||||
(
|
(
|
||||||
const string& original,
|
const string& original,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
@ -151,11 +151,11 @@ Foam::string Foam::stringOps::expandDict
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
string s(original);
|
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,
|
string& s,
|
||||||
const dictionary& dict,
|
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);
|
const entry* ePtr = dict.lookupEntryPtr(varName, true, true);
|
||||||
|
|
||||||
// if defined - copy its entries
|
// if defined - copy its entries
|
||||||
if (ePtr != NULL)
|
if (ePtr)
|
||||||
{
|
{
|
||||||
OStringStream buf;
|
OStringStream buf;
|
||||||
if (ePtr->isDict())
|
if (ePtr->isDict())
|
||||||
@ -248,7 +248,7 @@ Foam::string& Foam::stringOps::inplaceExpandDict
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// not defined - leave untouched.
|
// not defined - leave original string untouched
|
||||||
begVar = endVar;
|
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 string& original,
|
||||||
const bool recurse,
|
const bool allowEmpty
|
||||||
const bool allowEmptyVar
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
string s(original);
|
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::inplaceExpand
|
||||||
Foam::string& Foam::stringOps::inplaceExpandEnv
|
|
||||||
(
|
(
|
||||||
string& s,
|
string& s,
|
||||||
const bool recurse,
|
const bool allowEmpty
|
||||||
const bool allowEmptyVar
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
string::size_type begVar = 0;
|
string::size_type begVar = 0;
|
||||||
@ -325,20 +322,19 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
|
|||||||
|
|
||||||
if (endVar != string::npos && endVar != begVar)
|
if (endVar != string::npos && endVar != begVar)
|
||||||
{
|
{
|
||||||
string varName = s.substr
|
const word varName
|
||||||
(
|
(
|
||||||
begVar + 1 + delim,
|
s.substr
|
||||||
endVar - begVar - 2*delim
|
(
|
||||||
|
begVar + 1 + delim,
|
||||||
|
endVar - begVar - 2*delim
|
||||||
|
),
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
string varValue = getEnv(varName);
|
const string varValue = getEnv(varName);
|
||||||
|
|
||||||
if (varValue.size())
|
if (varValue.size())
|
||||||
{
|
{
|
||||||
if (recurse)
|
|
||||||
{
|
|
||||||
varValue.expand(recurse, allowEmptyVar);
|
|
||||||
}
|
|
||||||
s.std::string::replace
|
s.std::string::replace
|
||||||
(
|
(
|
||||||
begVar,
|
begVar,
|
||||||
@ -347,7 +343,7 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
|
|||||||
);
|
);
|
||||||
begVar += varValue.size();
|
begVar += varValue.size();
|
||||||
}
|
}
|
||||||
else if (allowEmptyVar)
|
else if (allowEmpty)
|
||||||
{
|
{
|
||||||
s.std::string::replace
|
s.std::string::replace
|
||||||
(
|
(
|
||||||
@ -358,7 +354,10 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalErrorIn("string::expand(const bool, const bool)")
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"stringOps::inplaceExpand(string&, const bool)"
|
||||||
|
)
|
||||||
<< "Unknown variable name " << varName << '.'
|
<< "Unknown variable name " << varName << '.'
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
@ -431,7 +430,7 @@ Foam::string Foam::stringOps::trimLeft(const string& s)
|
|||||||
if (!s.empty())
|
if (!s.empty())
|
||||||
{
|
{
|
||||||
string::size_type beg = 0;
|
string::size_type beg = 0;
|
||||||
while (isspace(s[beg]))
|
while (beg < s.size() && isspace(s[beg]))
|
||||||
{
|
{
|
||||||
++beg;
|
++beg;
|
||||||
}
|
}
|
||||||
@ -451,7 +450,7 @@ Foam::string& Foam::stringOps::inplaceTrimLeft(string& s)
|
|||||||
if (!s.empty())
|
if (!s.empty())
|
||||||
{
|
{
|
||||||
string::size_type beg = 0;
|
string::size_type beg = 0;
|
||||||
while (isspace(s[beg]))
|
while (beg < s.size() && isspace(s[beg]))
|
||||||
{
|
{
|
||||||
++beg;
|
++beg;
|
||||||
}
|
}
|
||||||
@ -517,4 +516,5 @@ Foam::string& Foam::stringOps::inplaceTrim(string& s)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -92,7 +92,7 @@ namespace stringOps
|
|||||||
//
|
//
|
||||||
// \note the leading sigil can be changed to avoid conflicts with other
|
// \note the leading sigil can be changed to avoid conflicts with other
|
||||||
// string expansions
|
// string expansions
|
||||||
string expandDict
|
string expand
|
||||||
(
|
(
|
||||||
const string&,
|
const string&,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
@ -109,7 +109,7 @@ namespace stringOps
|
|||||||
//
|
//
|
||||||
// \note the leading sigil can be changed to avoid conflicts with other
|
// \note the leading sigil can be changed to avoid conflicts with other
|
||||||
// string expansions
|
// string expansions
|
||||||
string& inplaceExpandDict
|
string& inplaceExpand
|
||||||
(
|
(
|
||||||
string&,
|
string&,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
@ -128,14 +128,13 @@ namespace stringOps
|
|||||||
// - leading "~user" : home directory for specified user
|
// - leading "~user" : home directory for specified user
|
||||||
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
|
// - 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
|
// \sa
|
||||||
// Foam::findEtcFile
|
// Foam::findEtcFile
|
||||||
string expandEnv
|
string expand
|
||||||
(
|
(
|
||||||
const string&,
|
const string&,
|
||||||
const bool recurse=false,
|
const bool allowEmpty = false
|
||||||
const bool allowEmptyVar = false
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -150,14 +149,13 @@ namespace stringOps
|
|||||||
// - leading "~user" : home directory for specified user
|
// - leading "~user" : home directory for specified user
|
||||||
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
|
// - 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
|
// \sa
|
||||||
// Foam::findEtcFile
|
// Foam::findEtcFile
|
||||||
string& inplaceExpandEnv
|
string& inplaceExpand
|
||||||
(
|
(
|
||||||
string&,
|
string&,
|
||||||
const bool recurse=false,
|
const bool allowEmpty = false
|
||||||
const bool allowEmptyVar = false
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -96,7 +96,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
|||||||
if (dict.found("codeInclude"))
|
if (dict.found("codeInclude"))
|
||||||
{
|
{
|
||||||
codeInclude = stringOps::trim(dict["codeInclude"]);
|
codeInclude = stringOps::trim(dict["codeInclude"]);
|
||||||
stringOps::inplaceExpandDict(codeInclude, dict);
|
stringOps::inplaceExpand(codeInclude, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "codeOptions" is optional
|
// "codeOptions" is optional
|
||||||
@ -104,12 +104,12 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
|||||||
if (dict.found("codeOptions"))
|
if (dict.found("codeOptions"))
|
||||||
{
|
{
|
||||||
codeOptions = stringOps::trim(dict["codeOptions"]);
|
codeOptions = stringOps::trim(dict["codeOptions"]);
|
||||||
stringOps::inplaceExpandDict(codeOptions, dict);
|
stringOps::inplaceExpand(codeOptions, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "code" is mandatory
|
// "code" is mandatory
|
||||||
string code = stringOps::trim(dict["code"]);
|
string code = stringOps::trim(dict["code"]);
|
||||||
stringOps::inplaceExpandDict(code, dict);
|
stringOps::inplaceExpand(code, dict);
|
||||||
|
|
||||||
|
|
||||||
// Create SHA1 digest from the contents
|
// Create SHA1 digest from the contents
|
||||||
|
|||||||
Reference in New Issue
Block a user