Write ZoneDefinition entry in parenthesis if there are unparsable character sequences

This commit is contained in:
Jan 2021-03-13 15:10:03 +01:00
parent 0db526d1c8
commit a84a4051f9

View File

@ -82,5 +82,35 @@ void ZoneDefinitionOutputStream::WriteMetaData(const std::string& metaDataKey, c
void ZoneDefinitionOutputStream::WriteEntry(const std::string& entryKey, const std::string& entryValue) const
{
m_stream << entryKey << "," << entryValue << "\n";
m_stream << entryKey << ",";
if(entryValue.find('"') != std::string::npos
|| entryValue.find("//") != std::string::npos)
{
m_stream << '"';
for(const auto& c : entryValue)
{
switch(c)
{
case '"':
m_stream << "\\\"";
break;
case '\\':
m_stream << "\\\\";
break;
default:
m_stream << c;
break;
}
}
m_stream << '"';
}
else
{
m_stream << entryValue;
}
m_stream << "\n";
}