From 86ac25456ec535d2434a938f54a6dea61b64f700 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Tue, 18 Jan 2011 18:34:28 +0200 Subject: [PATCH] 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. --- lib/filelister.h | 9 --------- lib/filelister_unix.cpp | 13 ++----------- lib/filelister_unix.h | 2 -- lib/filelister_win32.cpp | 15 +-------------- lib/filelister_win32.h | 1 - lib/path.cpp | 17 +++++++++++++++++ lib/path.h | 9 +++++++++ lib/tokenize.cpp | 2 +- 8 files changed, 30 insertions(+), 38 deletions(-) diff --git a/lib/filelister.h b/lib/filelister.h index 40eef61ea..be4c60016 100644 --- a/lib/filelister.h +++ b/lib/filelister.h @@ -49,15 +49,6 @@ public: virtual void recursiveAddFiles(std::vector &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 diff --git a/lib/filelister_unix.cpp b/lib/filelister_unix.cpp index 12d179910..ed6d12f4b 100644 --- a/lib/filelister_unix.cpp +++ b/lib/filelister_unix.cpp @@ -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 &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 &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; diff --git a/lib/filelister_unix.h b/lib/filelister_unix.h index 7fab425b4..f0b4e4c96 100644 --- a/lib/filelister_unix.h +++ b/lib/filelister_unix.h @@ -31,8 +31,6 @@ class FileListerUnix : public FileLister { public: virtual void recursiveAddFiles(std::vector &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 diff --git a/lib/filelister_win32.cpp b/lib/filelister_win32.cpp index 9581d3fd3..041613331 100644 --- a/lib/filelister_win32.cpp +++ b/lib/filelister_win32.cpp @@ -168,7 +168,7 @@ void FileListerWin32::recursiveAddFiles(std::vector &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 &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); diff --git a/lib/filelister_win32.h b/lib/filelister_win32.h index 2d6948145..4f89438bd 100644 --- a/lib/filelister_win32.h +++ b/lib/filelister_win32.h @@ -31,7 +31,6 @@ class FileListerWin32 : public FileLister { public: virtual void recursiveAddFiles(std::vector &filenames, const std::string &path); - virtual bool sameFileName(const std::string &fname1, const std::string &fname2); virtual bool isDirectory(const std::string &path); private: diff --git a/lib/path.cpp b/lib/path.cpp index cf8383116..6660e5089 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #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 +} diff --git a/lib/path.h b/lib/path.h index ce8143a29..2de7a1653 100644 --- a/lib/path.h +++ b/lib/path.h @@ -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); }; /// @} diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bbc54c538..9adc3d642 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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;