Refactoring. Assume that .C files contain C code on case insensitive filesystems.

This commit is contained in:
Daniel Marjamäki 2012-01-08 10:34:31 +01:00
parent 304980848f
commit ee55d3294a
2 changed files with 27 additions and 3 deletions

View File

@ -23,6 +23,17 @@
#include <cctype>
#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;
}

View File

@ -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"));