From ee55d3294a00d4e570f0ffc1b32c8479a3d1a5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 Jan 2012 10:34:31 +0100 Subject: [PATCH] Refactoring. Assume that .C files contain C code on case insensitive filesystems. --- lib/path.cpp | 18 +++++++++++++++++- test/testpath.cpp | 12 ++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/path.cpp b/lib/path.cpp index 4ef2f43e1..86215e276 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -23,6 +23,17 @@ #include #include "path.h" +/** Is the filesystem case insensitive? */ +static bool caseInsensitiveFilesystem() +{ +#ifdef _WIN32 + return true; +#else + // TODO: Non-windows filesystems might be case insensitive + return false; +#endif +} + std::string Path::toNativeSeparators(std::string path) { #if defined(_WIN32) @@ -127,7 +138,12 @@ std::string Path::getFilenameExtension(const std::string &path) if (dotLocation == std::string::npos) return ""; - const std::string extension = path.substr(dotLocation); + std::string extension = path.substr(dotLocation); + if (caseInsensitiveFilesystem()) { + // on a case insensitive filesystem the case doesn't matter so + // let's return the extension in lowercase + std::transform(extension.begin(), extension.end(), extension.begin(), tolowerWrapper); + } return extension; } diff --git a/test/testpath.cpp b/test/testpath.cpp index c80e6ba83..e376d1f23 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -84,14 +84,22 @@ private: ASSERT(Path::isC("C:\\foo\\index.c")); // In unix .C is considered C++ - ASSERT(Path::isC("C:\\foo\\index.C")==false); +#ifdef _WIN32 + ASSERT_EQUALS(true, Path::isC("C:\\foo\\index.C")); +#else + ASSERT_EQUALS(false, Path::isC("C:\\foo\\index.C")); +#endif } void is_cpp() { ASSERT(Path::isCPP("index.c")==false); // In unix .C is considered C++ - ASSERT(Path::isCPP("index.C")); +#ifdef _WIN32 + ASSERT_EQUALS(false, Path::isCPP("index.C")); +#else + ASSERT_EQUALS(true, Path::isCPP("index.C")); +#endif ASSERT(Path::isCPP("index.cpp")); ASSERT(Path::isCPP("C:\\foo\\index.cpp")); ASSERT(Path::isCPP("C:\\foo\\index.Cpp"));