67static bool cleanFileName
74 const auto maxLen = str.length();
75 std::string::size_type nChar = 0;
80 if (maxLen > 2 && str[0] ==
'\\' && str[1] ==
'\\')
86 auto top = std::string::npos;
89 for (
auto src = nChar; src < maxLen; )
111 if (c ==
'/' && top == std::string::npos)
117 if (doClean && prev ==
'/')
135 const char c1 = str[src];
138 if (c1 ==
'/' || c1 ==
'\\')
151 || str[src+1] ==
'/' || str[src+1] ==
'\\'
159 std::string::size_type parent;
163 && top != std::string::npos
164 && (parent = str.rfind(
'/', nChar-2)) != std::string::npos
181 str[nChar++] = prev =
c;
185 if (doClean && nChar > 1 && str[nChar-1] ==
'/')
191 return changed || (nChar != maxLen);
201 return cleanFileName(str,
true,
false);
207 const std::string& str,
212 cleanFileName(out, doClean,
true);
219 const std::string& s1,
220 const std::string& s2,
224 const auto n1 = s1.length();
225 const auto n2 = s2.length();
228 out.reserve(n1 + n2 + 1);
232 if (n1 && n2 && s1.back() != delim && s2.front() != delim)
250 std::string::size_type i1 = 0;
251 std::string::size_type i2 = 0;
253 const auto n1 = s1.length();
254 const auto n2 = s2.length();
257 while (i1 < n1 && i2 < n2)
261 if (s1[i1] != s2[i2])
271 while (s1[i1] ==
'/');
277 while (s2[i2] ==
'/');
282 return (i1 == n1 && i2 == n2);
292 else if (
s.back() ==
'~')
298 auto dot = find_ext(
s);
309 !
s.compare(
dot, npos,
"bak") || !
s.compare(
dot, npos,
"BAK")
310 || !
s.compare(
dot, npos,
"old") || !
s.compare(
dot, npos,
"save")
320 for (
const word& item : list)
322 len += 1 + item.length();
326 for (
const word& item : list)
340 for (
const word& item : list)
342 len += 1 + item.length();
346 for (
const word& item : list)
350 if (length()) operator+=(
'/');
367 if (checkGzip && (Type::UNDEFINED == t) && size())
400 auto beg = str.rfind(
'/');
401 auto dot = str.rfind(
'.');
412 if (
dot != npos &&
dot <= beg)
419 return str.substr(beg);
422 return str.substr(beg,
dot - beg);
428 const auto len = newName.
length();
432 auto beg = rfind(
'/');
441 replace(beg, length()-beg, newName);
455 const auto top = parent.
length();
469 top && (
f.length() > (top+1)) &&
f[top] ==
'/'
470 &&
f.starts_with(parent)
475 const auto trailing =
f.
find(
'/', top+1);
477 if (npos != trailing)
479 switch (trailing-top-1)
483 if (!compare((top+1), 6,
"system"))
485 return "<system>"/
f.substr(trailing+1);
491 if (!compare((top+1), 8,
"constant"))
493 return "<constant>"/
f.substr(trailing+1);
499 return "<case>"/
f.substr(top+1);
503 return f.substr(top+1);
506 else if (caseTag &&
f.length() && !
f.isAbsolute())
508 const auto trailing =
f.
find(
'/');
510 if (npos != trailing)
516 if (!compare(0, 6,
"system"))
518 return "<system>"/
f.substr(trailing+1);
524 if (!compare(0, 8,
"constant"))
526 return "<constant>"/
f.substr(trailing+1);
546 for (
const auto& sub : parsed)
549 words[i] = sub.str();
568 if (cmpt == std::string::npos)
570 return parsed.back().str();
572 else if (cmpt < parsed.size())
574 return parsed[cmpt].str();
594 if (
s.back() !=
'/' && other.front() !=
'/')
602 else if (other.size())
622 if (s1.back() ==
'/' || s2.front() ==
'/')
624 return fileName(s1 + s2);
628 return fileName(s1 +
'/' + s2);
660 return directory/item;
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
graph_traits< Graph >::vertices_size_type size_type
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
label find(const T &val) const
Find index of the first occurrence of the value.
A class for handling file names.
wordList components(const char delim='/') const
Return path components as wordList.
fileName relative(const fileName &parent, const bool caseTag=false) const
Return a relative name by stripping off the parent directory where possible.
static fileName validate(const std::string &, const bool doClean=true)
Construct fileName without invalid characters, possibly applying other transformations such as changi...
bool assign(const token &tok)
Assign from word or string token.
bool clean()
Cleanup filename (inplace).
Type
Enumerations to handle directory entry types.
@ UNDEFINED
Undefined type.
Type type(bool followLink=true, bool checkGzip=false) const
Return the directory entry type: UNDEFINED, FILE, DIRECTORY (or SYMLINK).
fileName()=default
Default construct.
fileName & operator/=(const string &other)
Append a path element with '/' separator.
static fileName concat(const std::string &s1, const std::string &s2, const char delim='/')
Join two strings with a path separator ('/' by default).
static bool equals(const std::string &s1, const std::string &s2)
This is a specialized (possibly slower) version of compare() that ignores duplicate or trailing slash...
word component(const size_type cmpt, const char delim='/') const
Return a single component of the path or empty if out of range.
static const fileName null
An empty fileName.
static bool valid(char c)
Is this character valid for a fileName?
fileName & toAbsolute()
Convert from relative to absolute.
static int debug
Debugging.
fileName & replace_name(const word &newName)
Replace basename (part beyond last /) with a new name.
bool isBackup() const
Return true if file name ends with "~", ".bak", ".old", ".save".
static int allowSpaceInFileName
Allow space character in fileName. To be used with caution.
word stem() const
Return basename, without extension.
static const char *const typeName
The typeName.
static std::string::size_type length(const char *s)
Length of the character sequence (with nullptr protection).
string & replace(const std::string &s1, const std::string &s2, size_type pos=0)
Replace first occurrence of sub-string s1 with s2, beginning at pos.
static std::string::size_type find_ext(const std::string &str)
Find position of a file extension dot, return npos on failure.
A class for handling words, derived from Foam::string.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
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))
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
const dimensionedScalar c
Speed of light in a vacuum.
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
Foam::SubStrings split(const std::string &str, const char delim, std::string::size_type pos=0, const bool keepEmpty=false)
Split string into sub-strings at the delimiter character.
fileName cwd()
The physical or logical current working directory path name.
List< word > wordList
List of word.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
triangles reserve(surf.size())