diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 87409de9b..9a90ff7fa 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -66,10 +66,9 @@ #include #include #include +#include using namespace std; -#include - // Defines to help with path handling #if defined BSPF_UNIX #define BSPF_PATH_SEPARATOR "/" @@ -78,7 +77,7 @@ using namespace std; #elif defined BSPF_MAC_OSX #define BSPF_PATH_SEPARATOR "/" #elif defined BSPF_GP2X - #define BSPF_PATH_SEPARATOR "/" + #define BSPF_PATH_SEPARATOR "/" #endif // I wish Windows had a complete POSIX layer @@ -110,15 +109,17 @@ using namespace std; #endif // Some convenience functions -template inline void BSPF_swap(T &a, T &b) { T tmp = a; a = b; b = tmp; } +template inline void BSPF_swap(T& a, T& b) { T tmp = a; a = b; b = tmp; } template inline T BSPF_abs (T x) { return (x>=0) ? x : -x; } template inline T BSPF_min (T a, T b) { return (a inline T BSPF_max (T a, T b) { return (a>b) ? a : b; } -inline string BSPF_tolower(const string& s) +inline bool BSPF_equalsIgnoreCase(const string& s1, const string& s2) { - string t = s; - transform(t.begin(), t.end(), t.begin(), (int(*)(int)) tolower); - return t; + return BSPF_strcasecmp(s1.c_str(), s2.c_str()) == 0; +} +inline bool BSPF_equalsIgnoreCase(const char* s1, const char* s2) +{ + return BSPF_strcasecmp(s1, s2) == 0; } static const string EmptyString(""); diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 9be4d2222..ac6c1dec9 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -1027,7 +1027,7 @@ const FrameBuffer::VideoMode FrameBuffer:: // If it's 'auto', we just use the mode as already previously defined // If it's not 'auto', attempt to fit the mode into the resolution // specified by 'fullres' (if possible) - if(isFullscreen && BSPF_tolower(settings.getString("fullres")) != "auto") + if(isFullscreen && !BSPF_equalsIgnoreCase(settings.getString("fullres"), "auto")) { // Only use 'fullres' if it's *bigger* than the requested mode int w, h; @@ -1085,8 +1085,8 @@ void FrameBuffer::VideoModeList::setByGfxMode(const string& name) GraphicsMode gfxmode; for(uInt32 i = 0; i < GFX_NumModes; ++i) { - if(ourGraphicsModes[i].name == BSPF_tolower(name) || - ourGraphicsModes[i].description == BSPF_tolower(name)) + if(BSPF_equalsIgnoreCase(ourGraphicsModes[i].name, name) || + BSPF_equalsIgnoreCase(ourGraphicsModes[i].description, name)) { gfxmode = ourGraphicsModes[i]; found = true; diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 73936a40a..0dff979b4 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -755,8 +755,8 @@ uInt8* OSystem::openROM(string file, string& md5, uInt32& size) // Grab 3-character extension char* ext = filename + strlen(filename) - 4; - if(!BSPF_strcasecmp(ext, ".a26") || !BSPF_strcasecmp(ext, ".bin") || - !BSPF_strcasecmp(ext, ".rom")) + if(BSPF_equalsIgnoreCase(ext, ".a26") || BSPF_equalsIgnoreCase(ext, ".bin") || + BSPF_equalsIgnoreCase(ext, ".rom")) { file = filename; break; diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index 2c1987005..d0cc10309 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -134,7 +134,7 @@ void ContextMenu::setSelected(const string& tag, const string& defaultTag) { for(unsigned int item = 0; item < _entries.size(); ++item) { - if(BSPF_strcasecmp(_entries[item].second.c_str(), tag.c_str()) == 0) + if(BSPF_equalsIgnoreCase(_entries[item].second, tag) == 0) { setSelected(item); return; @@ -144,7 +144,7 @@ void ContextMenu::setSelected(const string& tag, const string& defaultTag) // If we get this far, the value wasn't found; use the default value for(unsigned int item = 0; item < _entries.size(); ++item) { - if(BSPF_strcasecmp(_entries[item].second.c_str(), defaultTag.c_str()) == 0) + if(BSPF_equalsIgnoreCase(_entries[item].second, defaultTag) == 0) { setSelected(item); return; diff --git a/src/gui/LauncherFilterDialog.cxx b/src/gui/LauncherFilterDialog.cxx index daac05e15..b74b708f7 100644 --- a/src/gui/LauncherFilterDialog.cxx +++ b/src/gui/LauncherFilterDialog.cxx @@ -136,7 +136,7 @@ bool LauncherFilterDialog::isValidRomName(const string& name, const char* ext = name.c_str() + idx + 1; for(uInt32 i = 0; i < exts.size(); ++i) - if(BSPF_strcasecmp(ext, exts[i].c_str()) == 0) + if(BSPF_equalsIgnoreCase(ext, exts[i])) return true; } @@ -153,7 +153,7 @@ bool LauncherFilterDialog::isValidRomName(const string& name, string& ext) for(uInt32 i = 0; i < 5; ++i) { - if(BSPF_strcasecmp(e, ourRomTypes[1][i]) == 0) + if(BSPF_equalsIgnoreCase(e, ourRomTypes[1][i])) { ext = e; return true;