Move sameFileName() method to Path class.
Ticket #2445 (Move FileLister classes from LIB to CLI). Moving sameFileName() to Path allows moving FileLister* classes to CLI.
This commit is contained in:
parent
75767705c7
commit
86ac25456e
|
@ -49,15 +49,6 @@ public:
|
|||
virtual void recursiveAddFiles(std::vector<std::string> &filenames,
|
||||
const std::string &path) = 0;
|
||||
|
||||
/**
|
||||
* @brief Compare filenames to see if they are the same.
|
||||
* On Linux the comparison is case-sensitive. On Windows it is case-insensitive.
|
||||
* @param fname1 one filename
|
||||
* @param fname2 other filename
|
||||
* @return true if the filenames match on the current platform
|
||||
*/
|
||||
virtual bool sameFileName(const std::string &fname1, const std::string &fname2) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if the file extension indicates that it's a source file.
|
||||
* Check if the file has source file extension: *.c;*.cpp;*.cxx;*.c++;*.cc;*.txx
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "path.h"
|
||||
#include "filelister.h"
|
||||
#include "filelister_unix.h"
|
||||
|
||||
|
@ -71,7 +72,7 @@ void FileListerUnix::recursiveAddFiles2(std::vector<std::string> &relative,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (sameFileName(path,filename) || FileListerUnix::acceptFile(filename))
|
||||
if (Path::sameFileName(path,filename) || FileListerUnix::acceptFile(filename))
|
||||
{
|
||||
relative.push_back(filename);
|
||||
absolute.push_back(fname);
|
||||
|
@ -93,16 +94,6 @@ void FileListerUnix::recursiveAddFiles(std::vector<std::string> &filenames, cons
|
|||
recursiveAddFiles2(filenames, abs, path);
|
||||
}
|
||||
|
||||
bool FileListerUnix::sameFileName(const std::string &fname1, const std::string &fname2)
|
||||
{
|
||||
#if defined(__linux__) || defined(__sun)
|
||||
return bool(fname1 == fname2);
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
return bool(strcasecmp(fname1.c_str(), fname2.c_str()) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FileListerUnix::isDirectory(const std::string &path)
|
||||
{
|
||||
bool ret = false;
|
||||
|
|
|
@ -31,8 +31,6 @@ class FileListerUnix : public FileLister
|
|||
{
|
||||
public:
|
||||
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path);
|
||||
virtual bool sameFileName(const std::string &fname1, const std::string &fname2);
|
||||
// virtual static bool acceptFile(const std::string &filename);
|
||||
virtual bool isDirectory(const std::string &path);
|
||||
private:
|
||||
#ifndef _WIN32
|
||||
|
|
|
@ -168,7 +168,7 @@ void FileListerWin32::recursiveAddFiles(std::vector<std::string> &filenames, con
|
|||
// File
|
||||
|
||||
// If recursive is not used, accept all files given by user
|
||||
if (sameFileName(path,ansiFfd) || FileLister::acceptFile(ansiFfd))
|
||||
if (Path::sameFileName(path,ansiFfd) || FileLister::acceptFile(ansiFfd))
|
||||
{
|
||||
const std::string nativename = Path::fromNativeSeparators(fname.str());
|
||||
filenames.push_back(nativename);
|
||||
|
@ -192,19 +192,6 @@ void FileListerWin32::recursiveAddFiles(std::vector<std::string> &filenames, con
|
|||
}
|
||||
}
|
||||
|
||||
bool FileListerWin32::sameFileName(const std::string &fname1, const std::string &fname2)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
return bool(strcasecmp(fname1.c_str(), fname2.c_str()) == 0);
|
||||
#endif
|
||||
#ifdef __BORLANDC__
|
||||
return bool(stricmp(fname1.c_str(), fname2.c_str()) == 0);
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
return bool(_stricmp(fname1.c_str(), fname2.c_str()) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FileListerWin32::isDirectory(const std::string &path)
|
||||
{
|
||||
return (MyIsDirectory(path) != FALSE);
|
||||
|
|
|
@ -31,7 +31,6 @@ class FileListerWin32 : public FileLister
|
|||
{
|
||||
public:
|
||||
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path);
|
||||
virtual bool sameFileName(const std::string &fname1, const std::string &fname2);
|
||||
virtual bool isDirectory(const std::string &path);
|
||||
private:
|
||||
|
||||
|
|
17
lib/path.cpp
17
lib/path.cpp
|
@ -19,6 +19,7 @@
|
|||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include "path.h"
|
||||
|
||||
std::string Path::toNativeSeparators(const std::string &path)
|
||||
|
@ -97,3 +98,19 @@ std::string Path::simplifyPath(const char *originalPath)
|
|||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
bool Path::sameFileName(const std::string &fname1, const std::string &fname2)
|
||||
{
|
||||
#if defined(__linux__) || defined(__sun)
|
||||
return bool(fname1 == fname2);
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
return bool(strcasecmp(fname1.c_str(), fname2.c_str()) == 0);
|
||||
#endif
|
||||
#ifdef __BORLANDC__
|
||||
return bool(stricmp(fname1.c_str(), fname2.c_str()) == 0);
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
return bool(_stricmp(fname1.c_str(), fname2.c_str()) == 0);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -54,6 +54,15 @@ public:
|
|||
* @return simplified path
|
||||
*/
|
||||
static std::string simplifyPath(const char *originalPath);
|
||||
|
||||
/**
|
||||
* @brief Compare filenames to see if they are the same.
|
||||
* On Linux the comparison is case-sensitive. On Windows it is case-insensitive.
|
||||
* @param fname1 one filename
|
||||
* @param fname2 other filename
|
||||
* @return true if the filenames match on the current platform
|
||||
*/
|
||||
static bool sameFileName(const std::string &fname1, const std::string &fname2);
|
||||
};
|
||||
|
||||
/// @}
|
||||
|
|
|
@ -313,7 +313,7 @@ void Tokenizer::createTokens(std::istream &code)
|
|||
fileIndexes.push_back(FileIndex);
|
||||
for (unsigned int i = 0; i < _files.size(); i++)
|
||||
{
|
||||
if (getFileLister()->sameFileName(_files[i].c_str(), line.c_str()))
|
||||
if (Path::sameFileName(_files[i].c_str(), line.c_str()))
|
||||
{
|
||||
// Use this index
|
||||
foundOurfile = true;
|
||||
|
|
Loading…
Reference in New Issue