diff --git a/stella/src/emucore/Settings.cxx b/stella/src/emucore/Settings.cxx index e0d39c5e8..7173371e9 100644 --- a/stella/src/emucore/Settings.cxx +++ b/stella/src/emucore/Settings.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Settings.cxx,v 1.24 2004-07-07 22:46:01 stephena Exp $ +// $Id: Settings.cxx,v 1.25 2004-07-09 00:27:39 stephena Exp $ //============================================================================ #include @@ -84,8 +84,6 @@ void Settings::loadConfig() { // Strip all whitespace and tabs from the line uInt32 garbage; - while((garbage = line.find(" ")) != string::npos) - line.erase(garbage, 1); while((garbage = line.find("\t")) != string::npos) line.erase(garbage, 1); @@ -97,8 +95,11 @@ void Settings::loadConfig() if((equalPos = line.find("=")) == string::npos) continue; + // Split the line into key/value pairs and trim any whitespace key = line.substr(0, equalPos); value = line.substr(equalPos + 1, line.length() - key.length() - 1); + key = trim(key); + value = trim(value); // Check for absent key or value if((key.length() == 0) || (value.length() == 0)) diff --git a/stella/src/emucore/Settings.hxx b/stella/src/emucore/Settings.hxx index 0f1601312..e3704c4cd 100644 --- a/stella/src/emucore/Settings.hxx +++ b/stella/src/emucore/Settings.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Settings.hxx,v 1.15 2004-07-07 22:46:01 stephena Exp $ +// $Id: Settings.hxx,v 1.16 2004-07-09 00:27:39 stephena Exp $ //============================================================================ #ifndef SETTINGS_HXX @@ -26,7 +26,7 @@ This class provides an interface for accessing frontend specific settings. @author Stephen Anthony - @version $Id: Settings.hxx,v 1.15 2004-07-07 22:46:01 stephena Exp $ + @version $Id: Settings.hxx,v 1.16 2004-07-09 00:27:39 stephena Exp $ */ class Settings { @@ -243,6 +243,14 @@ class Settings // Assignment operator isn't supported by this class so make it private Settings& operator = (const Settings&); + // Trim leading and following whitespace from a string + string trim(string& str) + { + string::size_type first = str.find_first_not_of(' '); + return (first == string::npos) ? string() : + str.substr(first, str.find_last_not_of(' ')-first+1); + } + // Current capacity of the settings array unsigned int myCapacity; };