52 const std::string&
mode,
56 unsigned short where(0);
58 if (std::string::npos !=
mode.find(
'u',
pos)) { where |= 0700; }
59 if (std::string::npos !=
mode.find(
'g',
pos)) { where |= 0070; }
60 if (std::string::npos !=
mode.find(
'o',
pos)) { where |= 0007; }
61 if (std::string::npos !=
mode.find(
'a',
pos)) { where |= 0777; }
82 auto delim =
s.find(
e);
83 if (std::string::npos == delim)
90 const char nextC =
s[++delim];
100 file.
assign(
s.substr(delim + 1));
103 const std::string tag(
s, 1, delim-2);
104 const auto tagLen = tag.length();
112 else if (tag ==
"case")
116 else if (tag ==
"constant" || tag ==
"system")
120 else if (tagLen >= 4 && tag.compare(0, 4,
"etc:") == 0)
143 const auto slash =
s.find(
'/');
144 if (slash == std::string::npos)
150 user =
s.substr(1, slash - 1);
151 file =
s.substr(slash + 1);
158 if (user ==
"OpenFOAM")
167 <<
"--> FOAM Warning :" <<
nl 168 <<
" Found [v" <<
version <<
"] '" 169 <<
"~OpenFOAM" <<
"' string expansion instead of '" 170 <<
"<etc>" <<
"' in string\n\"" <<
s <<
"\"\n" <<
nl 202 else if (
s[1] ==
'/')
204 s.replace(0, 1,
cwd());
227 const bool allowSubDict
246 eptr->dict().write(buf,
false);
257 ITstream& its = eptr->stream();
258 return its.toString();
280 static inline bool validVariableChar(
char c)
296 const std::string&
s,
301 while (
pos != std::string::npos)
304 if (
pos != std::string::npos)
309 const int altType =
s[
pos+1];
310 if (altType ==
'+' || altType ==
'-')
320 pos = std::string::npos;
335 const std::string&
s,
337 const char sigil =
'$' 342 if (
pos <
s.length())
352 auto iter =
s.cbegin() +
pos;
353 iter !=
s.cend() && validVariableChar(*iter);
382 const bool allowEmpty,
383 const bool allowSubDict
393 const word lookupName =
408 else if (allowEnv || dictptr ==
nullptr)
413 if (value.empty() ? (altType ==
'-') : (altType ==
'+'))
417 value =
name.substr(altPos + 2);
420 if (!allowEmpty && value.empty())
422 if (dictptr !=
nullptr)
426 <<
"Cannot find dictionary entry ";
430 err <<
"or environment ";
433 err <<
"variable '" << lookupName <<
"'" <<
nl 439 <<
"Unknown variable '" << lookupName <<
"'" <<
nl 460 const std::string&
s,
464 const bool allowEmpty,
465 const bool allowSubDict
471 const bool isExpr = (index <
s.size() &&
s[index] ==
'{');
479 bool isVar = !isExpr;
483 for (; index <
s.size(); ++index)
488 if (
s[index+1] ==
'{')
509 if (
s[index-1] ==
'}')
514 else if (validVariableChar(
s[index+1]))
518 const auto varLen = findVariableLen(
s, index);
519 const word varName(
s.substr(index+1, varLen),
false);
540 else if (
s[index] ==
'}')
553 else if (dictptr !=
nullptr)
557 <<
"Expansion ${{ is missing a closing '}}'\n" 563 <<
"Expansion ${{ is missing a closing '}}'\n" 612 const dictionary* dictptr,
614 const bool allowEmpty,
615 const bool allowSubDict,
625 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
626 && varBeg <
s.size()-1
629 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
631 if (
s[varBeg+1] ==
'{')
634 const auto replaceBeg = varBeg;
650 s.replace(replaceBeg, varBeg - replaceBeg, varValue);
651 varBeg = replaceBeg+varValue.size();
653 else if (validVariableChar(
s[varBeg+1]))
656 const auto varLen(findVariableLen(
s, varBeg, sigil));
657 const word varName(
s.substr(varBeg+1, varLen),
false);
671 s.replace(varBeg, varName.size()+1, varValue);
672 varBeg += varValue.size();
695 const std::string&
s,
705 size_t len = (
s ? strlen(
s) : 0);
712 const std::string&
s,
736 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
737 && varBeg <
s.size()-1
740 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
748 auto altPos = std::string::npos;
750 if (
s[varBeg+1] ==
'{')
752 varEnd =
s.find(
'}', varBeg);
756 if (varEnd != std::string::npos)
764 varEnd += findVariableLen(
s, varBeg, sigil);
767 if (varEnd == std::string::npos)
772 else if (varEnd == varBeg)
785 (altPos == std::string::npos ? varEnd : altPos)
792 std::string altValue;
793 if (altPos != std::string::npos)
799 varEnd - altPos - 2*delim
804 const auto fnd = mapping.
cfind(varName);
806 if (fnd.good() ? (altType ==
'+') : (altType ==
'-'))
811 s.replace(varBeg, varEnd - varBeg + 1, altValue);
812 varBeg += altValue.size();
817 s.replace(varBeg, varEnd - varBeg + 1, *fnd);
818 varBeg += (*fnd).size();
823 s.erase(varBeg, varEnd - varBeg + 1);
837 const std::string&
s,
838 const dictionary&
dict,
853 const bool allowEmpty,
854 const bool allowSubDict,
877 const std::string&
s,
878 const bool allowEmpty
890 const bool allowEmpty
901 if (
s.empty() || varName.empty())
912 const auto i =
s.find(content);
913 if (i == std::string::npos)
918 s.replace(i, content.size(),
string(
"${" + varName +
"}"));
928 const auto end =
s.length();
937 return s.substr(
pos);
950 const auto end =
s.length();
969 auto end =
s.length();
975 if (
end <
s.length())
977 return s.substr(0,
end);
989 auto end =
s.length();
1000 std::pair<std::size_t, std::size_t>
1003 const std::string&
s,
1008 size_t end =
s.length();
1013 else if (len != std::string::npos)
1035 return std::pair<std::size_t, std::size_t>(
pos,
end);
1069 s.erase(std::remove_if(
s.begin(),
s.end(),
::isspace),
s.end());
1083 const auto len =
s.length();
1137 i =
s.find(
'\n', ++i);
1139 if (i == std::string::npos)
1151 i =
s.find(
"*/", ++i, 2);
1153 if (i == std::string::npos)
1180 out.resize(
s.length());
1196 out.resize(
s.length());
1212 const std::string& str,
1223 const auto len = str.size();
1229 if (escape &&
c ==
'\\')
1237 if (len &&
c !=
'\n')
1247 std::size_t
pos = 0;
1248 const auto len = str.size();
1251 while (
pos < len && str[
pos] ==
'\n')
1264 if (std::string::npos != breakp && breakp < endp)
1274 && (str[endp-1] ==
' ' || str[endp-1] ==
'\t')
1280 else if (endp >= len)
1290 breakp = nextp = endp;
1294 bool foundBreak =
false;
1295 while (breakp >
pos)
1299 const char c = str[breakp];
1301 if (
c ==
' ' ||
c ==
'\t')
1308 else if (foundBreak)
1321 if (punc == std::string::npos)
1326 case '(' :
case '<' :
1332 case ')' :
case '>' :
1333 case ',' :
case '.' :
1334 case ':' :
case ';' :
1335 case '/' :
case '|' :
1337 punc = (breakp + 1);
1350 if (punc != std::string::npos)
1352 nextp = endp = punc;
1379 const char c = str[
pos];
1381 if (escape &&
c ==
'\\')
void inplaceUpper(std::string &s)
Inplace transform string with std::toupper on each character.
static std::string entryToString(const entry *eptr, const bool allowSubDict)
Generic output stream using a standard (STL) stream.
A class for handling file names.
Ostream & indent(Ostream &os)
Indent stream.
string trimLeft(const std::string &s)
Return string trimmed of leading whitespace.
bool inplaceReplaceVar(std::string &s, const word &varName)
Replace environment variable contents with its name.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static char findParameterAlternative(const std::string &s, std::string::size_type &pos, std::string::size_type endPos=std::string::npos)
static unsigned short modeToLocation(const std::string &mode, std::size_t pos=0)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Input/output from string buffers.
std::pair< size_t, size_t > findTrim(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Find (first, last) non-space locations in string or sub-string.
constexpr char nl
The newline '\n' character (0x0a)
void inplaceRemoveSpace(std::string &s)
Eliminate whitespace inplace.
void inplaceTrim(std::string &s)
Trim leading and trailing whitespace inplace.
Ostream & endl(Ostream &os)
Add newline and flush stream.
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
string getEnv(const std::string &envName)
Get environment value for given envName.
fileName home()
Return home directory path name for the current user.
static void expandLeading(std::string &s)
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
static bool warnAboutAge(const int version) noexcept
Test if an age warning should be emitted.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
dimensionedScalar pos(const dimensionedScalar &ds)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
void inplaceTrimRight(std::string &s)
Trim trailing whitespace inplace.
bool assign(const token &tok)
Assign from word or string token.
const dimensionedScalar e
Elementary charge.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
static bool master(const label communicator=-1)
Like Pstream::master but with a Pstream::parRun guard in case Pstream has not yet been initialised...
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
A class for handling words, derived from Foam::string.
Functions to search 'etc' directories for configuration files etc.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
string trimRight(const std::string &s)
Return string trimmed of trailing whitespace.
void inplaceTrimLeft(std::string &s)
Trim leading whitespace inplace.
string trim(const std::string &s)
Return string trimmed of leading and trailing whitespace.
A HashTable similar to std::unordered_map.
graph_traits< Graph >::vertices_size_type size_type
void inplaceRemoveComments(std::string &s)
Remove C/C++ comments inplace.
void inplaceExpand(std::string &s, const HashTable< string > &mapping, const char sigil='$')
Inplace expand occurrences of variables according to the mapping. Does not use environment values...
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
OBJstream os(runTime.globalPath()/outputName)
static Foam::string recursiveExpand(const std::string &s, std::string::size_type &index, const dictionary *dictptr, const bool allowEnv, const bool allowEmpty, const bool allowSubDict)
fileName findEtcEntry(const fileName &name, unsigned short location=0777, const fileName::Type typeRequired=fileName::Type::UNDEFINED)
Search for a single FILE or DIRECTORY within the etc directories.
static Foam::string getVariable(const word &name, const dictionary *dictptr, const bool allowEnv, const bool allowEmpty, const bool allowSubDict)
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
void writeWrapped(OSstream &os, const std::string &str, const std::string::size_type width, const std::string::size_type indent=0, const bool escape=false)
Output string with text wrapping.
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
void inplaceLower(std::string &s)
Inplace transform string with std::tolower on each character.
static void expandLeadingTilde(std::string &s)
const dimensionedScalar c
Speed of light in a vacuum.
bool isspace(char c) noexcept
Test for whitespace (C-locale)
std::string::size_type count(const std::string &s, const char c)
Count the number of occurrences of the specified character.
fileName cwd()
The physical or logical current working directory path name.
static void expandString(std::string &s, const dictionary *dictptr, const bool allowEnv, const bool allowEmpty, const bool allowSubDict, const char sigil)
string removeComments(const std::string &s)
Return string with C/C++ comments removed.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static void expandLeadingTag(std::string &s, const char b, const char e)
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
A class for handling character strings derived from std::string.
A keyword and a list of tokens is an 'entry'.
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Expand occurrences of variables according to the mapping and return the expanded string.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...