Merge branch 'develop' of https://github.com/pocoproject/poco into develop

This commit is contained in:
Guenter Obiltschnig 2015-09-17 12:00:41 +02:00
commit a7bb89839c
4 changed files with 52 additions and 33 deletions

View File

@ -108,7 +108,7 @@ private:
void saveKeyValue(std::istream& istr);
bool isNewLine(int c) const;
bool isKeyValueSeparator(int c) const;
void outputKeyValue(std::ostream& ostr, const std::string& key, const std::string& value) const;
std::string composeOneLine(const std::string& key, const std::string& value) const;
bool _preserveComment;
FileContent _fileContent;

View File

@ -81,23 +81,13 @@ void PropertyFileConfiguration::save(std::ostream& ostr) const
{
if (_preserveComment)
{
// Check the starting char of each line in _fileContent.
// If the char is a comment sign, write the line out directly.
// Otherwise, use this line as key to get the value from parent's map and write out.
for (FileContent::const_iterator it = _fileContent.begin(); it != _fileContent.end(); ++it)
{
if (isComment((*it)[0])) ostr << *it;
else outputKeyValue(ostr, *it, getString(*it));
}
} else
ostr << *it;
}
else
{
MapConfiguration::iterator it = begin();
MapConfiguration::iterator ed = end();
while (it != ed)
{
outputKeyValue(ostr, it->first, it->second);
++it;
}
for (MapConfiguration::iterator it = begin(); it != end(); ++it)
ostr << composeOneLine(it->first, it->second);
}
}
@ -117,6 +107,9 @@ void PropertyFileConfiguration::save(const std::string& path) const
}
// If _preserveComment is true, not only save key-value into map
// but also save the entire file into _fileContent.
// Otherwise, only save key-value into map.
void PropertyFileConfiguration::parseLine(std::istream& istr)
{
skipSpace(istr);
@ -125,7 +118,6 @@ void PropertyFileConfiguration::parseLine(std::istream& istr)
{
if (isComment(istr.peek()))
{
// Save
if (_preserveComment) saveComment(istr);
else skipLine(istr);
}
@ -179,11 +171,20 @@ int PropertyFileConfiguration::readChar(std::istream& istr)
void PropertyFileConfiguration::setRaw(const std::string& key, const std::string& value)
{
MapConfiguration::setRaw(key, value);
// Insert the key to the end of _fileContent and update _keyFileContentItMap.
if (_preserveComment)
{
FileContent::iterator fit = _fileContent.insert(_fileContent.end(), key);
_keyFileContentItMap[key] = fit;
// Insert the key-value to the end of _fileContent and update _keyFileContentItMap.
if (_keyFileContentItMap.count(key) == 0)
{
FileContent::iterator fit = _fileContent.insert(_fileContent.end(), composeOneLine(key, value));
_keyFileContentItMap[key] = fit;
}
// Update the key-value in _fileContent.
else
{
FileContent::iterator fit = _keyFileContentItMap[key];
*fit = composeOneLine(key, value);
}
}
}
@ -260,36 +261,36 @@ bool PropertyFileConfiguration::isNewLine(int c) const
}
void PropertyFileConfiguration::outputKeyValue(std::ostream& ostr, const std::string& key, const std::string& value) const
std::string PropertyFileConfiguration::composeOneLine(const std::string& key, const std::string& value) const
{
ostr << key << ": ";
std::string result = key + ": ";
for (std::string::const_iterator its = value.begin(); its != value.end(); ++its)
{
switch (*its)
{
case '\t':
ostr << "\\t";
result += "\\t";
break;
case '\r':
ostr << "\\r";
result += "\\r";
break;
case '\n':
ostr << "\\n";
result += "\\n";
break;
case '\f':
ostr << "\\f";
result += "\\f";
break;
case '\\':
ostr << "\\\\";
result += "\\\\";
break;
default:
ostr << *its;
result += *its;
break;
}
}
ostr << "\n";
return result += "\n";
}

View File

@ -140,7 +140,8 @@ void PropertyFileConfigurationTest::testLoadSaveWithPreserveComment()
"# comment !\n"
"prop2 = value2 \n"
"! comment !\n"
"prop3:foo";
"prop3:foo\n"
"prop4";
std::istringstream istr(propFile);
AutoPtr<PropertyFileConfiguration> pConf = new PropertyFileConfiguration(istr, true);
@ -153,7 +154,8 @@ void PropertyFileConfigurationTest::testLoadSaveWithPreserveComment()
"# comment !\n"
"prop2: value2\n"
"! comment !\n"
"prop3: foo\n",
"prop3: foo\n"
"prop4: \n",
ostr.str());
pConf->setString("prop4", "value4");
@ -182,6 +184,19 @@ void PropertyFileConfigurationTest::testLoadSaveWithPreserveComment()
"prop3: foo\n"
"prop4: value4\n",
ostr.str());
pConf->setString("prop4", "value5");
ostr.clear();
ostr.str("");
pConf->save(ostr);
assertEqual ("! comment #\n"
"prop1: value1\n"
"# comment #\n"
"# comment !\n"
"! comment !\n"
"prop3: foo\n"
"prop4: value5\n",
ostr.str());
}

View File

@ -16,15 +16,18 @@ if (WIN32)
# be set up anyway
get_filename_component(sdk_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" REALPATH)
get_filename_component(kit_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot]" REALPATH)
get_filename_component(kit81_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot81]" REALPATH)
if (X64)
set(sdk_bindir "${sdk_dir}/bin/x64")
set(kit_bindir "${kit_dir}/bin/x64")
set(kit81_bindir "${kit81_dir}/bin/x64")
else (X64)
set(sdk_bindir "${sdk_dir}/bin")
set(kit_bindir "${kit_dir}/bin/x86")
set(kit81_bindir "${kit81_dir}/bin/x86")
endif (X64)
endif ()
find_program(CMAKE_MC_COMPILER mc.exe HINTS "${sdk_bindir}" "${kit_bindir}"
find_program(CMAKE_MC_COMPILER mc.exe HINTS "${sdk_bindir}" "${kit_bindir}" "${kit81_bindir}"
DOC "path to message compiler")
if (NOT CMAKE_MC_COMPILER)
message(FATAL_ERROR "message compiler not found: required to build")