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
520 dynamicCast<const primitiveEntry>(*ePtr);
525 const token& t = pe[0];
544 if (!dictVar.empty())
546 if (!varType.empty())
555 <<
".lookupScoped<" << varType <<
">"
556 <<
"(\"" << varName <<
"\", true, false)";
564 <<
"Type not specified for variable "
565 << varName <<
" in code string " <<
nl
567 <<
"Variable " << varName <<
" expands to "
576 dynamicCast<const primitiveEntry>(*ePtr)
585 if (!varType.empty())
590 buf <<
"read<" << varType <<
">(\"";
600 buf.
precision(IOstream::defaultPrecision());
610 dynamicCast<const primitiveEntry>(*ePtr)
614 if (!varType.empty())
621 s.std::string::replace
627 begVar += buf.
str().size();
659 (begVar =
s.find(sigil, begVar)) != string::npos
660 && begVar <
s.size() - 1
663 if (begVar == 0 ||
s[begVar - 1] !=
'\\')
669 if (
s[begVar + 1] ==
'{')
671 endVar =
s.findClosing(
'}', begVar + 1);
676 string::iterator iter =
s.begin() + begVar + 1;
698 if (endVar == string::npos)
703 else if (endVar == begVar)
715 endVar - begVar - 2*delim
722 mapping.
find(varName);
727 s.std::string::replace
733 begVar += (*fnd).size();
738 s.std::string::erase(begVar, endVar - begVar + 1);
756 const bool allowEnvVars,
757 const bool allowEmpty,
767 (begVar =
s.find(sigil, begVar)) != string::npos
768 && begVar <
s.size() - 1
771 if (begVar == 0 ||
s[begVar - 1] !=
'\\')
773 if (
s[begVar + 1] ==
'{')
776 label stringStart = begVar;
790 s.std::string::replace
793 begVar - stringStart + 1,
797 begVar = stringStart+varValue.size();
801 string::iterator iter =
s.begin() + begVar + 1;
844 s.std::string::replace
850 begVar += varValue.size();
868 while (beg <
s.size() &&
isspace(
s[beg]))
875 return s.substr(beg);
888 while (beg <
s.size() &&
isspace(
s[beg]))
915 return s.substr(0, sz);
957 const string& message,
962 const string indent(nIndent, token::SPACE);
970 message.find_first_of(token::NL, i1);
972 message.find_first_of(token::SPACE, i1);
977 iNewLine != string::npos
978 && (iSpace == string::npos || iNewLine < iSpace)
981 result +=
indent + message.substr(i0, iNewLine - i0) +
'\n';
982 i0 = i1 = iNewLine + 1;
986 else if (iSpace != string::npos)
988 if (iSpace - i0 > nLength - nIndent)
990 result +=
indent + message.substr(i0, i1 - i0) +
'\n';
1002 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 token holds items read from Istream.
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)