Ensuring scene dump is valid json 96/248196/6
authorDavid Steele <david.steele@samsung.com>
Mon, 23 Nov 2020 12:46:15 +0000 (12:46 +0000)
committerDavid Steele <david.steele@samsung.com>
Tue, 6 Jul 2021 10:39:54 +0000 (11:39 +0100)
Change-Id: I6fe45a0f0da509bc4c7566543f36bcac474e9da1

dali/internal/network/common/automation.cpp

index 18d1fa6..2a5ba8f 100644 (file)
@@ -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