[x265] [PATCH] dhdr: Skip comments in the json file while parsing it

bhavna at multicorewareinc.com bhavna at multicorewareinc.com
Fri Feb 16 09:21:39 CET 2018


# HG changeset patch
# User Bhavna Hariharan <bhavna at multicorewareinc.com>
# Date 1518761459 -19800
#      Fri Feb 16 11:40:59 2018 +0530
# Node ID d50bb9bf0ab29a5f15df83db1527b5337f2da9c1
# Parent  a92fd62210b87f112f5fe087ede1a0e8f0eb8027
dhdr: Skip comments in the json file while parsing it.

Comments of the type /* */ OR // are ignored.

diff -r a92fd62210b8 -r d50bb9bf0ab2 source/dynamicHDR10/JsonHelper.cpp
--- a/source/dynamicHDR10/JsonHelper.cpp	Fri Feb 16 11:37:45 2018 +0530
+++ b/source/dynamicHDR10/JsonHelper.cpp	Fri Feb 16 11:40:59 2018 +0530
@@ -139,21 +139,13 @@
         return JsonObject();
     }
 
-    ifstream tfile;
-    string json_str;
-    string json_str2;
+    std::ifstream ifs(path);
+    const std::string json_str2((std::istreambuf_iterator<char>(ifs)),
+                                (std::istreambuf_iterator<char>()));
+
     string err = "";
-    tfile.open(path);
-    while(tfile)
-    {
-        std::getline(tfile, json_str);
-        json_str2.append(json_str);
-    }
 
-    tfile.close();
-    size_t beginning = json_str2.find_first_of("{");
-    int fixchar = json_str2[json_str2.size() - 2] == '}' ? 1 : 0;
-    return Json::parse(json_str2.substr(beginning,json_str2.size() - fixchar),err).object_items();
+    return Json::parse(json_str2,err, JsonParse::COMMENTS).object_items();
 }
 
 JsonArray JsonHelper::readJsonArray(const string &path)
@@ -174,28 +166,13 @@
         return JsonArray();
     }
 
-    ifstream tfile;
-    string json_str;
-    string json_str2;
+    std::ifstream ifs(path);
+    const std::string json_str2((std::istreambuf_iterator<char>(ifs)),
+                                (std::istreambuf_iterator<char>()));
+
     string err = "";
-    tfile.open(path);
-    while(tfile)
-    {
-        std::getline(tfile, json_str);
-        json_str2.append(json_str);
-    }
 
-    tfile.close();
-
-    vector<Json> data;
-    if (json_str2.size() != 0)
-    {
-        size_t beginning = json_str2.find_first_of("[");
-        int fixchar = json_str2[json_str2.size() - 2] == ']' ? 1 : 0;
-        return Json::parse(json_str2.substr(beginning, json_str2.size() - fixchar), err).array_items();
-    }
-    else
-        return data;
+    return Json::parse(json_str2,err, JsonParse::COMMENTS).array_items();
 }
 
 bool JsonHelper::validatePathExtension(string &path)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265-clean.patch
Type: text/x-patch
Size: 2343 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20180216/dfa77bca/attachment.bin>


More information about the x265-devel mailing list