Cppcheck
|
Path handling routines. More...
#include <path.h>
Static Public Member Functions | |
static std::string | toNativeSeparators (std::string path) |
Convert path to use native separators. More... | |
static std::string | fromNativeSeparators (std::string path) |
Convert path to use internal path separators. More... | |
static std::string | simplifyPath (std::string originalPath) |
Simplify path "foo/bar/.." => "foo". More... | |
static std::string | getPathFromFilename (const std::string &filename) |
Lookup the path part from a filename (e.g., '/tmp/a.h' -> '/tmp/', 'a.h' -> '') More... | |
static bool | sameFileName (const std::string &fname1, const std::string &fname2) |
Compare filenames to see if they are the same. More... | |
static std::string | removeQuotationMarks (std::string path) |
Remove quotation marks (") from the path. More... | |
static std::string | getFilenameExtension (const std::string &path, bool lowercase=false) |
Get an extension of the filename. More... | |
static std::string | getFilenameExtensionInLowerCase (const std::string &path) |
Get an extension of the filename in lower case. More... | |
static std::string | getCurrentPath () |
Returns the absolute path of current working directory. More... | |
static std::string | getCurrentExecutablePath (const char *fallback) |
Returns the absolute path to the current executable. More... | |
static bool | isAbsolute (const std::string &path) |
Check if given path is absolute. More... | |
static std::string | getRelativePath (const std::string &absolutePath, const std::vector< std::string > &basePaths) |
Create a relative path from an absolute one, if absolute path is inside the basePaths. More... | |
static std::string | getAbsoluteFilePath (const std::string &filePath) |
Get an absolute file path from a relative one. More... | |
static bool | acceptFile (const std::string &filename) |
Check if the file extension indicates that it's a C/C++ source file. More... | |
static bool | acceptFile (const std::string &path, const std::set< std::string > &extra) |
Check if the file extension indicates that it's a C/C++ source file. More... | |
static DEPRECATED bool | isC (const std::string &path) |
Identify language based on file extension. More... | |
static DEPRECATED bool | isCPP (const std::string &path) |
Identify language based on file extension. More... | |
static DEPRECATED bool | isHeader (const std::string &path) |
Is filename a header based on file extension. More... | |
static bool | isHeader2 (const std::string &path) |
Is filename a header based on file extension. More... | |
static Standards::Language | identify (const std::string &path, bool *header=nullptr) |
Identify the language based on the file extension. More... | |
static std::string | stripDirectoryPart (const std::string &file) |
Get filename without a directory path part. More... | |
static bool | isFile (const std::string &path) |
Checks if given path is a file. More... | |
static bool | isDirectory (const std::string &path) |
Checks if a given path is a directory. More... | |
static std::string | join (const std::string &path1, const std::string &path2) |
join 2 paths with '/' separators More... | |
Path handling routines.
Internally cppcheck wants to store paths with / separator which is also native separator for Unix-derived systems. When giving path to user or for other functions we convert path separators back to native type.
|
inlinestatic |
Check if the file extension indicates that it's a C/C++ source file.
Check if the file has source file extension: *.c;*.cpp;*.cxx;*.c++;*.cc;*.txx
filename | filename to check. path info is optional |
Definition at line 142 of file path.h.
Referenced by addFiles2(), ImportProject::importBcb6Prj(), ImportProject::importCompileCommands(), and ImportProject::importVcxproj().
|
static |
Check if the file extension indicates that it's a C/C++ source file.
Check if the file has source file extension: *.c;*.cpp;*.cxx;*.c++;*.cc;*.txx
path | filename to check. path info is optional |
extra | extra file extensions |
Definition at line 235 of file path.cpp.
References getFilenameExtension(), and identify().
|
static |
Convert path to use internal path separators.
path | Path string to convert. |
Definition at line 75 of file path.cpp.
References replace().
Referenced by addIncludePathsToList(), CppCheck::checkClang(), CppCheck::checkFile(), Preprocessor::error(), ImportProject::fsSetIncludePaths(), AddonInfo::getAddonInfo(), ImportProject::import(), ImportProject::importCompileCommands(), ImportProject::importSln(), Library::load(), Platform::loadFromFile(), CmdLineParser::loadLibraries(), PathMatch::match(), CmdLineParser::parseFromArgs(), ErrorMessage::FileLocation::setfile(), ImportProject::setRelativePaths(), simplifyPathWithVariables(), and AnalyzerInformation::writeFilesTxt().
|
static |
Get an absolute file path from a relative one.
filePath | File path to be made absolute. |
Definition at line 284 of file path.cpp.
Referenced by Library::load(), and loadVisualStudioProperties().
|
static |
Returns the absolute path to the current executable.
Definition at line 143 of file path.cpp.
Referenced by Library::load(), and CmdLineParser::parseFromArgs().
|
static |
Returns the absolute path of current working directory.
Definition at line 129 of file path.cpp.
Referenced by PathMatch::PathMatch(), and ImportProject::setRelativePaths().
|
static |
Get an extension of the filename.
path | Path containing filename. |
lowercase | Return the extension in lower case |
Definition at line 109 of file path.cpp.
References caseInsensitiveFilesystem(), and strTolower().
Referenced by acceptFile(), getFilenameExtensionInLowerCase(), identify(), isC(), isCPP(), and Library::load().
|
static |
Get an extension of the filename in lower case.
path | Path containing filename. |
Definition at line 124 of file path.cpp.
References getFilenameExtension().
Referenced by Library::blockend(), Library::blockstart(), Library::blockstartoffset(), ImportProject::importBcb6Prj(), isCPP(), Library::isexecutableblock(), isHeader(), Library::isimporter(), Library::iskeyword(), Library::markupFile(), Library::processMarkupAfterCode(), and Library::reportErrors().
|
static |
Lookup the path part from a filename (e.g., '/tmp/a.h' -> '/tmp/', 'a.h' -> '')
filename | filename to lookup, must have / -separators. |
Definition at line 88 of file path.cpp.
Referenced by CppCheck::executeAddons(), getFullPath(), ImportProject::import(), ImportProject::importBcb6Prj(), ImportProject::importVcxproj(), Library::load(), Settings::loadCppcheckCfg(), Platform::loadFromFile(), CmdLineParser::loadLibraries(), loadVisualStudioProperties(), and LibraryDialog::saveCfgAs().
|
static |
Create a relative path from an absolute one, if absolute path is inside the basePaths.
absolutePath | Path to be made relative. |
basePaths | Paths to which it may be made relative. |
Definition at line 181 of file path.cpp.
References endsWith().
Referenced by CppCheck::checkFile(), TokenList::createTokens(), Tokenizer::dump(), Preprocessor::error(), CppCheck::getDumpFileContentsRawTokens(), PathMatch::match(), and ImportProject::setRelativePaths().
|
static |
Identify the language based on the file extension.
path | filename to check. path info is optional |
header | if provided indicates if the file is a header |
Definition at line 248 of file path.cpp.
References c_src_exts, caseInsensitiveFilesystem(), cpp_src_exts, getFilenameExtension(), header_exts, and strTolower().
Referenced by acceptFile(), CppCheck::checkClang(), CppCheck::checkFile(), createDUI(), createDumpFile(), TokenList::determineCppC(), and isHeader2().
|
static |
Check if given path is absolute.
path | Path to check |
Definition at line 166 of file path.cpp.
References startsWith(), and toNativeSeparators().
Referenced by ImportProject::ignorePaths(), ImportProject::importBcb6Prj(), ImportProject::importCompileCommands(), ImportProject::importSln(), ImportProject::importVcxproj(), joinRelativePath(), Settings::loadCppcheckCfg(), loadVisualStudioProperties(), PathMatch::match(), and ImportProject::setRelativePaths().
|
static |
Identify language based on file extension.
path | filename to check. path info is optional |
Definition at line 210 of file path.cpp.
References getFilenameExtension().
|
static |
Identify language based on file extension.
path | filename to check. path info is optional |
Definition at line 218 of file path.cpp.
References getFilenameExtension(), and getFilenameExtensionInLowerCase().
|
static |
Checks if a given path is a directory.
path | Path to be checked |
Definition at line 334 of file path.cpp.
References file_type().
Referenced by addFiles2(), CmdLineParser::fillSettingsFromArgs(), and CmdLineParser::parseFromArgs().
|
static |
Checks if given path is a file.
path | Path to be checked |
Definition at line 329 of file path.cpp.
References file_type().
Referenced by getFullPath(), Settings::loadCppcheckCfg(), and ImportProject::sourceFileExists().
|
static |
Is filename a header based on file extension.
path | filename to check. path info is optional |
Definition at line 242 of file path.cpp.
References getFilenameExtensionInLowerCase(), and startsWith().
|
static |
Is filename a header based on file extension.
path | filename to check. path info is optional |
Definition at line 277 of file path.cpp.
References identify().
Referenced by ResultsTree::recheckSelectedFiles(), and ResultsView::updateDetails().
|
static |
join 2 paths with '/' separators
Definition at line 339 of file path.cpp.
Referenced by AnalyzerInformation::getAnalyzerInfoFile(), and Settings::loadCppcheckCfg().
|
static |
Remove quotation marks (") from the path.
path | path to be cleaned. |
Definition at line 103 of file path.cpp.
Referenced by addIncludePathsToList(), and CmdLineParser::parseFromArgs().
|
static |
Compare filenames to see if they are the same.
On Linux the comparison is case-sensitive. On Windows it is case-insensitive.
fname1 | one filename |
fname2 | other filename |
Definition at line 98 of file path.cpp.
References caseInsensitiveFilesystem(), and caseInsensitiveStringCompare().
Referenced by TokenList::appendFileIfNew().
|
static |
Simplify path "foo/bar/.." => "foo".
originalPath | path to be simplified, must have / -separators. |
Definition at line 83 of file path.cpp.
Referenced by addInlineSuppressions(), SuppressionList::addSuppressionLine(), CppCheck::analyseClangTidy(), CppCheck::check(), CppCheck::checkFile(), ImportProject::fsSetIncludePaths(), AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(), SuppressionList::getUnmatchedLocalSuppressions(), ImportProject::importBcb6Prj(), ImportProject::importCompileCommands(), ImportProject::importVcxproj(), CmdLineParser::parseFromArgs(), ErrorMessage::FileLocation::setfile(), SuppressionList::ErrorMessage::setFileName(), simplifyPathWithVariables(), and AnalyzerInformation::writeFilesTxt().
|
static |
Get filename without a directory path part.
file | filename to be stripped. path info is optional |
Definition at line 302 of file path.cpp.
Referenced by bailoutInternal(), ValueType::setDebugPath(), and setSourceLocation().
|
static |
Convert path to use native separators.
path | Path string to convert. |
Definition at line 62 of file path.cpp.
References replace().
Referenced by CppCheck::analyseClangTidy(), CppCheck::checkFile(), cmdFileName(), CmdLineParser::fillSettingsFromArgs(), ErrorMessage::FileLocation::getfile(), ErrorMessage::FileLocation::getOrigFile(), ImportProject::importSln(), isAbsolute(), CmdLineParser::parseFromArgs(), reportClangErrors(), and ErrorMessage::FileLocation::stringify().