67 static bool cleanFileName
74 const auto maxLen = str.
length();
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] ==
'\\' 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)
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)
330 if (length())
operator+=(
'/');
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);
451 const fileName& parent,
455 const auto top = parent.
length();
456 const fileName&
f = *
this;
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);
541 const auto parsed = stringOps::split<string>(*
this, delim);
546 for (
const auto& sub : parsed)
549 words[i] = sub.str();
564 const auto parsed = stringOps::split<string>(*
this, delim);
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;
static std::string::size_type length(const char *s)
Length of the character sequence (with nullptr protection)
static int debug
Debugging.
A class for handling file names.
fileName & operator/=(const string &other)
Append a path element with '/' separator.
bool clean()
Cleanup filename (inplace)
word stem() const
Return basename, without extension.
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
static const fileName null
An empty fileName.
Type type(bool followLink=true, bool checkGzip=false) const
Return the directory entry type: UNDEFINED, FILE, DIRECTORY (or SYMLINK).
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
static const char *const typeName
The typeName.
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...
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
word component(const size_type cmpt, const char delim='/') const
Return a single component of the path or empty if out of range.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool assign(const token &tok)
Assign from word or string token.
fileName relative(const fileName &parent, const bool caseTag=false) const
Return a relative name by stripping off the parent directory where possible.
fileName()=default
Default construct.
A class for handling words, derived from Foam::string.
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.
fileName & toAbsolute()
Convert from relative to absolute.
wordList components(const char delim='/') const
Return path components as wordList.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static bool valid(char c)
Is this character valid for a fileName?
static fileName concat(const std::string &s1, const std::string &s2, const char delim='/')
Join two strings with a path separator ('/' by default).
fileName & replace_name(const word &newName)
Replace basename (part beyond last /) with a new name.
List< word > wordList
List of word.
static int allowSpaceInFileName
Allow space character in fileName. To be used with caution.
bool isBackup() const
Return true if file name ends with "~", ".bak", ".old", ".save".
static fileName validate(const std::string &, const bool doClean=true)
Construct fileName without invalid characters, possibly applying other transformations such as changi...
const dimensionedScalar c
Speed of light in a vacuum.
triangles reserve(surf.size())
fileName cwd()
The physical or logical current working directory path name.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
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))
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.
Type
Enumerations to handle directory entry types.