45 while (
pos != std::string::npos)
48 if (
pos != std::string::npos)
53 const int altType =
s[
pos + 1];
54 if (altType ==
'+' || altType ==
'-')
64 pos = std::string::npos;
78 const bool allowEnvVars,
95 dynamicCast<const primitiveEntry>(*ePtr).write(buf,
true);
99 else if (allowEnvVars)
101 string::const_iterator iter =
name.begin();
107 while (iter !=
name.end() && (isalnum(*iter) || *iter ==
'_'))
113 const word varName(
name.substr(begVar, endVar - begVar),
false);
115 string varValue =
getEnv(varName);
117 if (!allowEmpty && varValue.empty())
122 ) <<
"Cannot find dictionary or environment variable "
126 varValue +=
name.substr(endVar,
name.size() - endVar);
135 ) <<
"Cannot find dictionary variable "
150 const bool allowEnvVars,
151 const bool allowEmpty
156 while (index <
s.size())
158 if (
s[index] ==
'$' &&
s[index + 1] ==
'{')
162 string val =
expand(
s, index,
dict, allowEnvVars, allowEmpty);
163 newString.append(val);
165 else if (
s[index] ==
'}')
171 newString.append(
string(
s[index]));
195 if (
pos != string::npos)
197 user =
s.substr(1,
pos - 1);
208 if (user ==
"OpenFOAM")
217 else if (
s[0] ==
'.')
224 else if (
s[1] ==
'/')
226 s.std::string::replace(0, 1,
cwd());
242 const string& original,
243 const bool allowEmpty
254 const bool allowEmpty
263 (begVar =
s.find(
'$', begVar)) != string::npos
264 && begVar <
s.size() - 1
267 if (begVar == 0 ||
s[begVar - 1] !=
'\\')
277 if (
s[begVar + 1] ==
'{')
279 endVar =
s.find(
'}', begVar);
283 if (endVar != string::npos)
291 string::iterator iter =
s.begin() + begVar + 1;
296 && (isalnum(*iter) || *iter ==
'_')
304 if (endVar == string::npos)
309 else if (endVar == begVar)
322 (altPos == string::npos ? endVar : altPos)
329 std::string altValue;
330 if (altPos != string::npos)
336 endVar - altPos - 2*delim
340 const string varValue =
getEnv(varName);
343 if (altPos != string::npos && altType ==
'+')
346 s.std::string::replace
352 begVar += altValue.size();
357 s.std::string::replace
363 begVar += varValue.size();
366 else if (altPos != string::npos)
372 s.std::string::replace
378 begVar += altValue.size();
384 s.std::string::erase(begVar, endVar - begVar + 1);
389 s.std::string::erase(begVar, endVar - begVar + 1);
394 <<
"Unknown variable name '" << varName <<
"'"
423 (begVar =
s.find(sigil, begVar)) != string::npos
424 && begVar <
s.size() - 1
427 if (begVar == 0 ||
s[begVar - 1] !=
'\\')
435 if (
s[begVar + 1] ==
'<')
437 begDelim +=
s.findClosing(
'>', begVar + 1) - begVar;
438 varType =
s.substr(begVar + 2, begDelim - 2);
442 if (
s[begVar+begDelim + 1] ==
'{')
445 endVar =
s.findClosing(
'}', begVar+begDelim + 1);
451 endVar = begVar + begDelim;
453 string::iterator iter =
s.begin() + begVar + begDelim + 1;
475 if (endVar == string::npos)
480 else if (endVar == begVar)
491 begVar + begDelim + 1,
492 (endVar - endDelim) - (begVar + begDelim)
501 const entry* ePtr =
dict.lookupScopedEntryPtr
512 bool compound =
false;
519 dynamicCast<const primitiveEntry>(*ePtr);
528 varType = pe[0].typeName();
533 compound = pe[0].isCompound();
537 if (!dictVar.empty())
539 if (!varType.empty())
554 <<
".lookupCompoundScoped<"
556 <<
"(\"" << varName <<
"\", true, false)";
561 <<
".lookupScoped<" << varType <<
">"
562 <<
"(\"" << varName <<
"\", true, false)";
571 <<
"Type not specified for variable "
572 << varName <<
" in code string " <<
nl
574 <<
"Variable " << varName <<
" expands to "
583 dynamicCast<const primitiveEntry>(*ePtr)
592 if (!varType.empty())
597 buf <<
"Foam::read<" << varType <<
">(\"";
607 buf.
precision(IOstream::defaultPrecision());
617 dynamicCast<const primitiveEntry>(*ePtr)
621 if (!varType.empty())
628 s.std::string::replace
634 begVar += buf.
str().size();
666 (begVar =
s.find(sigil, begVar)) != string::npos
667 && begVar <
s.size() - 1
670 if (begVar == 0 ||
s[begVar - 1] !=
'\\')
676 if (
s[begVar + 1] ==
'{')
678 endVar =
s.findClosing(
'}', begVar + 1);
683 string::iterator iter =
s.begin() + begVar + 1;
705 if (endVar == string::npos)
710 else if (endVar == begVar)
722 endVar - begVar - 2*delim
729 mapping.
find(varName);
734 s.std::string::replace
740 begVar += (*fnd).size();
745 s.std::string::erase(begVar, endVar - begVar + 1);
763 const bool allowEnvVars,
764 const bool allowEmpty,
774 (begVar =
s.find(sigil, begVar)) != string::npos
775 && begVar <
s.size() - 1
778 if (begVar == 0 ||
s[begVar - 1] !=
'\\')
780 if (
s[begVar + 1] ==
'{')
783 label stringStart = begVar;
797 s.std::string::replace
800 begVar - stringStart + 1,
804 begVar = stringStart+varValue.size();
808 string::iterator iter =
s.begin() + begVar + 1;
851 s.std::string::replace
857 begVar += varValue.size();
875 while (beg <
s.size() &&
isspace(
s[beg]))
882 return s.substr(beg);
895 while (beg <
s.size() &&
isspace(
s[beg]))
922 return s.substr(0, sz);
964 const string& message,
969 const string indent(nIndent, token::SPACE);
977 message.find_first_of(token::NL, i1);
979 message.find_first_of(token::SPACE, i1);
984 iNewLine != string::npos
985 && (iSpace == string::npos || iNewLine < iSpace)
988 result +=
indent + message.substr(i0, iNewLine - i0) +
'\n';
989 i0 = i1 = iNewLine + 1;
993 else if (iSpace != string::npos)
995 if (iSpace - i0 > nLength - nIndent)
997 result +=
indent + message.substr(i0, i1 - i0) +
'\n';
1009 result +=
indent + message.substr(i0);
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
graph_traits< Graph >::vertices_size_type size_type
An STL-conforming const_iterator.
An STL-conforming hash table.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
static unsigned int defaultPrecision()
Return the default precision.
void size(const label)
Override size to be inconsistent with allocated storage.
virtual int precision() const
Get precision of output field.
Output to memory buffer stream.
string str() const
Return the string.
A list of keyword definitions, which are a keyword followed by any number of values (e....
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present,.
A keyword and a list of tokens is an 'entry'.
virtual bool isDict() const
Return true if this entry is a dictionary.
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
A class for handling file names.
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
A class for handling character strings derived from std::string.
static const string null
An empty string.
A class for handling words, derived from string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Functions to search 'etc' directories for configuration files etc.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
string & inplaceExpandCodeString(string &, const dictionary &dict, const word &dictVar="dict", const char sigil='$')
Inplace expand occurrences of variables according to the dictionary.
string & inplaceTrimRight(string &)
Trim trailing whitespace inplace.
string trim(const string &)
Return string trimmed of leading and trailing whitespace.
string & inplaceExpandCodeTemplate(string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Inplace expand occurrences of variables according to the mapping.
string & inplaceExpandEnvVar(string &, const bool allowEmpty=false)
Expand all occurrences of environment variables and paths.
string expandEnvVar(const string &, const bool allowEmpty=false)
Expand all occurrences of environment variables and paths.
string & inplaceExpandEntry(string &s, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty, const char sigil='$')
Inplace expand occurrences of variables according to the dictionary.
string trimRight(const string &)
Return string trimmed of trailing whitespace.
string breakIntoIndentedLines(const string &str, const string::size_type nLength=80, const string::size_type nIndent=0)
Break a string up into indented lines.
string trimLeft(const string &)
Return string trimmed of leading whitespace.
string & inplaceTrim(string &)
Trim leading and trailing whitespace inplace.
string & inplaceTrimLeft(string &)
Trim leading whitespace inplace.
errorManipArg< error, int > exit(error &err, const int errNo=1)
fileName cwd()
Return current working directory path name.
dimensionedScalar pos(const dimensionedScalar &ds)
Foam::string & inplaceExpandPath(string &s)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
word name(const bool)
Return a word representation of a bool.
fileName findEtcFile(const fileName &, bool mandatory=false)
Search for a file using findEtcFiles.
static int findParameterAlternative(const string &s, string::size_type &pos, string::size_type endPos)
IOstream & scientific(IOstream &io)
string getEnv(const word &)
Return environment variable of given name.
string getVariable(const word &name, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty)
Ostream & indent(Ostream &os)
Indent stream.
fileName home()
Return home directory path name for the current user.
string expand(const string &s, string::size_type &index, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty)