This commit is contained in:
Aleksandar Fabijanic
2018-02-08 18:42:30 -06:00
committed by Alex Fabijanic
parent bd81aec779
commit fbd229ee4a
12 changed files with 142 additions and 126 deletions

View File

@@ -15,6 +15,7 @@
#include "Poco/JSON/Array.h"
#include "Poco/JSON/Object.h"
#include "Poco/JSON/Stringifier.h"
#include "Poco/JSONString.h"
using Poco::Dynamic::Var;
@@ -24,8 +25,8 @@ namespace Poco {
namespace JSON {
Array::Array(bool escapeUnicode): _modified(false),
_escapeUnicode(escapeUnicode)
Array::Array(int options): _modified(false),
_escapeUnicode(options & Poco::JSON_ESCAPE_UNICODE)
{
}
@@ -153,6 +154,9 @@ bool Array::isObject(ConstIterator& it) const
void Array::stringify(std::ostream& out, unsigned int indent, int step) const
{
int options = Poco::JSON_WRAP_STRINGS;
options |= _escapeUnicode ? Poco::JSON_ESCAPE_UNICODE : 0;
if (step == -1) step = indent;
out << "[";
@@ -163,7 +167,7 @@ void Array::stringify(std::ostream& out, unsigned int indent, int step) const
{
for (int i = 0; i < indent; i++) out << ' ';
Stringifier::stringify(*it, out, indent + step, step, _escapeUnicode);
Stringifier::stringify(*it, out, indent + step, step, options);
if (++it != _values.end())
{

View File

@@ -26,8 +26,8 @@ namespace JSON {
Object::Object(int options):
_preserveInsOrder(options & JSON_PRESERVE_KEY_ORDER),
_escapeUnicode(options & JSON_ESCAPE_UNICODE),
_preserveInsOrder(options & Poco::JSON_PRESERVE_KEY_ORDER),
_escapeUnicode(options & Poco::JSON_ESCAPE_UNICODE),
_modified(false)
{
}

View File

@@ -21,20 +21,22 @@ namespace Poco {
namespace JSON {
PrintHandler::PrintHandler(unsigned indent):
PrintHandler::PrintHandler(unsigned indent, int options):
_out(std::cout),
_indent(indent),
_array(0),
_objStart(true)
_objStart(true),
_options(options)
{
}
PrintHandler::PrintHandler(std::ostream& out, unsigned indent):
PrintHandler::PrintHandler(std::ostream& out, unsigned indent, int options):
_out(out),
_indent(indent),
_array(0),
_objStart(true)
_objStart(true),
_options(options)
{
}
@@ -118,10 +120,10 @@ void PrintHandler::key(const std::string& k)
{
if (!_objStart) comma();
_objStart = true;
_objStart = true;
_out << _tab;
Stringifier::formatString(k, _out);
Stringifier::formatString(k, _out, _options);
if (!printFlat()) _out << ' ';
_out << ':';
if (!printFlat()) _out << ' ';
@@ -173,7 +175,7 @@ void PrintHandler::value(UInt64 v)
void PrintHandler::value(const std::string& value)
{
arrayValue();
Stringifier::formatString(value, _out);
Stringifier::formatString(value, _out, _options);
_objStart = false;
}

View File

@@ -15,7 +15,6 @@
#include "Poco/JSON/Stringifier.h"
#include "Poco/JSON/Array.h"
#include "Poco/JSON/Object.h"
#include "Poco/JSONString.h"
#include <iomanip>
@@ -26,8 +25,10 @@ namespace Poco {
namespace JSON {
void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int indent, int step, bool escapeUnicode)
void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int indent, int step, int options)
{
bool escapeUnicode = options & Poco::JSON_ESCAPE_UNICODE;
if (step == -1) step = indent;
if (any.type() == typeid(Object))
@@ -61,13 +62,13 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
else if (any.isNumeric() || any.isBoolean())
{
std::string value = any.convert<std::string>();
if (any.type() == typeid(char)) formatString(value, out, escapeUnicode);
if (any.type() == typeid(char)) formatString(value, out, options);
else out << value;
}
else if (any.isString() || any.isDateTime() || any.isDate() || any.isTime())
{
std::string value = any.convert<std::string>();
formatString(value, out, escapeUnicode);
formatString(value, out, options);
}
else
{
@@ -76,9 +77,9 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
}
void Stringifier::formatString(const std::string& value, std::ostream& out, bool escapeUnicode)
void Stringifier::formatString(const std::string& value, std::ostream& out, int options)
{
Poco::toJSON(value, out, true, escapeUnicode);
Poco::toJSON(value, out, options);
}