18template <
typename OutputStream>
25 return WriteStartElement(
"null",
true);
30 WriteStartElement(
"boolean") &&
31 WriteString(b ?
"true" :
"false") &&
32 WriteEndElement(
"boolean");
37 return WriteNumberElement(buffer, sprintf(buffer,
"%d", i));
42 return WriteNumberElement(buffer, sprintf(buffer,
"%u", i));
47 return WriteNumberElement(buffer, sprintf(buffer,
"%" PRId64, i));
52 return WriteNumberElement(buffer, sprintf(buffer,
"%" PRIu64, i));
57 return WriteNumberElement(buffer, sprintf(buffer,
"%.17g",
d));
62 WriteStartElement(
"number") &&
63 WriteEscapedText(str, length) &&
64 WriteEndElement(
"number");
69 WriteStartElement(
"string") &&
70 WriteEscapedText(str, length) &&
71 WriteEndElement(
"string");
75 return WriteStartElement(
"object");
81 for (
SizeType i = 0; i < length; i++)
88 return WriteEndElement(
"object");
92 return WriteStartElement(
"array");
96 return WriteEndElement(
"array");
100 bool WriteString(
const char*
s) {
106 bool WriteEscapedAttributeValue(
const char*
s,
size_t length) {
107 for (
size_t i = 0; i < length; i++) {
109 case '&': WriteString(
"&");
break;
110 case '<': WriteString(
"<");
break;
111 case '"': WriteString(
""");
break;
112 default: os_.Put(
s[i]);
break;
118 bool WriteEscapedText(
const char*
s,
size_t length) {
119 for (
size_t i = 0; i < length; i++) {
121 case '&': WriteString(
"&");
break;
122 case '<': WriteString(
"<");
break;
123 default: os_.Put(
s[i]);
break;
129 bool WriteStartElement(
const char* type,
bool emptyElement =
false) {
131 if (!WriteString(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"))
134 if (!WriteString(
"<json:") || !WriteString(type))
140 " xsi:schemaLocation=\"http://www.datapower.com/schemas/json jsonx.xsd\""
141 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
142 " xmlns:json=\"http://www.ibm.com/xmlns/prod/2009/jsonx\""))
148 if (!WriteString(
" name=\"") ||
155 return WriteString(
"/>");
158 return WriteString(
">");
162 bool WriteEndElement(
const char* type) {
163 if (!WriteString(
"</json:") ||
164 !WriteString(type) ||
175 bool WriteNumberElement(
const char* buffer,
int length) {
176 if (!WriteStartElement(
"number"))
178 for (
int j = 0;
j < length;
j++)
180 return WriteEndElement(
"number");
192 char readBuffer[65536];
196 char writeBuffer[65536];
201 if (!reader.
Parse(is, writer)) {
File byte stream for input using fread().
Wrapper of C file stream for output using fwrite().
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
const Ch * GetString() const
size_t GetSize() const
Get the size of string in bytes in the string buffer.
bool Key(const char *str, SizeType length, bool)
bool RawNumber(const char *str, SizeType length, bool)
JsonxWriter(OutputStream &os)
bool String(const char *str, SizeType length, bool)
RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
unsigned __int64 uint64_t