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")
168 <<
"--> FOAM Warning :" <<
nl
169 <<
" Found [v" <<
version <<
"] '"
170 <<
"~OpenFOAM" <<
"' string expansion instead of '"
171 <<
"<etc>" <<
"' in string\n\"" <<
s <<
"\"\n" <<
nl
203 else if (
s[1] ==
'/')
205 s.replace(0, 1,
cwd());
228 const bool allowSubDict
241 if (allowSubDict && eptr->
isDict())
250 dynamicCast<const primitiveEntry>(*eptr);
252 if (pe.size() == 1 && pe[0].isStringType())
255 str = pe[0].stringToken();
283 static inline bool validVariableChar(
char c)
299 const std::string&
s,
304 while (
pos != std::string::npos)
307 if (
pos != std::string::npos)
312 const int altType =
s[
pos+1];
313 if (altType ==
'+' || altType ==
'-')
323 pos = std::string::npos;
338 const std::string&
s,
340 const char sigil =
'$'
345 if (
pos <
s.length())
355 auto iter =
s.cbegin() +
pos;
356 iter !=
s.cend() && validVariableChar(*iter);
385 const bool allowEmpty,
386 const bool allowSubDict
396 const word lookupName =
411 else if (allowEnv || dictptr ==
nullptr)
416 if (value.empty() ? (altType ==
'-') : (altType ==
'+'))
420 value =
name.substr(altPos + 2);
423 if (!allowEmpty && value.empty())
425 if (dictptr !=
nullptr)
429 <<
"Cannot find dictionary entry ";
433 err <<
"or environment ";
436 err <<
"variable '" << lookupName <<
"'" <<
nl
442 <<
"Unknown variable '" << lookupName <<
"'" <<
nl
463 const std::string&
s,
467 const bool allowEmpty,
468 const bool allowSubDict
474 const bool isExpr = (index <
s.size() &&
s[index] ==
'{');
482 bool isVar = !isExpr;
486 for (; index <
s.size(); ++index)
491 if (
s[index+1] ==
'{')
512 if (
s[index-1] ==
'}')
517 else if (validVariableChar(
s[index+1]))
521 const auto varLen = findVariableLen(
s, index);
522 const word varName(
s.substr(index+1, varLen),
false);
543 else if (
s[index] ==
'}')
556 else if (dictptr !=
nullptr)
560 <<
"Expansion ${{ is missing a closing '}}'\n"
566 <<
"Expansion ${{ is missing a closing '}}'\n"
617 const bool allowEmpty,
618 const bool allowSubDict,
628 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
629 && varBeg <
s.size()-1
632 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
634 if (
s[varBeg+1] ==
'{')
637 const auto replaceBeg = varBeg;
653 s.replace(replaceBeg, varBeg - replaceBeg, varValue);
654 varBeg = replaceBeg+varValue.size();
656 else if (validVariableChar(
s[varBeg+1]))
659 const auto varLen(findVariableLen(
s, varBeg, sigil));
660 const word varName(
s.substr(varBeg+1, varLen),
false);
674 s.replace(varBeg, varName.size()+1, varValue);
675 varBeg += varValue.size();
698 const std::string&
s,
719 const std::string&
s,
743 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
744 && varBeg <
s.size()-1
747 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
755 auto altPos = std::string::npos;
757 if (
s[varBeg+1] ==
'{')
759 varEnd =
s.find(
'}', varBeg);
763 if (varEnd != std::string::npos)
771 varEnd += findVariableLen(
s, varBeg, sigil);
774 if (varEnd == std::string::npos)
779 else if (varEnd == varBeg)
792 (altPos == std::string::npos ? varEnd : altPos)
799 std::string altValue;
800 if (altPos != std::string::npos)
806 varEnd - altPos - 2*delim
811 const auto fnd = mapping.
cfind(varName);
813 if (fnd.found() ? (altType ==
'+') : (altType ==
'-'))
818 s.replace(varBeg, varEnd - varBeg + 1, altValue);
819 varBeg += altValue.size();
821 else if (fnd.found())
824 s.replace(varBeg, varEnd - varBeg + 1, *fnd);
825 varBeg += (*fnd).size();
830 s.erase(varBeg, varEnd - varBeg + 1);
844 const std::string&
s,
860 const bool allowEmpty,
861 const bool allowSubDict,
884 const std::string&
s,
885 const bool allowEmpty
897 const bool allowEmpty
908 if (
s.empty() || varName.empty())
919 const auto i =
s.find(content);
920 if (i == std::string::npos)
925 s.replace(i, content.size(),
string(
"${" + varName +
"}"));
935 const auto end =
s.length();
944 return s.substr(
pos);
957 const auto end =
s.length();
976 auto end =
s.length();
982 if (
end <
s.length())
984 return s.substr(0,
end);
996 auto end =
s.length();
1007 std::pair<std::size_t, std::size_t>
1010 const std::string&
s,
1015 size_t end =
s.length();
1020 else if (len != std::string::npos)
1042 return std::pair<std::size_t, std::size_t>(
pos,
end);
1076 s.erase(std::remove_if(
s.begin(),
s.end(),
::isspace),
s.end());
1090 const auto len =
s.length();
1144 i =
s.find(
'\n', ++i);
1146 if (i == std::string::npos)
1158 i =
s.find(
"*/", ++i, 2);
1160 if (i == std::string::npos)
1187 out.resize(
s.length());
1203 out.resize(
s.length());
1219 const std::string& str,
1225 const auto len = str.length();
1230 while (str[
pos] ==
'\n' &&
pos < len)
1248 if (std::string::npos != eol && eol <=
end)
1254 else if (std::string::npos != eol && eol <=
end)
1262 next = str.find_first_not_of(
" \t\n",
end);
1268 next = str.find_first_not_of(
" \t\n",
end);
1273 auto prev = str.find_last_of(
" \t\n",
end);
1275 if (std::string::npos != prev && prev >
pos)
1283 if (std::string::npos == next)
1303 const char c = str[
pos];
1305 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.
bool isspace(char c) noexcept
Test for whitespace (C-locale)
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.
virtual bool isDict() const noexcept
Return true if this entry is a dictionary.
static Foam::string getVariable(const word &name, 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.
string trim(const std::string &s)
Return string trimmed of leading and trailing whitespace.
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.
static char findParameterAlternative(const std::string &s, std::string::size_type &pos, std::string::size_type endPos=std::string::npos)
void inplaceExpand(std::string &s, const HashTable< string > &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].
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
static std::string entryToString(const entry *eptr, const bool allowSubDict)
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.
OBJstream os(runTime.globalPath()/outputName)
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.
static unsigned int defaultPrecision() noexcept
Return the default precision.
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.
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.
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. Always UNCOMPRESSED.
static bool master(const label communicator=-1)
const dimensionedScalar e
Elementary charge.
const dimensionedScalar c
Speed of light in a vacuum.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
static bool warnAboutAge(const int version) noexcept
Test if an age warning should be emitted.
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.
bool assign(const token &tok)
Assign from word or string token.
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.
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
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 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.
dimensionedScalar pos(const dimensionedScalar &ds)