Go to the documentation of this file.
53 const std::string&
mode,
57 unsigned short where(0);
59 if (std::string::npos !=
mode.find(
'u',
pos)) { where |= 0700; }
60 if (std::string::npos !=
mode.find(
'g',
pos)) { where |= 0070; }
61 if (std::string::npos !=
mode.find(
'o',
pos)) { where |= 0007; }
62 if (std::string::npos !=
mode.find(
'a',
pos)) { where |= 0777; }
83 auto delim =
s.find(
e);
84 if (std::string::npos == delim)
91 const char nextC =
s[++delim];
101 file.assign(
s.substr(delim + 1));
104 const std::string tag(
s, 1, delim-2);
105 const auto tagLen = tag.length();
113 else if (tag ==
"case")
117 else if (tag ==
"constant" || tag ==
"system")
121 else if (tagLen >= 4 && tag.compare(0, 4,
"etc:") == 0)
144 const auto slash =
s.find(
'/');
145 if (slash == std::string::npos)
151 user =
s.substr(1, slash - 1);
152 file =
s.substr(slash + 1);
159 if (user ==
"OpenFOAM")
170 <<
"--> FOAM Warning :" <<
nl
171 <<
" Found [v" <<
version <<
"] '"
172 <<
"~OpenFOAM" <<
"' string expansion instead of '"
173 <<
"<etc>" <<
"' in string\n\"" <<
s <<
"\"\n" <<
nl
205 else if (
s[1] ==
'/')
207 s.replace(0, 1,
cwd());
230 const bool allowSubDict
243 if (allowSubDict && eptr->
isDict())
252 dynamicCast<const primitiveEntry>(*eptr);
254 if (pe.size() == 1 && pe[0].isStringType())
257 str = pe[0].stringToken();
285 static inline bool validVariableChar(
char c)
301 const std::string&
s,
306 while (
pos != std::string::npos)
309 if (
pos != std::string::npos)
314 const int altType =
s[
pos+1];
315 if (altType ==
'+' || altType ==
'-')
325 pos = std::string::npos;
340 const std::string&
s,
342 const char sigil =
'$'
347 if (
pos <
s.length())
357 auto iter =
s.cbegin() +
pos;
358 iter !=
s.cend() && validVariableChar(*iter);
387 const bool allowEmpty,
388 const bool allowSubDict
398 const word lookupName =
413 else if (allowEnv || dictptr ==
nullptr)
418 if (value.empty() ? (altType ==
'-') : (altType ==
'+'))
422 value =
name.substr(altPos + 2);
425 if (!allowEmpty && value.empty())
427 if (dictptr !=
nullptr)
431 <<
"Cannot find dictionary entry ";
435 err <<
"or environment ";
438 err <<
"variable '" << lookupName <<
"'" <<
nl
444 <<
"Unknown variable '" << lookupName <<
"'" <<
nl
465 const std::string&
s,
469 const bool allowEmpty,
470 const bool allowSubDict
476 const bool isExpr = (index <
s.size() &&
s[index] ==
'{');
484 bool isVar = !isExpr;
488 for (; index <
s.size(); ++index)
493 if (
s[index+1] ==
'{')
514 if (
s[index-1] ==
'}')
519 else if (validVariableChar(
s[index+1]))
523 const auto varLen = findVariableLen(
s, index);
524 const word varName(
s.substr(index+1, varLen),
false);
545 else if (
s[index] ==
'}')
558 else if (dictptr !=
nullptr)
562 <<
"Expansion ${{ is missing a closing '}}'\n"
568 <<
"Expansion ${{ is missing a closing '}}'\n"
619 const bool allowEmpty,
620 const bool allowSubDict,
630 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
631 && varBeg <
s.size()-1
634 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
636 if (
s[varBeg+1] ==
'{')
639 const auto replaceBeg = varBeg;
655 s.replace(replaceBeg, varBeg - replaceBeg, varValue);
656 varBeg = replaceBeg+varValue.size();
658 else if (validVariableChar(
s[varBeg+1]))
661 const auto varLen(findVariableLen(
s, varBeg, sigil));
662 const word varName(
s.substr(varBeg+1, varLen),
false);
676 s.replace(varBeg, varName.size()+1, varValue);
677 varBeg += varValue.size();
700 const std::string&
s,
721 const std::string&
s,
745 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
746 && varBeg <
s.size()-1
749 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
757 auto altPos = std::string::npos;
759 if (
s[varBeg+1] ==
'{')
761 varEnd =
s.find(
'}', varBeg);
765 if (varEnd != std::string::npos)
773 varEnd += findVariableLen(
s, varBeg, sigil);
776 if (varEnd == std::string::npos)
781 else if (varEnd == varBeg)
794 (altPos == std::string::npos ? varEnd : altPos)
801 std::string altValue;
802 if (altPos != std::string::npos)
808 varEnd - altPos - 2*delim
813 const auto fnd = mapping.
cfind(varName);
815 if (fnd.found() ? (altType ==
'+') : (altType ==
'-'))
820 s.replace(varBeg, varEnd - varBeg + 1, altValue);
821 varBeg += altValue.size();
823 else if (fnd.found())
826 s.replace(varBeg, varEnd - varBeg + 1, *fnd);
827 varBeg += (*fnd).size();
832 s.erase(varBeg, varEnd - varBeg + 1);
846 const std::string&
s,
862 const bool allowEmpty,
863 const bool allowSubDict,
886 const std::string&
s,
887 const bool allowEmpty
899 const bool allowEmpty
910 if (
s.empty() || varName.empty())
921 const auto i =
s.find(content);
922 if (i == std::string::npos)
927 s.replace(i, content.size(),
string(
"${" + varName +
"}"));
937 const auto end =
s.length();
946 return s.substr(
pos);
959 const auto end =
s.length();
978 auto end =
s.length();
984 if (
end <
s.length())
986 return s.substr(0,
end);
998 auto end =
s.length();
1009 std::pair<std::size_t, std::size_t>
1012 const std::string&
s,
1017 size_t end =
s.length();
1022 else if (len != std::string::npos)
1044 return std::pair<std::size_t, std::size_t>(
pos,
end);
1078 s.erase(std::remove_if(
s.begin(),
s.end(),
::isspace),
s.end());
1092 const auto len =
s.length();
1146 i =
s.find(
'\n', ++i);
1148 if (i == std::string::npos)
1160 i =
s.find(
"*/", ++i, 2);
1162 if (i == std::string::npos)
1189 out.resize(
s.length());
1205 out.resize(
s.length());
1221 const std::string& str,
1227 const auto len = str.length();
1232 while (str[
pos] ==
'\n' &&
pos < len)
1250 if (std::string::npos != eol && eol <=
end)
1256 else if (std::string::npos != eol && eol <=
end)
1264 next = str.find_first_not_of(
" \t\n",
end);
1270 next = str.find_first_not_of(
" \t\n",
end);
1275 auto prev = str.find_last_of(
" \t\n",
end);
1277 if (std::string::npos != prev && prev >
pos)
1285 if (std::string::npos == next)
1305 const char c = str[
pos];
1307 if (escape &&
c ==
'\\')
A keyword and a list of tokens is an 'entry'.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
static void expandLeadingTag(std::string &s, const char b, const char e)
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
void inplaceTrimRight(std::string &s)
Trim trailing whitespace inplace.
A class for handling words, derived from Foam::string.
A class for handling file names.
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))
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.
void inplaceTrim(std::string &s)
Trim leading and trailing whitespace inplace.
bool inplaceReplaceVar(std::string &s, const word &varName)
Replace environment variable contents with its name.
static Foam::string getVariable(const word &name, const dictionary *dictptr, const bool allowEnv, const bool allowEmpty, const bool allowSubDict)
static bool & parRun()
Test if this a parallel run, or allow modify access.
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.
string trim(const std::string &s)
Return string trimmed of leading and trailing whitespace.
static bool master(const label communicator=worldComm)
Am I the master process.
Input/output from string buffers.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static void expandLeadingTilde(std::string &s)
virtual void write(Ostream &os) const
Write.
A class for handling character strings derived from std::string.
string trimLeft(const std::string &s)
Return string trimmed of leading whitespace.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
void inplaceRemoveComments(std::string &s)
Remove C/C++ comments inplace.
string getEnv(const std::string &envName)
Get environment value for given envName.
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
string expand(const std::string &s, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
virtual bool isDict() const
Return true if this entry is a dictionary.
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
word name(const complex &c)
Return string representation of complex.
static std::string entryToString(const entry *eptr, const bool allowSubDict)
void inplaceExpand(std::string &s, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
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.
static void expandString(std::string &s, const dictionary *dictptr, const bool allowEnv, const bool allowEmpty, const bool allowSubDict, const char sigil)
Generic output stream using a standard (STL) stream.
graph_traits< Graph >::vertices_size_type size_type
IOstream & fixed(IOstream &io)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
string trimRight(const std::string &s)
Return string trimmed of trailing whitespace.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
static unsigned short modeToLocation(const std::string &mode, std::size_t pos=0)
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
Ostream & indent(Ostream &os)
Indent stream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
static void expandLeading(std::string &s)
A HashTable similar to std::unordered_map.
virtual int precision() const
Get precision of output field.
Functions to search 'etc' directories for configuration files etc.
void inplaceLower(std::string &s)
Inplace transform string with std::tolower on each character.
Foam::string str() const
Get the string - as Foam::string rather than std::string.
void inplaceTrimLeft(std::string &s)
Trim leading whitespace inplace.
fileName home()
Return home directory path name for the current user.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static void warnAboutAge(const char *what, const int version)
Emit warning on stderr about something being old.
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
static unsigned int defaultPrecision()
Return the default precision.
void inplaceRemoveSpace(std::string &s)
Eliminate whitespace inplace.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Output to string buffer, using a OSstream.
const dimensionedScalar e
Elementary charge.
const dimensionedScalar c
Speed of light in a vacuum.
fileName cwd()
The physical or logical current working directory path name.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
std::string::size_type count(const std::string &s, const char c)
Count the number of occurrences of the specified character.
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
string removeComments(const std::string &s)
Return string with C/C++ comments removed.
void inplaceUpper(std::string &s)
Inplace transform string with std::toupper on each character.
bool isspace(char c)
Test for horizontal whitespace.
static int findParameterAlternative(const std::string &s, std::string::size_type &pos, std::string::size_type endPos=std::string::npos)
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
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)
dimensionedScalar pos(const dimensionedScalar &ds)