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")
162 const int version(1806);
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();
283static inline bool validVariableChar(
char c)
299 const std::string&
s,
300 std::string::size_type& pos,
301 std::string::size_type endPos
304 while (pos != std::string::npos)
306 pos =
s.find(
':', pos);
307 if (pos != std::string::npos)
312 const int altType =
s[
pos+1];
313 if (altType ==
'+' || altType ==
'-')
323 pos = std::string::npos;
336static inline std::string::size_type findVariableLen
338 const std::string&
s,
339 std::string::size_type pos,
340 const char sigil =
'$'
343 std::string::size_type len = 0;
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
390 std::string::size_type altPos = 0;
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,
464 std::string::size_type& index,
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,
622 std::string::size_type varBeg = 0;
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,
702 return std::count(
s.cbegin(),
s.cend(), c);
712 : std::count(
s, (
s + std::char_traits<char>::length(
s)), c)
719 const std::string&
s,
737 std::string::size_type varBeg = 0;
743 (varBeg =
s.find(sigil, varBeg)) != std::string::npos
744 && varBeg <
s.size()-1
747 if (varBeg == 0 ||
s[varBeg-1] !=
'\\')
750 std::string::size_type varEnd = varBeg;
751 std::string::size_type delim = 0;
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 +
"}"));
934 std::string::size_type
pos = 0;
935 const auto end =
s.length();
937 while (
pos < end && std::isspace(
s[
pos]))
944 return s.substr(
pos);
956 std::string::size_type
pos = 0;
957 const auto end =
s.length();
959 while (
pos < end && std::isspace(
s[
pos]))
976 auto end =
s.length();
977 while (end && std::isspace(
s[end-1]))
982 if (end <
s.length())
984 return s.substr(0, end);
996 auto end =
s.length();
997 while (end && std::isspace(
s[end-1]))
1007std::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)
1031 while (pos < end && std::isspace(
s[end-1]))
1037 while (pos < end && std::isspace(
s[pos]))
1042 return std::pair<std::size_t, std::size_t>(pos, end);
1048 std::string::size_type
pos = 0;
1049 std::string::size_type end =
s.length();
1052 while (
pos < end && std::isspace(
s[end-1]))
1058 while (
pos < end && std::isspace(
s[
pos]))
1063 return s.substr(
pos, end-
pos);
1076 s.erase(std::remove_if(
s.begin(),
s.end(), ::isspace),
s.end());
1090 const auto len =
s.length();
1097 std::string::size_type
n = 0;
1099 for (std::string::size_type i = 0; i < len; ++i)
1132 while (
n && std::isspace(
s[
n-1]))
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());
1189 std::transform(
s.begin(),
s.end(), out.begin(), ::tolower);
1196 std::transform(
s.begin(),
s.end(),
s.begin(), ::tolower);
1203 out.resize(
s.length());
1205 std::transform(
s.begin(),
s.end(), out.begin(), ::toupper);
1212 std::transform(
s.begin(),
s.end(),
s.begin(), ::toupper);
1219 const std::string& str,
1220 const std::string::size_type width,
1221 const std::string::size_type indent,
1225 const auto len = str.length();
1227 std::string::size_type
pos = 0;
1230 while (str[
pos] ==
'\n' &&
pos < len)
1239 std::string::size_type end =
pos + width - 1;
1240 std::string::size_type eol = str.find(
'\n',
pos);
1241 std::string::size_type next = string::npos;
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)
1295 for (std::string::size_type i = 0; i <
indent; ++i)
1303 const char c = str[
pos];
1305 if (escape && c ==
'\\')
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Input/output from string buffers.
Foam::string str() const
Get the string - as Foam::string rather than std::string.
A HashTable similar to std::unordered_map.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
static unsigned int defaultPrecision() noexcept
Return the default precision.
Generic output stream using a standard (STL) stream.
virtual int precision() const
Get precision of output field.
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
void size(const label n)
Older name for setAddressableSize.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
A keyword and a list of tokens is an 'entry'.
virtual bool isDict() const noexcept
Return true if this entry is a dictionary.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
static bool warnAboutAge(const int version) noexcept
Test if an age warning should be emitted.
A class for handling file names.
bool assign(const token &tok)
Assign from word or string token.
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
virtual void write(Ostream &os) const
Write.
splitCell * master() const
A class for handling character strings derived from std::string.
A class for handling words, derived from Foam::string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Functions to search 'etc' directories for configuration files etc.
OBJstream os(runTime.globalPath()/outputName)
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 inplaceLower(std::string &s)
Inplace transform string with std::tolower on each character.
string removeComments(const std::string &s)
Return string with C/C++ comments removed.
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.
void inplaceRemoveComments(std::string &s)
Remove C/C++ comments inplace.
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
bool inplaceReplaceVar(std::string &s, const word &varName)
Replace environment variable contents with its name.
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 trim(const std::string &s)
Return string trimmed of leading and trailing whitespace.
void inplaceUpper(std::string &s)
Inplace transform string with std::toupper on each character.
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.
void inplaceExpand(std::string &s, const HashTable< string > &mapping, const char sigil='$')
void inplaceTrimLeft(std::string &s)
Trim leading whitespace inplace.
std::string::size_type count(const std::string &s, const char c)
Count the number of occurrences of the specified character.
void inplaceTrim(std::string &s)
Trim leading and trailing whitespace inplace.
string trimLeft(const std::string &s)
Return string trimmed of leading whitespace.
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
string trimRight(const std::string &s)
Return string trimmed of trailing whitespace.
void inplaceTrimRight(std::string &s)
Trim trailing whitespace inplace.
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
void inplaceRemoveSpace(std::string &s)
Eliminate whitespace inplace.
fileName cwd()
The physical or logical current working directory path name.
static std::string entryToString(const entry *eptr, const bool allowSubDict)
dimensionedScalar pos(const dimensionedScalar &ds)
string getEnv(const std::string &envName)
Get environment value for given envName.
IOstream & fixed(IOstream &io)
bool isspace(char c) noexcept
Test for whitespace (C-locale)
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
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 findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
Ostream & indent(Ostream &os)
Indent stream.
static Foam::string getVariable(const word &name, const dictionary *dictptr, const bool allowEnv, const bool allowEmpty, const bool allowSubDict)
static void expandLeading(std::string &s)
static void expandString(std::string &s, const dictionary *dictptr, const bool allowEnv, const bool allowEmpty, const bool allowSubDict, const char sigil)
static unsigned short modeToLocation(const std::string &mode, std::size_t pos=0)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
static void expandLeadingTag(std::string &s, const char b, const char e)
errorManipArg< error, int > exit(error &err, const int errNo=1)
fileName home()
Return home directory path name for the current user.
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 void expandLeadingTilde(std::string &s)
constexpr char nl
The newline '\n' character (0x0a)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
static char findParameterAlternative(const std::string &s, std::string::size_type &pos, std::string::size_type endPos=std::string::npos)