Cppcheck
Static Public Member Functions | Static Private Member Functions
Path Class Reference

Path handling routines. More...

#include <path.h>

List of all members.

Static Public Member Functions

static std::string toNativeSeparators (std::string path)
 Convert path to use native separators.
static std::string fromNativeSeparators (std::string path)
 Convert path to use internal path separators.
static std::string simplifyPath (const char *originalPath)
 Simplify path "foo/bar/.." => "foo".
static std::string getPathFromFilename (const std::string &filename)
 Lookup the path part from a filename (e.g., '/tmp/a.h' -> '/tmp/', 'a.h' -> '')
static bool sameFileName (const std::string &fname1, const std::string &fname2)
 Compare filenames to see if they are the same.
static std::string removeQuotationMarks (std::string path)
 Remove quotation marks (") from the path.
static std::string getFilenameExtension (const std::string &path)
 Get an extension of the filename.
static std::string getFilenameExtensionInLowerCase (const std::string &path)
 Get an extension of the filename in lower case.
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.
static bool acceptFile (const std::string &filename)
 Check if the file extension indicates that it's a C/C++ source file.
static bool isC (const std::string &path)
 Identify language based on file extension.
static bool isCPP (const std::string &extensionInLowerCase)
 Identify language based on file extension.

Static Private Member Functions

static bool isHeader (const std::string &path)
 Is filename a header based on file extension.

Detailed Description

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.

Definition at line 36 of file path.h.


Member Function Documentation

bool Path::acceptFile ( const std::string &  filename) [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

Parameters:
pathfilename to check. path info is optional
Returns:
returns true if the file extension indicates it should be checked

Definition at line 209 of file path.cpp.

References isC(), isCPP(), and isHeader().

Referenced by CppCheck::processFile(), and FileLister::recursiveAddFiles2().

std::string Path::fromNativeSeparators ( std::string  path) [static]

Convert path to use internal path separators.

Parameters:
pathPath string to convert.
Returns:
converted path.

Definition at line 50 of file path.cpp.

Referenced by AddInclPathsToList(), Suppressions::addSuppressionLine(), Preprocessor::handleIncludes(), Preprocessor::missingInclude(), CmdLineParser::ParseFromArgs(), and ErrorLogger::ErrorMessage::FileLocation::setfile().

std::string Path::getFilenameExtension ( const std::string &  path) [static]

Get an extension of the filename.

Parameters:
pathPath containing filename.
Returns:
Filename extension (containing the dot, e.g. ".h" or ".CPP").

Definition at line 148 of file path.cpp.

References caseInsensitiveFilesystem(), and tolowerWrapper().

Referenced by getFilenameExtensionInLowerCase(), isC(), isCPP(), and CppCheckExecutor::parseFromArgs().

std::string Path::getFilenameExtensionInLowerCase ( const std::string &  path) [static]

Get an extension of the filename in lower case.

Parameters:
pathPath containing filename.
Returns:
Filename extension (containing the dot, e.g. ".h").

Definition at line 163 of file path.cpp.

References getFilenameExtension(), and tolowerWrapper().

Referenced by isCPP(), and isHeader().

std::string Path::getPathFromFilename ( const std::string &  filename) [static]

Lookup the path part from a filename (e.g., '/tmp/a.h' -> '/tmp/', 'a.h' -> '')

Parameters:
filenamefilename to lookup, must have / -separators.
Returns:
path part of the filename

Definition at line 107 of file path.cpp.

std::string Path::getRelativePath ( const std::string &  absolutePath,
const std::vector< std::string > &  basePaths 
) [static]

Create a relative path from an absolute one, if absolute path is inside the basePaths.

Parameters:
absolutePathPath to be made relative.
basePathsPaths to which it may be made relative.
Returns:
relative path, if possible. Otherwise absolutePath is returned unchanged

Definition at line 170 of file path.cpp.

Referenced by TokenList::createTokens(), and Tokenizer::tokenize().

bool Path::isC ( const std::string &  path) [static]

Identify language based on file extension.

Parameters:
pathfilename to check. path info is optional
Returns:
true if extension is meant for C files

Definition at line 185 of file path.cpp.

References getFilenameExtension().

Referenced by acceptFile().

bool Path::isCPP ( const std::string &  extensionInLowerCase) [static]

Identify language based on file extension.

Parameters:
pathfilename to check. path info is optional
Returns:
true if extension is meant for C++ files

Definition at line 192 of file path.cpp.

References getFilenameExtension(), and getFilenameExtensionInLowerCase().

Referenced by acceptFile(), and Preprocessor::getcode().

bool Path::isHeader ( const std::string &  path) [static, private]

Is filename a header based on file extension.

Parameters:
pathfilename to check. path info is optional
Returns:
true if filename extension is meant for headers

Definition at line 214 of file path.cpp.

References getFilenameExtensionInLowerCase().

Referenced by acceptFile().

std::string Path::removeQuotationMarks ( std::string  path) [static]

Remove quotation marks (") from the path.

Parameters:
pathpath to be cleaned.
Returns:
Cleaned path without quotation marks.

Definition at line 142 of file path.cpp.

Referenced by AddInclPathsToList(), and CmdLineParser::ParseFromArgs().

bool Path::sameFileName ( const std::string &  fname1,
const std::string &  fname2 
) [static]

Compare filenames to see if they are the same.

On Linux the comparison is case-sensitive. On Windows it is case-insensitive.

Parameters:
fname1one filename
fname2other filename
Returns:
true if the filenames match on the current platform

Definition at line 120 of file path.cpp.

Referenced by TokenList::createTokens(), and FileLister::recursiveAddFiles2().

std::string Path::simplifyPath ( const char *  originalPath) [static]

Simplify path "foo/bar/.." => "foo".

Parameters:
originalPathpath to be simplified, must have / -separators.
Returns:
simplified path

Definition at line 58 of file path.cpp.

Referenced by Suppressions::FileMatcher::addFile(), TokenList::createTokens(), Preprocessor::handleIncludes(), CmdLineParser::ParseFromArgs(), CppCheck::processFile(), ErrorLogger::ErrorMessage::FileLocation::setfile(), and Tokenizer::tokenize().

std::string Path::toNativeSeparators ( std::string  path) [static]

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