From a84a4051f92ba73ab4f9c5207e21c940533681ad Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 13 Mar 2021 15:10:03 +0100 Subject: [PATCH] Write ZoneDefinition entry in parenthesis if there are unparsable character sequences --- .../Zone/Definition/ZoneDefinitionStream.cpp | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ZoneCommon/Zone/Definition/ZoneDefinitionStream.cpp b/src/ZoneCommon/Zone/Definition/ZoneDefinitionStream.cpp index 45e902b8..5e20f475 100644 --- a/src/ZoneCommon/Zone/Definition/ZoneDefinitionStream.cpp +++ b/src/ZoneCommon/Zone/Definition/ZoneDefinitionStream.cpp @@ -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"; }