forked from avTranscoder/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonWriter.cpp
More file actions
57 lines (52 loc) · 1.19 KB
/
JsonWriter.cpp
File metadata and controls
57 lines (52 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "JsonWriter.hpp"
#include <string>
#include <sstream>
namespace avtranscoder
{
namespace json
{
std::string JsonStreamWriter::escapeJsonString(const std::string& input)
{
std::ostringstream ss;
for(std::string::const_iterator iter = input.begin(); iter != input.end(); iter++)
{
switch(*iter)
{
case '\\':
ss << "\\\\";
break;
default:
ss << *iter;
break;
}
}
return ss.str();
}
template <>
JsonObjectStreamWriter& JsonObjectStreamWriter::operator<<(const std::pair<const char*, const char*> pair)
{
std::string first(pair.first);
std::string second(pair.second);
addSep() << escapeJsonString(first).c_str() << ':' << escapeJsonString(second).c_str();
return *this;
}
template <>
JsonStreamWriter& JsonStreamWriter::operator<<(bool value)
{
stream << (value ? "true" : "false");
return *this;
}
template <>
JsonStreamWriter& JsonStreamWriter::operator<<(const char* string)
{
stream << '"' << string << '"';
return *this;
}
template <>
JsonStreamWriter& JsonStreamWriter::operator<<(JsonNull)
{
stream << "null";
return *this;
}
}
}