changeset 59:d88ae86b7b79

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 22 Jan 2021 09:59:19 +0100
parents ef1a1ce0c1e3
children 950c1fb892ad 303708bc73d8
files Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h
diffstat 2 files changed, 54 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp	Fri Jan 22 07:36:18 2021 +0100
+++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp	Fri Jan 22 09:59:19 2021 +0100
@@ -313,6 +313,37 @@
   }
 
 
+  static bool ReadJsonInternal(Json::Value& target,
+                               const void* buffer,
+                               size_t size,
+                               bool collectComments)
+  {
+#if JSONCPP_USE_DEPRECATED == 1
+    Json::Reader reader;
+    return reader.parse(reinterpret_cast<const char*>(buffer),
+                        reinterpret_cast<const char*>(buffer) + size, target, collectComments);
+#else
+    Json::CharReaderBuilder builder;
+    builder.settings_["collectComments"] = collectComments;
+    
+    const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+    assert(reader.get() != NULL);
+    
+    JSONCPP_STRING err;
+    if (reader->parse(reinterpret_cast<const char*>(buffer),
+                      reinterpret_cast<const char*>(buffer) + size, &target, &err))
+    {
+      return true;
+    }
+    else
+    {
+      LogError("Cannot parse JSON: " + std::string(err));
+      return false;
+    }
+#endif
+  }
+
+
   bool ReadJson(Json::Value& target,
                 const std::string& source)
   {
@@ -324,29 +355,25 @@
                 const void* buffer,
                 size_t size)
   {
-#if JSONCPP_USE_DEPRECATED == 1
-    Json::Reader reader;
-    return reader.parse(reinterpret_cast<const char*>(buffer),
-                        reinterpret_cast<const char*>(buffer) + size, target);
-#else
-    Json::CharReaderBuilder builder;
-    const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
-    assert(reader.get() != NULL);
-    JSONCPP_STRING err;
-    if (reader->parse(reinterpret_cast<const char*>(buffer),
-                      reinterpret_cast<const char*>(buffer) + size, &target, &err))
-    {
-      return true;
-    }
-    else
-    {
-      LogError("Cannot parse JSON: " + err);
-      return false;
-    }
-#endif
+    return ReadJsonInternal(target, buffer, size, true);
   }
   
 
+  bool ReadJsonWithoutComments(Json::Value& target,
+                               const std::string& source)
+  {
+    return ReadJsonWithoutComments(target, source.empty() ? NULL : source.c_str(), source.size());
+  }
+  
+
+  bool ReadJsonWithoutComments(Json::Value& target,
+                               const void* buffer,
+                               size_t size)
+  {
+    return ReadJsonInternal(target, buffer, size, false);
+  }
+
+
   void WriteFastJson(std::string& target,
                      const Json::Value& source)
   {
--- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h	Fri Jan 22 07:36:18 2021 +0100
+++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h	Fri Jan 22 09:59:19 2021 +0100
@@ -483,6 +483,13 @@
                 const void* buffer,
                 size_t size);
 
+  bool ReadJsonWithoutComments(Json::Value& target,
+                               const std::string& source);  
+
+  bool ReadJsonWithoutComments(Json::Value& target,
+                               const void* buffer,
+                               size_t size);
+
   void WriteFastJson(std::string& target,
                      const Json::Value& source);