Go to the documentation of this file.
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")
169 <<
"--> FOAM Warning :" <<
nl
170 <<
" Found [v" <<
version <<
"] '"
171 <<
"~OpenFOAM" <<
"' string expansion instead of '"
172 <<
"<etc>" <<
"' in string\n\"" <<
s <<
"\"\n" <<
nl
204 else if (
s[1] ==
'/')
206 s.replace(0, 1,
cwd());
229 const bool allowSubDict
242 if (allowSubDict && eptr->
isDict())
251 dynamicCast<const primitiveEntry>(*eptr);
253 if (pe.size() == 1 && pe[0].isStringType())
256 str = pe[0].stringToken();
284 static inline bool validVariableChar(
char c)
298 static inline int findParameterAlternative
300 const std::string&
s,
305 while (
pos != std::string::npos)
308 if (
pos != std::string::npos)
313 const int altType =
s[
pos+1];
314 if (altType ==
'+' || altType ==
'-')
324 pos = std::string::npos;
339 const std::string&
s,
341 const char sigil =
'$'
346 if (
pos <
s.length())
356 auto iter =
s.cbegin() +
pos;
357 iter !=
s.cend() && validVariableChar(*iter);
386 const bool allowEmpty,
387 const bool allowSubDict
395 findParameterAlternative(
name, altPos,
name.size()-1);
397 const word lookupName =
412 else if (allowEnv || dictptr ==
nullptr)
417 if (value.empty() ? (altType ==
'-') : (altType ==
'+'))
421 value =
name.substr(altPos + 2);
424 if (!allowEmpty && value.empty())
426 if (dictptr !=
nullptr)
430 <<
"Cannot find dictionary entry ";
434 err <<
"or environment ";
437 err <<
"variable '" << lookupName <<
"'" <<
nl
443 <<
"Unknown variable '" << lookupName <<
"'" <<
nl
464 const std::string&
s,
468 const bool allowEmpty,
469 const bool allowSubDict
475 const bool isExpr = (index <
s.size() &&
s[index] ==
'{');
483 bool isVar = !isExpr;
487 for (; index <
s.size(); ++index)
492 if (
s[index+1] ==
'{')
513 if (
s[index-1] ==
'}')
518 else if (validVariableChar(
s[index+1]))
522 const auto varLen = findVariableLen(
s, index);
523 const word varName(
s.substr(index+1, varLen),
false);
544 else if (
s[index] ==
'}')
557 else if (dictptr !=
nullptr)
561 <<
"Expansion ${{ is missing a closing '}}'\n"
567 <<
"Expansion ${{ is missing a closing '}}'\n"
618 const bool allowEmpty,
619 const bool allowSubDict,
629 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
630 && varBeg <
s.size()-1
633 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
635 if (
s[varBeg+1] ==
'{')
638 const auto replaceBeg = varBeg;
654 s.replace(replaceBeg, varBeg - replaceBeg, varValue);
655 varBeg = replaceBeg+varValue.size();
657 else if (validVariableChar(
s[varBeg+1]))
660 const auto varLen(findVariableLen(
s, varBeg, sigil));
661 const word varName(
s.substr(varBeg+1, varLen),
false);
675 s.replace(varBeg, varName.size()+1, varValue);
676 varBeg += varValue.size();
699 const std::string& str,
705 for (
auto iter = str.cbegin(); iter != str.cend(); ++iter)
726 for (
const char *iter = str; *iter; ++iter)
740 const std::string& str,
764 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
765 && varBeg <
s.size()-1
768 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
776 auto altPos = std::string::npos;
778 if (
s[varBeg+1] ==
'{')
780 varEnd =
s.find(
'}', varBeg);
784 if (varEnd != std::string::npos)
787 altType = findParameterAlternative(
s, altPos, varEnd);
792 varEnd += findVariableLen(
s, varBeg, sigil);
795 if (varEnd == std::string::npos)
800 else if (varEnd == varBeg)
813 (altPos == std::string::npos ? varEnd : altPos)
820 std::string altValue;
821 if (altPos != std::string::npos)
827 varEnd - altPos - 2*delim
832 const auto fnd = mapping.
cfind(varName);
834 if (fnd.found() ? (altType ==
'+') : (altType ==
'-'))
839 s.replace(varBeg, varEnd - varBeg + 1, altValue);
840 varBeg += altValue.size();
842 else if (fnd.found())
845 s.replace(varBeg, varEnd - varBeg + 1, *fnd);
846 varBeg += (*fnd).size();
851 s.erase(varBeg, varEnd - varBeg + 1);
865 const std::string& str,
881 const bool allowEmpty,
882 const bool allowSubDict,
905 const std::string& str,
906 const bool allowEmpty
918 const bool allowEmpty
929 if (
s.empty() || varName.empty())
940 const auto i =
s.find(content);
941 if (i == std::string::npos)
946 s.replace(i, content.size(),
string(
"${" + varName +
"}"));
956 const auto end =
s.length();
965 return s.substr(
pos);
978 const auto end =
s.length();
997 auto end =
s.length();
1003 if (
end <
s.length())
1005 return s.substr(0,
end);
1017 auto end =
s.length();
1028 std::pair<std::size_t, std::size_t>
1031 const std::string&
s,
1036 size_t end =
s.length();
1041 else if (len != std::string::npos)
1063 return std::pair<std::size_t, std::size_t>(
pos,
end);
1105 const auto len =
s.length();
1159 i =
s.find(
'\n', ++i);
1161 if (i == std::string::npos)
1173 i =
s.find(
"*/", ++i, 2);
1175 if (i == std::string::npos)
1209 for (
auto iter =
s.begin(); iter !=
s.end(); ++iter)
1211 *iter =
static_cast<std::string::value_type
>
1213 std::tolower(
static_cast<unsigned char>(*iter))
1229 for (
auto iter =
s.begin(); iter !=
s.end(); ++iter)
1231 *iter =
static_cast<std::string::value_type
>
1233 std::toupper(
static_cast<unsigned char>(*iter))
1242 const std::string& str,
1248 const auto len = str.length();
1253 while (str[
pos] ==
'\n' &&
pos < len)
1271 if (std::string::npos != eol && eol <=
end)
1277 else if (std::string::npos != eol && eol <=
end)
1285 next = str.find_first_not_of(
" \t\n",
end);
1291 next = str.find_first_not_of(
" \t\n",
end);
1296 auto prev = str.find_last_of(
" \t\n",
end);
1298 if (std::string::npos != prev && prev >
pos)
1306 if (std::string::npos == next)
1326 const char c = str[
pos];
1328 if (escape &&
c ==
'\\')
A keyword and a list of tokens is an 'entry'.
label ListType::const_reference val
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()
Is this a parallel run?
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.
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.
string lower(const std::string &str)
Return string transformed with std::tolower on each character.
A class for handling character strings derived from std::string.
string trimLeft(const std::string &s)
Return string trimmed of leading whitespace.
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.
std::string::size_type count(const std::string &str, const char c)
Count the number of occurrences of the specified 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.
string upper(const std::string &str)
Return string transformed with std::toupper on each character.
static void expandString(std::string &s, const dictionary *dictptr, const bool allowEnv, const bool allowEmpty, const bool allowSubDict, const char sigil)
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.
string removeComments(const std::string &str)
Return string with C/C++ comments removed.
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 bool master(const label communicator=0)
Am I the master process.
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 write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Output to string buffer, using a OSstream.
string expand(const std::string &str, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
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.
void inplaceUpper(std::string &s)
Inplace transform string with std::toupper on each character.
bool isspace(char c)
Test for horizontal whitespace.
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)
string trim(const std::string &str)
Return string trimmed of leading and trailing whitespace.
dimensionedScalar pos(const dimensionedScalar &ds)