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 106 of file fileinfo.cpp.

107{
108 std::string result;
109 std::error_code ec;
110 fs::path path = toFsPath(m_name);
111 if (!path.is_relative())
112 {
113 result = fromFsPath(path.lexically_normal());
114 }
115 else
116 {
117 result = fromFsPath((fs::current_path(ec) / path).lexically_normal());
118 }
119 correctPath(result);
120 return result;
121}
static void correctPath(std::string &s)
Definition fileinfo.cpp:101
std::string fromFsPath(const fs::path &p)
Converts a path into a UTF-8 encoded string.
Definition fswrapper.h:78
fs::path toFsPath(const std::string &s)
Converts a UTF-8 encoded string into a path.
Definition fswrapper.h:64

References correctPath(), fromFsPath(), m_name, and toFsPath().

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 128 of file fileinfo.cpp.

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

References fileName().

Referenced by parseMain().

◆ correctPath()

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

Definition at line 101 of file fileinfo.cpp.

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

Referenced by absFilePath(), and dirPath().

◆ dirPath()

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

Definition at line 142 of file fileinfo.cpp.

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

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

Referenced by Config::checkAndCorrect(), computeVerifiedDotPath(), 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 135 of file fileinfo.cpp.

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

References fileName().

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

◆ fileName()

◆ filePath()

std::string FileInfo::filePath ( ) const

Definition at line 96 of file fileinfo.cpp.

97{
98 return m_name;
99}

References m_name.

Referenced by openOutputFile().

◆ isDir()

bool FileInfo::isDir ( ) const

Definition at line 75 of file fileinfo.cpp.

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

References m_name, and toFsPath().

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 56 of file fileinfo.cpp.

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

References m_name, and toFsPath().

◆ isFile()

bool FileInfo::isFile ( ) const

Definition at line 68 of file fileinfo.cpp.

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

References m_name, and toFsPath().

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 49 of file fileinfo.cpp.

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

References m_name, and toFsPath().

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

◆ isRelative()

bool FileInfo::isRelative ( ) const

Definition at line 63 of file fileinfo.cpp.

64{
65 return toFsPath(m_name).is_relative();
66}

References m_name, and toFsPath().

Referenced by computeVerifiedDotPath(), and resolveSymlink().

◆ isSymLink()

bool FileInfo::isSymLink ( ) const

Definition at line 82 of file fileinfo.cpp.

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

References m_name, and toFsPath().

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

◆ isWritable()

bool FileInfo::isWritable ( ) const

Definition at line 42 of file fileinfo.cpp.

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

References m_name, and toFsPath().

◆ 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:96
@ 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 89 of file fileinfo.cpp.

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

References fromFsPath(), m_name, and toFsPath().

Referenced by resolveSymlink().

◆ size()

size_t FileInfo::size ( ) const

Definition at line 28 of file fileinfo.cpp.

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

References m_name, and toFsPath().

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: