MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / caseInsensitive

Function caseInsensitive

src/Engine/CrossPlatform.cpp:311–340  ·  view source on GitHub ↗

* Takes a path and tries to find it based on the * system's case-sensitivity. * @param base Base unaltered path. * @param path Full path to check for casing. * @return Correct filename or "" if it doesn't exist. * @note There's no actual method for figuring out the correct * filename on case-sensitive systems, this is just a workaround. */

Source from the content-addressed store, hash-verified

309 * filename on case-sensitive systems, this is just a workaround.
310 */
311std::string caseInsensitive(const std::string &base, const std::string &path)
312{
313 std::string fullPath = base + path, newPath = path;
314
315 // Try all various case mutations
316 // Normal unmangled
317 if (fileExists(fullPath.c_str()))
318 {
319 return fullPath;
320 }
321
322 // UPPERCASE
323 std::transform(newPath.begin(), newPath.end(), newPath.begin(), toupper);
324 fullPath = base + newPath;
325 if (fileExists(fullPath.c_str()))
326 {
327 return fullPath;
328 }
329
330 // lowercase
331 std::transform(newPath.begin(), newPath.end(), newPath.begin(), tolower);
332 fullPath = base + newPath;
333 if (fileExists(fullPath.c_str()))
334 {
335 return fullPath;
336 }
337
338 // If we got here nothing can help us
339 return "";
340}
341
342/**
343 * Takes a path and tries to find it based on the

Callers 1

getDataFileFunction · 0.85

Calls 1

fileExistsFunction · 0.85

Tested by

no test coverage detected