From 39a3675c7571f25aef6afa41591b2c342bb6b4a4 Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 23 Nov 2020 12:46:15 +0000 Subject: [PATCH] Ensuring scene dump is valid json Change-Id: I6fe45a0f0da509bc4c7566543f36bcac474e9da1 --- dali/internal/network/common/automation.cpp | 75 +++++++++++++++++------------ 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/dali/internal/network/common/automation.cpp b/dali/internal/network/common/automation.cpp index 18d1fa6..2a5ba8f 100644 --- a/dali/internal/network/common/automation.cpp +++ b/dali/internal/network/common/automation.cpp @@ -245,42 +245,55 @@ std::string GetPropertyValueString(Dali::Handle handle, int propertyIndex) { Dali::Property::Value value = handle.GetProperty(propertyIndex); - if(value.GetType() == Dali::Property::STRING) + switch(value.GetType()) { - // Escape the string (to ensure valid json) - // Write out quotes, escapes and control characters using unicode syntax \uXXXX - std::ostringstream unescapedValue; - unescapedValue << value; - std::string valueString = unescapedValue.str(); - std::ostringstream escapedValue; - for(std::string::iterator c = valueString.begin(); c != valueString.end(); ++c) + case Dali::Property::STRING: + case Dali::Property::MAP: + case Dali::Property::ARRAY: { - if(*c == '"') + // Escape the string (to ensure valid json) + // Write out quotes, escapes and control characters using unicode syntax \uXXXX + std::ostringstream unescapedValue; + unescapedValue << value; + std::string valueString = unescapedValue.str(); + std::ostringstream escapedValue; + for(std::string::iterator c = valueString.begin(); c != valueString.end(); ++c) { - escapedValue << "\\\""; - } - else if(*c == '\\') - { - escapedValue << "\\\\"; - } - else if('\x00' <= *c && *c <= '\x1f') - { - escapedValue << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(*c); - } - else - { - escapedValue << *c; + if(*c == '"') + { + escapedValue << "\\\""; + } + else if(*c == '\\') + { + escapedValue << "\\\\"; + } + else if(*c == '\r') + { + escapedValue << "\\\n"; + } + else if('\x00' <= *c && *c <= '\x1f') + { + escapedValue << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(*c); + } + else + { + escapedValue << *c; + } } + valueStream << escapedValue.str(); + break; + } + case Dali::Property::MATRIX: + case Dali::Property::MATRIX3: + { + MatrixToStream(value, valueStream); + break; + } + default: + { + valueStream << value; + break; } - valueStream << escapedValue.str(); - } - else if(value.GetType() == Dali::Property::MATRIX || value.GetType() == Dali::Property::MATRIX3) - { - MatrixToStream(value, valueStream); - } - else - { - valueStream << value; } } else -- 2.7.4