From 83b0f47ffb859d4ff4ec9bc8dddcf36ecb956309 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Mon, 19 May 2014 09:42:15 +0200 Subject: [PATCH] fixed GH# 398: PropertyFileConfiguration: input != output --- Util/src/PropertyFileConfiguration.cpp | 27 ++++++++++++++++++- .../src/PropertyFileConfigurationTest.cpp | 4 ++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Util/src/PropertyFileConfiguration.cpp b/Util/src/PropertyFileConfiguration.cpp index c34fadd9c..6bc414db5 100644 --- a/Util/src/PropertyFileConfiguration.cpp +++ b/Util/src/PropertyFileConfiguration.cpp @@ -79,7 +79,32 @@ void PropertyFileConfiguration::save(std::ostream& ostr) const MapConfiguration::iterator ed = end(); while (it != ed) { - ostr << it->first << ": " << it->second << "\n"; + ostr << it->first << ": "; + for (std::string::const_iterator its = it->second.begin(); its != it->second.end(); ++its) + { + switch (*its) + { + case '\t': + ostr << "\\t"; + break; + case '\r': + ostr << "\\r"; + break; + case '\n': + ostr << "\\n"; + break; + case '\f': + ostr << "\\f"; + break; + case '\\': + ostr << "\\\\"; + break; + default: + ostr << *its; + break; + } + } + ostr << "\n"; ++it; } } diff --git a/Util/testsuite/src/PropertyFileConfigurationTest.cpp b/Util/testsuite/src/PropertyFileConfigurationTest.cpp index 1356015b0..c5cbb483c 100644 --- a/Util/testsuite/src/PropertyFileConfigurationTest.cpp +++ b/Util/testsuite/src/PropertyFileConfigurationTest.cpp @@ -96,12 +96,14 @@ void PropertyFileConfigurationTest::testSave() pConf->setString("prop1", "value1"); pConf->setInt("prop2", 42); + pConf->setString("prop3", "value\\1\txxx"); std::ostringstream ostr; pConf->save(ostr); std::string propFile = ostr.str(); assert (propFile == "prop1: value1\n" - "prop2: 42\n"); + "prop2: 42\n" + "prop3: value\\\\1\\txxx\n"); }