18 template <
typename OutputStream>
21 JsonxWriter(OutputStream& os) : os_(os), name_(), level_(0), hasName_(false) {
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");
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;
119 for (
size_t i = 0; i < length; i++) {
121 case '&': WriteString(
"&");
break;
122 case '<': WriteString(
"<");
break;
123 default: os_.Put(s[i]);
break;
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=\"") ||
149 !WriteEscapedAttributeValue(name_.GetString(), name_.GetSize()) ||
155 return WriteString(
"/>");
158 return WriteString(
">");
163 if (!WriteString(
"</json:") ||
164 !WriteString(type) ||
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)) {
bool String(const char *str, SizeType length, bool)
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
bool WriteEscapedAttributeValue(const char *s, size_t length)
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
Wrapper of C file stream for input using fread().
bool WriteEndElement(const char *type)
bool WriteString(const char *s)
bool WriteEscapedText(const char *s, size_t length)
bool WriteNumberElement(const char *buffer, int length)
unsigned __int64 uint64_t
bool WriteStartElement(const char *type, bool emptyElement=false)
File byte stream for input using fread().
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.
RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
bool Key(const char *str, SizeType length, bool)
JsonxWriter(OutputStream &os)
bool RawNumber(const char *str, SizeType length, bool)