From 14728bf2cc9cef28e6acb815248769f2304df4f2 Mon Sep 17 00:00:00 2001 From: stephena Date: Fri, 9 Jul 2004 00:27:39 +0000 Subject: [PATCH] Changed the parsing of lines in the settings file. Instead of stripping all the whitespace in line, first split the line into key/value pairs (split by '=' sign), then trim whitespace from beginning and end of both the key and the value. This fixes the bug where settings that must contain spaces (pathnames) are garbled when they have internal spaces removed. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@298 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/emucore/Settings.cxx | 7 ++++--- stella/src/emucore/Settings.hxx | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) 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; };