From 4ed24a06191a0dbf68bd72ad0fcc8d467b37f580 Mon Sep 17 00:00:00 2001
From: archshift <admin@archshift.com>
Date: Sun, 7 Sep 2014 00:49:52 -0700
Subject: loader.cpp: improved file extension checking, made Upper/LowerStr
 useful

Instead of forcibly taking the last 4 characters, it now finds the last extension separator (the period) and takes a substr of its location.
---
 src/core/loader/loader.cpp | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

(limited to 'src/core/loader/loader.cpp')

diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 365f5a2777..ce1154b792 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -26,21 +26,23 @@ FileType IdentifyFile(const std::string &filename) {
         ERROR_LOG(LOADER, "invalid filename %s", filename.c_str());
         return FileType::Error;
     }
-    std::string extension = filename.size() >= 5 ? filename.substr(filename.size() - 4) : "";
 
-    if (!strcasecmp(extension.c_str(), ".elf")) {
+    size_t extension_loc = filename.find_last_of('.');
+    std::string extension = extension_loc != std::string::npos ? filename.substr(extension_loc) : "";
+
+    if (LowerStr(extension) == ".elf") {
         return FileType::ELF; // TODO(bunnei): Do some filetype checking :p
     }
-    else if (!strcasecmp(extension.c_str(), ".axf")) {
+    else if (LowerStr(extension) == ".axf") {
         return FileType::ELF; // TODO(bunnei): Do some filetype checking :p
     }
-    else if (!strcasecmp(extension.c_str(), ".cxi")) {
+    else if (LowerStr(extension) == ".cxi") {
         return FileType::CXI; // TODO(bunnei): Do some filetype checking :p
     }
-    else if (!strcasecmp(extension.c_str(), ".cci")) {
+    else if (LowerStr(extension) == ".cci") {
         return FileType::CCI; // TODO(bunnei): Do some filetype checking :p
     }
-    else if (!strcasecmp(extension.c_str(), ".bin")) {
+    else if (LowerStr(extension) == ".bin") {
         return FileType::BIN; // TODO(bunnei): Do some filetype checking :p
     }
     return FileType::Unknown;
-- 
cgit v1.2.3-70-g09d2