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:
Kimmo Varis 2011-01-18 18:34:28 +02:00 committed by Kimmo Varis
parent 75767705c7
commit 86ac25456e
8 changed files with 30 additions and 38 deletions

View File

@ -49,15 +49,6 @@ public:
virtual void recursiveAddFiles(std::vector<std::string> &filenames, virtual void recursiveAddFiles(std::vector<std::string> &filenames,
const std::string &path) = 0; 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. * @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 * Check if the file has source file extension: *.c;*.cpp;*.cxx;*.c++;*.cc;*.txx

View File

@ -31,6 +31,7 @@
#ifndef _WIN32 #ifndef _WIN32
#include "path.h"
#include "filelister.h" #include "filelister.h"
#include "filelister_unix.h" #include "filelister_unix.h"
@ -71,7 +72,7 @@ void FileListerUnix::recursiveAddFiles2(std::vector<std::string> &relative,
continue; continue;
} }
if (sameFileName(path,filename) || FileListerUnix::acceptFile(filename)) if (Path::sameFileName(path,filename) || FileListerUnix::acceptFile(filename))
{ {
relative.push_back(filename); relative.push_back(filename);
absolute.push_back(fname); absolute.push_back(fname);
@ -93,16 +94,6 @@ void FileListerUnix::recursiveAddFiles(std::vector<std::string> &filenames, cons
recursiveAddFiles2(filenames, abs, path); 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 FileListerUnix::isDirectory(const std::string &path)
{ {
bool ret = false; bool ret = false;

View File

@ -31,8 +31,6 @@ class FileListerUnix : public FileLister
{ {
public: public:
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path); 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); virtual bool isDirectory(const std::string &path);
private: private:
#ifndef _WIN32 #ifndef _WIN32

View File

@ -168,7 +168,7 @@ void FileListerWin32::recursiveAddFiles(std::vector<std::string> &filenames, con
// File // File
// If recursive is not used, accept all files given by user // 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()); const std::string nativename = Path::fromNativeSeparators(fname.str());
filenames.push_back(nativename); 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) bool FileListerWin32::isDirectory(const std::string &path)
{ {
return (MyIsDirectory(path) != FALSE); return (MyIsDirectory(path) != FALSE);

View File

@ -31,7 +31,6 @@ class FileListerWin32 : public FileLister
{ {
public: public:
virtual void recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path); 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); virtual bool isDirectory(const std::string &path);
private: private:

View File

@ -19,6 +19,7 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <cstring>
#include "path.h" #include "path.h"
std::string Path::toNativeSeparators(const std::string &path) std::string Path::toNativeSeparators(const std::string &path)
@ -97,3 +98,19 @@ std::string Path::simplifyPath(const char *originalPath)
return oss.str(); 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
}

View File

@ -54,6 +54,15 @@ public:
* @return simplified path * @return simplified path
*/ */
static std::string simplifyPath(const char *originalPath); 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);
}; };
/// @} /// @}

View File

@ -313,7 +313,7 @@ void Tokenizer::createTokens(std::istream &code)
fileIndexes.push_back(FileIndex); fileIndexes.push_back(FileIndex);
for (unsigned int i = 0; i < _files.size(); i++) 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 // Use this index
foundOurfile = true; foundOurfile = true;