diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx index 694633688..8bf5c38d9 100644 --- a/src/emucore/Props.cxx +++ b/src/emucore/Props.cxx @@ -96,37 +96,27 @@ void Properties::load(istream& in) { setDefaults(); - string line, key, value; - string::size_type one, two, three, four, garbage; - // Loop reading properties - while(getline(in, line)) + string key, value; + for(;;) { - // Strip all tabs from the line - while((garbage = line.find("\t")) != string::npos) - line.erase(garbage, 1); + // Get the key associated with this property + key = readQuotedString(in); - // Ignore commented and empty lines - if((line.length() == 0) || (line[0] == ';')) - continue; + // Make sure the stream is still okay + if(!in) + return; - // End of this record - if(line == "\"\"") + // A null key signifies the end of the property list + if(key == "") break; - one = line.find("\"", 0); - two = line.find("\"", one + 1); - three = line.find("\"", two + 1); - four = line.find("\"", three + 1); + // Get the value associated with this property + value = readQuotedString(in); - // Invalid line if it doesn't contain 4 quotes - if((one == string::npos) || (two == string::npos) || - (three == string::npos) || (four == string::npos)) - break; - - // Otherwise get the key and value - key = line.substr(one + 1, two - one - 1); - value = line.substr(three + 1, four - three - 1); + // Make sure the stream is still okay + if(!in) + return; // Set the property PropertyType type = getPropertyType(key); @@ -170,9 +160,7 @@ string Properties::readQuotedString(istream& in) while(in.get(c)) { if(c == '"') - { break; - } } // Read characters until we see the close quote @@ -180,21 +168,13 @@ string Properties::readQuotedString(istream& in) while(in.get(c)) { if((c == '\\') && (in.peek() == '"')) - { in.get(c); - } else if((c == '\\') && (in.peek() == '\\')) - { in.get(c); - } else if(c == '"') - { break; - } else if(c == '\r') - { continue; - } s += c; } @@ -219,9 +199,7 @@ void Properties::writeQuotedString(ostream& out, const string& s) out.put('"'); } else - { out.put(s[i]); - } } out.put('"'); } diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index 78925855b..e5596c75e 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -77,7 +77,7 @@ void EditableWidget::setEditable(bool editable) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool EditableWidget::tryInsertChar(char c, int pos) { - if (isprint(c) && c != '\"' && c != '\\') + if(isprint(c) && c != '\"') { _editString.insert(pos, 1, c); return true;