File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed
src/AvTranscoder/properties Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 1
1
#include " JsonWriter.hpp"
2
2
3
+ #include < string>
4
+ #include < sstream>
5
+
3
6
namespace avtranscoder {
4
7
namespace json {
5
8
9
+ std::string JsonStreamWriter::escapeJsonString (const std::string& input)
10
+ {
11
+ std::ostringstream ss;
12
+ for (std::string::const_iterator iter = input.begin (); iter != input.end (); iter++) {
13
+ switch (*iter) {
14
+ case ' \\ ' : ss << " \\\\ " ; break ;
15
+ default : ss << *iter; break ;
16
+ }
17
+ }
18
+ return ss.str ();
19
+ }
20
+
6
21
template <>
7
22
JsonStreamWriter& JsonStreamWriter::operator <<(bool value)
8
23
{
Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ class AvExport JsonStreamWriter
52
52
}
53
53
54
54
virtual std::ostream& finish () = 0;
55
+
56
+ // Escape strings accordingly to the JSON standard
57
+ std::string escapeJsonString (const std::string& input);
55
58
};
56
59
57
60
// Write a boolean to the stream.
@@ -76,6 +79,15 @@ class AvExport JsonObjectStreamWriter : public JsonStreamWriter
76
79
return *this ;
77
80
}
78
81
82
+ template <>
83
+ JsonObjectStreamWriter& operator <<(const std::pair<const char *, const char *> pair)
84
+ {
85
+ std::string first (pair.first );
86
+ std::string second (pair.second );
87
+ addSep () << escapeJsonString (first).c_str () << ' :' << escapeJsonString (second).c_str ();
88
+ return *this ;
89
+ }
90
+
79
91
protected:
80
92
virtual std::ostream& finish () { return stream << ' }' ; }
81
93
};
Original file line number Diff line number Diff line change @@ -138,7 +138,5 @@ def testCheckFilePropertiesAsJson():
138
138
inputFile = av .InputFile ( inputFileName )
139
139
140
140
import json
141
- # throw exception if it is not a valid JSON
141
+ # json.loads method throws a ValueError if it is not a valid JSON.
142
142
json .loads (inputFile .getProperties ().allPropertiesAsJson ())
143
-
144
-
You can’t perform that action at this time.
0 commit comments