Doxygen
Loading...
Searching...
No Matches
FileInfo Class Reference

Minimal replacement for QFileInfo. More...

#include <src/fileinfo.h>

Public Member Functions

 FileInfo (const std::string &name)
bool exists () const
size_t size () const
bool isWritable () const
bool isReadable () const
bool isExecutable () const
bool isRelative () const
bool isFile () const
bool isDir () const
bool isSymLink () const
std::string readLink () const
std::string filePath () const
std::string absFilePath () const
std::string fileName () const
std::string baseName () const
std::string extension (bool complete) const
std::string dirPath (bool absPath=true) const
template<class PatternList, class PatternElem = std::string, typename PatternGet = std::string(*)(const PatternElem &)>
bool match (const PatternList &patList, bool caseSenseNames, PatternElem *elem=nullptr, PatternGet getter=[](const std::string &s){ return s;}) const
 Match the file name against a list of patterns.

Static Private Member Functions

static void correctPath (std::string &s)

Private Attributes

std::string m_name

Detailed Description

Minimal replacement for QFileInfo.

Definition at line 25 of file fileinfo.h.

Constructor & Destructor Documentation

◆ FileInfo()

FileInfo::FileInfo ( const std::string & name)
inlineexplicit

Definition at line 28 of file fileinfo.h.

28: m_name(name) {}
std::string m_name
Definition fileinfo.h:108

References m_name.

Member Function Documentation

◆ absFilePath()

std::string FileInfo::absFilePath ( ) const

Definition at line 105 of file fileinfo.cpp.

106{
107 std::string result;
108 std::error_code ec;
109 fs::path path(m_name);
110 if (!path.is_relative())
111 {
112 result = path.lexically_normal().string();
113 }
114 else
115 {
116 result = (fs::current_path(ec) / m_name).lexically_normal().string();
117 }
118 correctPath(result);
119 return result;
120}
static void correctPath(std::string &s)
Definition fileinfo.cpp:100

References correctPath(), and m_name.

Referenced by Preprocessor::addSearchDir(), checkAndOpenFile(), checkMarkdownMainfile(), cleanUpPaths(), determineAbsoluteIncludeName(), dirPath(), findExampleFilePath(), FormulaManager::generateImages(), getConvertLatexMacro(), markdownFileNameToId(), openDbConnection(), parseFile(), MarkdownOutlineParser::parseInput(), preProcessFile(), RTFGenerator::preProcessFileInplace(), Markdown::Private::processLink(), readConfiguration(), readDir(), readFileOrDirectory(), readTagFile(), resolveDirLink(), setFileName(), substituteLatexKeywords(), and ClassDefImpl::writeIncludeFilesForSlice().

◆ baseName()

std::string FileInfo::baseName ( ) const

Definition at line 127 of file fileinfo.cpp.

128{
129 std::string s = fileName();
130 size_t pos = s.find('.');
131 return pos!=std::string::npos ? s.substr(0,pos) : s;
132}
std::string fileName() const
Definition fileinfo.cpp:122

References fileName().

Referenced by parseMain().

◆ correctPath()

void FileInfo::correctPath ( std::string & s)
staticprivate

Definition at line 100 of file fileinfo.cpp.

101{
102 std::replace( s.begin(), s.end(), '\\', '/' );
103}

Referenced by absFilePath(), and dirPath().

◆ dirPath()

std::string FileInfo::dirPath ( bool absPath = true) const

Definition at line 141 of file fileinfo.cpp.

142{
143 std::string result;
144 if (absPath)
145 {
146 result = absFilePath();
147 }
148 else
149 {
150 result = m_name;
151 correctPath(result);
152 }
153 size_t pos = result.rfind('/');
154 if (pos==std::string::npos)
155 {
156 return ".";
157 }
158 else if (pos==0)
159 {
160 return "/";
161 }
162 else
163 {
164 return result.substr(0,pos);
165 }
166}
std::string absFilePath() const
Definition fileinfo.cpp:105

References absFilePath(), correctPath(), and m_name.

Referenced by Config::checkAndCorrect(), determineAbsoluteIncludeName(), findFile(), findPackageScope(), initWarningFormat(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), ManDocVisitor::operator()(), ManDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), CodeFragmentManager::parseCodeFragment(), readDir(), and readFileOrDirectory().

◆ exists()

◆ extension()

std::string FileInfo::extension ( bool complete) const

Definition at line 134 of file fileinfo.cpp.

135{
136 std::string fn = fileName();
137 size_t pos = complete ? fn.find('.') : fn.rfind('.');
138 return pos!=std::string::npos ? fn.substr(pos+1) : std::string();
139}

References fileName().

Referenced by getLanguageFromFileName(), and DefinitionImpl::Private::setDefFileName().

◆ fileName()

◆ filePath()

std::string FileInfo::filePath ( ) const

Definition at line 95 of file fileinfo.cpp.

96{
97 return m_name;
98}

References m_name.

Referenced by openOutputFile().

◆ isDir()

bool FileInfo::isDir ( ) const

Definition at line 74 of file fileinfo.cpp.

75{
76 std::error_code ec;
77 fs::file_status status = fs::status(m_name,ec);
78 return !ec && fs::is_directory(std::move(status));
79}

References m_name.

Referenced by Preprocessor::addSearchDir(), Config::checkAndCorrect(), cleanUpPaths(), copyExtraFiles(), copyIcon(), copyLatexStyleSheet(), copyLogo(), copyStyleSheet(), determineAbsoluteIncludeName(), Dir::exists(), readDir(), readFileOrDirectory(), and resolveSymlink().

◆ isExecutable()

bool FileInfo::isExecutable ( ) const

Definition at line 55 of file fileinfo.cpp.

56{
57 std::error_code ec;
58 fs::file_status status = fs::status(m_name,ec);
59 return !ec && (status.permissions() & fs::perms::owner_exec)!=fs::perms::none;
60}

References m_name.

◆ isFile()

bool FileInfo::isFile ( ) const

Definition at line 67 of file fileinfo.cpp.

68{
69 std::error_code ec;
70 fs::file_status status = fs::status(m_name,ec);
71 return !ec && fs::is_regular_file(std::move(status));
72}

References m_name.

Referenced by Config::checkAndCorrect(), checkAndOpenFile(), computeVerifiedDotPath(), fileToString(), javaExecutable(), parseInput(), readDir(), readFileOrDirectory(), readIncludeFile(), readTagFile(), runPlantumlContent(), tryPath(), and HtmlGenerator::writeStyleInfo().

◆ isReadable()

bool FileInfo::isReadable ( ) const

Definition at line 48 of file fileinfo.cpp.

49{
50 std::error_code ec;
51 fs::file_status status = fs::status(m_name,ec);
52 return !ec && (status.permissions() & fs::perms::owner_read)!=fs::perms::none;
53}

References m_name.

Referenced by Htags::loadFilemap(), Markdown::Private::processLink(), readDir(), readFileOrDirectory(), and HtmlGenerator::writeStyleInfo().

◆ isRelative()

bool FileInfo::isRelative ( ) const

Definition at line 62 of file fileinfo.cpp.

63{
64 return fs::path(m_name).is_relative();
65}

References m_name.

Referenced by resolveSymlink().

◆ isSymLink()

bool FileInfo::isSymLink ( ) const

Definition at line 81 of file fileinfo.cpp.

82{
83 std::error_code ec;
84 fs::file_status status = fs::symlink_status(m_name,ec);
85 return !ec && fs::is_symlink(std::move(status));
86}

References m_name.

Referenced by DocParser::findAndCopyImage(), readDir(), readFileOrDirectory(), and resolveSymlink().

◆ isWritable()

bool FileInfo::isWritable ( ) const

Definition at line 41 of file fileinfo.cpp.

42{
43 std::error_code ec;
44 fs::file_status status = fs::status(m_name,ec);
45 return !ec && (status.permissions() & fs::perms::owner_write)!=fs::perms::none;
46}

References m_name.

◆ match()

template<class PatternList, class PatternElem = std::string, typename PatternGet = std::string(*)(const PatternElem &)>
bool FileInfo::match ( const PatternList & patList,
bool caseSenseNames,
PatternElem * elem = nullptr,
PatternGet getter = [](const std::string &s){ return s; } ) const
inline

Match the file name against a list of patterns.

The pattern list can be a list of strings or a list of objects that can be converted to strings. The pattern is matched against the file name, the file path and the absolute file path. If a match is found, the matching pattern is returned in elem (if not nullptr).

Parameters
patListList of patterns to match against.
caseSenseNamesWhether to match case-sensitively or not.
elemPointer to store the matching pattern (optional).
getterFunction to convert pattern elements to strings (optional).
Returns
True if a match is found, false otherwise.

Definition at line 60 of file fileinfo.h.

63 { return s; }
64 ) const
65 {
66 bool found = false;
67
68 if (!patList.empty())
69 {
70 std::string fn = fileName();
71 std::string fp = filePath();
72 std::string afp= absFilePath();
73
74 for (const auto &li : patList)
75 {
76 std::string pattern = getter(li);
77 if (!pattern.empty())
78 {
79 size_t i=pattern.find('=');
80 if (i!=std::string::npos) pattern=pattern.substr(0,i); // strip of the extension specific filter name
81
82 if (!caseSenseNames)
83 {
84 pattern = convertUTF8ToLower(pattern);
85 fn = convertUTF8ToLower(fn);
86 fp = convertUTF8ToLower(fp);
87 afp = convertUTF8ToLower(afp);
88 }
89 reg::Ex re(pattern,reg::Ex::Mode::Wildcard);
90 found = re.isValid() && (reg::match(fn,re) ||
91 (fn!=fp && reg::match(fp,re)) ||
92 (fn!=afp && fp!=afp && reg::match(afp,re)));
93 if (found)
94 {
95 if (elem) *elem = li;
96 break;
97 }
98 //printf("Matching '%s' against pattern '%s' found=%d\n",
99 // qPrint(fi->fileName()),qPrint(pattern),found);
100 }
101 }
102 }
103 return found;
104 }
std::string filePath() const
Definition fileinfo.cpp:95
@ Wildcard
simple globbing pattern.
Definition regex.h:45
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:861
std::string convertUTF8ToLower(const std::string &input)
Converts the input string into a lower case version, also taking into account non-ASCII characters th...
Definition utf8.cpp:191

Referenced by checkAndOpenFile(), getEncoding(), and readDir().

◆ readLink()

std::string FileInfo::readLink ( ) const

Definition at line 88 of file fileinfo.cpp.

89{
90 std::error_code ec;
91 fs::path targetPath = fs::read_symlink(fs::path(m_name));
92 return !ec ? targetPath.string() : std::string();
93}

References m_name.

Referenced by resolveSymlink().

◆ size()

size_t FileInfo::size ( ) const

Definition at line 27 of file fileinfo.cpp.

28{
29 std::error_code ec;
30 size_t result = static_cast<size_t>(fs::file_size(fs::path(m_name),ec));
31 return ec ? 0 : result;
32}

References m_name.

Referenced by deliverablesPresent(), insertMapFile(), and readInputFile().

Member Data Documentation

◆ m_name

std::string FileInfo::m_name
private

The documentation for this class was generated from the following files: