Skip to content

Commit ee55d32

Browse files
committed
Refactoring. Assume that .C files contain C code on case insensitive filesystems.
1 parent 3049808 commit ee55d32

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

lib/path.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
#include <cctype>
2424
#include "path.h"
2525

26+
/** Is the filesystem case insensitive? */
27+
static bool caseInsensitiveFilesystem()
28+
{
29+
#ifdef _WIN32
30+
return true;
31+
#else
32+
// TODO: Non-windows filesystems might be case insensitive
33+
return false;
34+
#endif
35+
}
36+
2637
std::string Path::toNativeSeparators(std::string path)
2738
{
2839
#if defined(_WIN32)
@@ -127,7 +138,12 @@ std::string Path::getFilenameExtension(const std::string &path)
127138
if (dotLocation == std::string::npos)
128139
return "";
129140

130-
const std::string extension = path.substr(dotLocation);
141+
std::string extension = path.substr(dotLocation);
142+
if (caseInsensitiveFilesystem()) {
143+
// on a case insensitive filesystem the case doesn't matter so
144+
// let's return the extension in lowercase
145+
std::transform(extension.begin(), extension.end(), extension.begin(), tolowerWrapper);
146+
}
131147
return extension;
132148
}
133149

test/testpath.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,22 @@ class TestPath : public TestFixture {
8484
ASSERT(Path::isC("C:\\foo\\index.c"));
8585

8686
// In unix .C is considered C++
87-
ASSERT(Path::isC("C:\\foo\\index.C")==false);
87+
#ifdef _WIN32
88+
ASSERT_EQUALS(true, Path::isC("C:\\foo\\index.C"));
89+
#else
90+
ASSERT_EQUALS(false, Path::isC("C:\\foo\\index.C"));
91+
#endif
8892
}
8993

9094
void is_cpp() {
9195
ASSERT(Path::isCPP("index.c")==false);
9296

9397
// In unix .C is considered C++
94-
ASSERT(Path::isCPP("index.C"));
98+
#ifdef _WIN32
99+
ASSERT_EQUALS(false, Path::isCPP("index.C"));
100+
#else
101+
ASSERT_EQUALS(true, Path::isCPP("index.C"));
102+
#endif
95103
ASSERT(Path::isCPP("index.cpp"));
96104
ASSERT(Path::isCPP("C:\\foo\\index.cpp"));
97105
ASSERT(Path::isCPP("C:\\foo\\index.Cpp"));

0 commit comments

Comments
 (0)