25 #include <boost/regex.hpp>
32 indenting(indenting), nesting(0), indentChars(indentChars), jsStyleKeys(jsStyleKeys)
41 stack.push(eEmptyObject);
49 if (stack.size() == 0)
51 throw LocalException(
"Stack is empty");
54 if (stack.top() != eEmptyObject && stack.top() != eObject)
56 throw LocalException(
"Wrong type");
70 if (jsStyleKeys &&
isId(key))
72 ss << key << (indenting == 2 ?
": " :
":");
76 ss <<
EscapeQuote(key) << (indenting == 2 ?
": " :
":");
85 stack.push(eEmptyArray);
93 if (stack.size() == 0)
95 throw LocalException(
"Stack is empty");
98 if (stack.top() != eEmptyArray && stack.top() != eArray)
100 throw LocalException(
"Wrong type");
127 boost::cmatch result;
128 return boost::regex_search(
str.c_str(),
130 boost::regex(
"^[_A-Za-z]\\w*$"),
131 boost::regex_constants::match_default);
143 std::ostringstream ss;
145 for (
auto iter =
str.cbegin(); iter !=
str.cend(); iter++)
180 ss <<
"\\u" << std::hex << std::uppercase << std::setfill(
'0')
181 << std::setw(4) <<
static_cast<int>(*iter);
196 JsonWriter::writeNewLine()
202 for (
int i = 0; i < nesting; i++)
210 JsonWriter::beginValue()
212 if (stack.size() == 0)
217 if (stack.top() == eArray)
219 ss << (indenting == 1 ?
", " :
",");
222 if (stack.top() != eObjectKey)
227 if (stack.top() != eEmptyArray && stack.top() != eArray && stack.top() != eObjectKey)
229 throw LocalException(
"Wrong type");
234 JsonWriter::beginKey()
236 if (stack.size() == 0)
238 throw LocalException(
"Stack is empty");
241 if (stack.top() != eEmptyObject && stack.top() != eObject)
243 throw LocalException(
"Wrong type");
246 if (stack.top() == eObject)
248 ss << (indenting == 1 ?
", " :
",");
258 stack.push(eObjectKey);
262 JsonWriter::endValue()
264 if (stack.size() == 0)
268 else if (stack.top() == eEmptyArray)
270 stack.top() = eArray;
272 else if (stack.top() == eObjectKey)
274 stack.top() = eObject;
279 JsonWriter::endArrayOrObject()
281 if (stack.top() == eArray || stack.top() == eObject)