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
240 if (allowSubDict && eptr->isDict())
242 eptr->dict().write(buf,
false);
248 const auto& pe = dynamicCast<const primitiveEntry>(*eptr);
250 if (pe.size() == 1 && pe[0].isStringType())
253 str = pe[0].stringToken();
281 static inline bool validVariableChar(
char c)
297 const std::string&
s,
302 while (
pos != std::string::npos)
305 if (
pos != std::string::npos)
310 const int altType =
s[
pos+1];
311 if (altType ==
'+' || altType ==
'-')
321 pos = std::string::npos;
336 const std::string&
s,
338 const char sigil =
'$' 343 if (
pos <
s.length())
353 auto iter =
s.cbegin() +
pos;
354 iter !=
s.cend() && validVariableChar(*iter);
383 const bool allowEmpty,
384 const bool allowSubDict
394 const word lookupName =
409 else if (allowEnv || dictptr ==
nullptr)
414 if (value.empty() ? (altType ==
'-') : (altType ==
'+'))
418 value =
name.substr(altPos + 2);
421 if (!allowEmpty && value.empty())
423 if (dictptr !=
nullptr)
427 <<
"Cannot find dictionary entry ";
431 err <<
"or environment ";
434 err <<
"variable '" << lookupName <<
"'" <<
nl 440 <<
"Unknown variable '" << lookupName <<
"'" <<
nl 461 const std::string&
s,
465 const bool allowEmpty,
466 const bool allowSubDict
472 const bool isExpr = (index <
s.size() &&
s[index] ==
'{');
480 bool isVar = !isExpr;
484 for (; index <
s.size(); ++index)
489 if (
s[index+1] ==
'{')
510 if (
s[index-1] ==
'}')
515 else if (validVariableChar(
s[index+1]))
519 const auto varLen = findVariableLen(
s, index);
520 const word varName(
s.substr(index+1, varLen),
false);
541 else if (
s[index] ==
'}')
554 else if (dictptr !=
nullptr)
558 <<
"Expansion ${{ is missing a closing '}}'\n" 564 <<
"Expansion ${{ is missing a closing '}}'\n" 613 const dictionary* dictptr,
615 const bool allowEmpty,
616 const bool allowSubDict,
626 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
627 && varBeg <
s.size()-1
630 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
632 if (
s[varBeg+1] ==
'{')
635 const auto replaceBeg = varBeg;
651 s.replace(replaceBeg, varBeg - replaceBeg, varValue);
652 varBeg = replaceBeg+varValue.size();
654 else if (validVariableChar(
s[varBeg+1]))
657 const auto varLen(findVariableLen(
s, varBeg, sigil));
658 const word varName(
s.substr(varBeg+1, varLen),
false);
672 s.replace(varBeg, varName.size()+1, varValue);
673 varBeg += varValue.size();
696 const std::string&
s,
706 size_t len = (
s ? strlen(
s) : 0);
713 const std::string&
s,
737 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
738 && varBeg <
s.size()-1
741 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
749 auto altPos = std::string::npos;
751 if (
s[varBeg+1] ==
'{')
753 varEnd =
s.find(
'}', varBeg);
757 if (varEnd != std::string::npos)
765 varEnd += findVariableLen(
s, varBeg, sigil);
768 if (varEnd == std::string::npos)
773 else if (varEnd == varBeg)
786 (altPos == std::string::npos ? varEnd : altPos)
793 std::string altValue;
794 if (altPos != std::string::npos)
800 varEnd - altPos - 2*delim
805 const auto fnd = mapping.
cfind(varName);
807 if (fnd.found() ? (altType ==
'+') : (altType ==
'-'))
812 s.replace(varBeg, varEnd - varBeg + 1, altValue);
813 varBeg += altValue.size();
815 else if (fnd.found())
818 s.replace(varBeg, varEnd - varBeg + 1, *fnd);
819 varBeg += (*fnd).size();
824 s.erase(varBeg, varEnd - varBeg + 1);
838 const std::string&
s,
839 const dictionary&
dict,
854 const bool allowEmpty,
855 const bool allowSubDict,
878 const std::string&
s,
879 const bool allowEmpty
891 const bool allowEmpty
902 if (
s.empty() || varName.empty())
913 const auto i =
s.find(content);
914 if (i == std::string::npos)
919 s.replace(i, content.size(),
string(
"${" + varName +
"}"));
929 const auto end =
s.length();
938 return s.substr(
pos);
951 const auto end =
s.length();
970 auto end =
s.length();
976 if (
end <
s.length())
978 return s.substr(0,
end);
990 auto end =
s.length();
1001 std::pair<std::size_t, std::size_t>
1004 const std::string&
s,
1009 size_t end =
s.length();
1014 else if (len != std::string::npos)
1036 return std::pair<std::size_t, std::size_t>(
pos,
end);
1070 s.erase(std::remove_if(
s.begin(),
s.end(),
::isspace),
s.end());
1084 const auto len =
s.length();
1138 i =
s.find(
'\n', ++i);
1140 if (i == std::string::npos)
1152 i =
s.find(
"*/", ++i, 2);
1154 if (i == std::string::npos)
1181 out.resize(
s.length());
1197 out.resize(
s.length());
1213 const std::string& str,
1224 const auto len = str.size();
1230 if (escape &&
c ==
'\\')
1238 if (len &&
c !=
'\n')
1248 std::size_t
pos = 0;
1249 const auto len = str.size();
1252 while (
pos < len && str[
pos] ==
'\n')
1265 if (std::string::npos != breakp && breakp < endp)
1275 && (str[endp-1] ==
' ' || str[endp-1] ==
'\t')
1281 else if (endp >= len)
1291 breakp = nextp = endp;
1295 bool foundBreak =
false;
1296 while (breakp >
pos)
1300 const char c = str[breakp];
1302 if (
c ==
' ' ||
c ==
'\t')
1309 else if (foundBreak)
1322 if (punc == std::string::npos)
1327 case '(' :
case '<' :
1333 case ')' :
case '>' :
1334 case ',' :
case '.' :
1335 case ':' :
case ';' :
1336 case '/' :
case '|' :
1338 punc = (breakp + 1);
1351 if (punc != std::string::npos)
1353 nextp = endp = punc;
1380 const char c = str[
pos];
1382 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.
static unsigned int defaultPrecision() noexcept
Return the default precision.
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.
IOstream & fixed(IOstream &io)
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 ...