OSDN Git Service

[VM][Qt] Kick out functions depending to Qt from src/*.cpp .
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 13 Dec 2015 09:03:49 +0000 (18:03 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 13 Dec 2015 09:03:49 +0000 (18:03 +0900)
source/src/common.cpp
source/src/common.h
source/src/config.cpp
source/src/fileio.h

index 14b5dd3..f890b48 100644 (file)
@@ -12,7 +12,8 @@
 #include "config.h"
 #include "agar_logger.h"
 #include <string>
-
+#include <algorithm>
+#include <cctype>
 #else
 # include <windows.h>
 # include <shlwapi.h>
@@ -410,24 +411,23 @@ uint8 A_OF_COLOR(scrntype c)
 
 
 #include "fileio.h"
+struct to_upper {  // Refer from documentation of libstdc++, GCC5.
+       char operator() (char c) const { return std::toupper(c); }
+};
 
 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext)
 {
-#if defined(_USE_AGAR)
-       int nam_len = strlen(file_path);
-       int ext_len = strlen(ext);
-       
-       return (nam_len >= ext_len && strncmp(&file_path[nam_len - ext_len], ext, ext_len) == 0);
-#elif defined(_USE_QT)
-        QString s_fpath = file_path;
-        QString s_ext = ext;
-        bool f = false;
-        s_fpath = s_fpath.toUpper();
-        s_ext = s_ext.toUpper();
-        if(s_fpath.length() < s_ext.length()) return false;
-        s_fpath = s_fpath.right(s_ext.length());
-        if(s_fpath == s_ext) return true;
-        return false;
+#if defined(_USE_QT)
+       std::string s_fpath = file_path;
+       std::string s_ext = ext;
+       bool f = false;
+       int pos;
+       std::transform(s_fpath.begin(), s_fpath.end(), s_fpath.begin(), to_upper());
+       std::transform(s_ext.begin(), s_ext.end(), s_ext.begin(), to_upper());
+       if(s_fpath.length() < s_ext.length()) return false;
+       pos = s_fpath.rfind(s_ext.c_str(), s_fpath.length());
+       if((pos != std::string::npos) && (pos >= (s_fpath.length() - s_ext.length()))) return true; 
+       return false;
 #else
        int nam_len = _tcslen(file_path);
        int ext_len = _tcslen(ext);
index 4372a02..54c72bd 100644 (file)
 
 #if defined(_USE_QT)
 # if defined(_USE_QT5)
-#  include <QString>
-#  include <QFile>
 #  include <QtEndian>
 # else
-#  include <QtCore/QString>
-#  include <QtCore/QFile>
 # endif
 #endif
 
index d7f4eea..368dbd3 100644 (file)
@@ -18,8 +18,6 @@
 #if defined(_USE_QT)
 #include <string>
 #include <vector>
-#include <QString>
-#include <QStringList>
 #include "fileio.h"
 #include "agar_logger.h"
 #include "qt_main.h"
index 2b237a7..73e3dd2 100644 (file)
 #define _FILEIO_H_
 
 #ifdef _USE_AGAR
-#include <agar/core.h>
 #elif defined(_USE_QT)
-#include <QtCore/QFile>
-#include <QtCore/QFileInfo>
 #else
 #include <windows.h>
 #endif