From ebfff85cb6f771d2dbb59ed4f537073b37b3b152 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Tue, 1 Jan 2019 15:22:30 -0330 Subject: [PATCH] Fixed nasty C-style string conversion to upper/lower-case. --- src/common/bspf.hxx | 12 ++++++++++++ src/debugger/TIADebug.cxx | 15 ++------------- src/emucore/Props.cxx | 5 +---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 95e017110..a60ce78cb 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -123,6 +123,18 @@ namespace BSPF if(val < lower || val > upper) val = setVal; } + // Convert string to given case + inline const string& toUpperCase(string& s) + { + transform(s.begin(), s.end(), s.begin(), ::toupper); + return s; + } + inline const string& toLowerCase(string& s) + { + transform(s.begin(), s.end(), s.begin(), ::tolower); + return s; + } + // Compare two strings, ignoring case inline int compareIgnoreCase(const string& s1, const string& s2) { diff --git a/src/debugger/TIADebug.cxx b/src/debugger/TIADebug.cxx index 01dfc0635..e2db47def 100644 --- a/src/debugger/TIADebug.cxx +++ b/src/debugger/TIADebug.cxx @@ -992,21 +992,10 @@ string TIADebug::audFreq(uInt8 div) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string TIADebug::booleanWithLabel(string label, bool value) { - char buf[64]; - string ret; - if(value) - { - char *p = buf; - const char *q = label.c_str(); - while((*p++ = toupper(*q++))) - ; - ret += "+"; - ret += buf; - return ret; - } + return "+" + BSPF::toUpperCase(label); else - return "-" + label; + return "-" + BSPF::toLowerCase(label); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx index 8e399f8ee..e6d93b376 100644 --- a/src/emucore/Props.cxx +++ b/src/emucore/Props.cxx @@ -15,8 +15,6 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -#include -#include #include #include "bspf.hxx" @@ -58,8 +56,7 @@ void Properties::set(PropertyType key, const string& value) case Controller_MouseAxis: case Display_Phosphor: { - transform(myProperties[key].begin(), myProperties[key].end(), - myProperties[key].begin(), ::toupper); + BSPF::toUpperCase(myProperties[key]); break; }