mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-27 17:09:20 +01:00
parent
c5dca8e3ff
commit
5a5509a3e3
@ -1,5 +1,12 @@
|
||||
This is the changelog file for the POCO C++ Libraries.
|
||||
|
||||
Release 1.6.0 (2015-06-??)
|
||||
==========================
|
||||
|
||||
- fixed GH #782: Poco::JSON::PrintHandler not working for nested arrays
|
||||
- fixed GH #819: JSON Stringifier fails with preserve insert order
|
||||
|
||||
|
||||
Release 1.6.0 (2014-12-22)
|
||||
==========================
|
||||
|
||||
|
@ -191,7 +191,7 @@ public:
|
||||
/// Sets a new value
|
||||
|
||||
void stringify(std::ostream& out, unsigned int indent = 0, int step = -1) const;
|
||||
/// Prints the object to out. When indent is 0, the object
|
||||
/// Prints the object to out stream. When indent is 0, the object
|
||||
/// will be printed on a single line without indentation.
|
||||
|
||||
void remove(const std::string& key);
|
||||
@ -239,8 +239,8 @@ private:
|
||||
out << '}';
|
||||
}
|
||||
|
||||
typedef std::deque<Dynamic::Var*> KeyPtrList;
|
||||
typedef Poco::DynamicStruct::Ptr StructPtr;
|
||||
typedef std::deque<const std::string*> KeyPtrList;
|
||||
typedef Poco::DynamicStruct::Ptr StructPtr;
|
||||
|
||||
const std::string& getKey(ValueMap::const_iterator& it) const;
|
||||
const Dynamic::Var& getValue(ValueMap::const_iterator& it) const;
|
||||
@ -320,7 +320,7 @@ inline const Dynamic::Var& Object::getValue(ValueMap::const_iterator& it) const
|
||||
|
||||
inline const Dynamic::Var& Object::getValue(KeyPtrList::const_iterator& it) const
|
||||
{
|
||||
return **it;
|
||||
return _values.at(**it);
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,7 +115,6 @@ private:
|
||||
unsigned _indent;
|
||||
std::string _tab;
|
||||
int _array;
|
||||
bool _value;
|
||||
bool _objStart;
|
||||
};
|
||||
|
||||
|
@ -107,16 +107,16 @@ const std::string& Object::getKey(KeyPtrList::const_iterator& iter) const
|
||||
ValueMap::const_iterator end = _values.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
if (it->second == **iter) return it->first;
|
||||
if (it->first == **iter) return it->first;
|
||||
}
|
||||
|
||||
throw NotFoundException((*iter)->convert<std::string>());
|
||||
throw NotFoundException(**iter);
|
||||
}
|
||||
|
||||
|
||||
void Object::set(const std::string& key, const Dynamic::Var& value)
|
||||
{
|
||||
_values[key] = value;
|
||||
std::pair<ValueMap::iterator, bool> ret = _values.insert(ValueMap::value_type(key, value));
|
||||
if (_preserveInsOrder)
|
||||
{
|
||||
KeyPtrList::iterator it = _keys.begin();
|
||||
@ -125,7 +125,7 @@ void Object::set(const std::string& key, const Dynamic::Var& value)
|
||||
{
|
||||
if (key == **it) return;
|
||||
}
|
||||
_keys.push_back(&_values[key]);
|
||||
_keys.push_back(&ret.first->first);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,7 @@ PrintHandler::PrintHandler(unsigned indent):
|
||||
_out(std::cout),
|
||||
_indent(indent),
|
||||
_array(0),
|
||||
_value(false),
|
||||
_objStart(false)
|
||||
_objStart(true)
|
||||
{
|
||||
}
|
||||
|
||||
@ -37,8 +36,7 @@ PrintHandler::PrintHandler(std::ostream& out, unsigned indent):
|
||||
_out(out),
|
||||
_indent(indent),
|
||||
_array(0),
|
||||
_value(false),
|
||||
_objStart(false)
|
||||
_objStart(true)
|
||||
{
|
||||
}
|
||||
|
||||
@ -53,7 +51,7 @@ void PrintHandler::reset()
|
||||
_out.flush();
|
||||
_tab = "";
|
||||
_array = 0;
|
||||
_value = false;
|
||||
_objStart = true;
|
||||
}
|
||||
|
||||
|
||||
@ -94,16 +92,17 @@ void PrintHandler::endObject()
|
||||
_tab.erase(_tab.length() - indent());
|
||||
|
||||
_out << endLine() << _tab << '}';
|
||||
if (array()) _value = true;
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
void PrintHandler::startArray()
|
||||
{
|
||||
arrayValue();
|
||||
_out << '[' << endLine();
|
||||
_tab.append(indent(), ' ');
|
||||
++_array;
|
||||
_value = false;
|
||||
_objStart = true;
|
||||
}
|
||||
|
||||
|
||||
@ -113,18 +112,16 @@ void PrintHandler::endArray()
|
||||
_out << endLine() << _tab << ']';
|
||||
--_array;
|
||||
poco_assert (_array >= 0);
|
||||
_value = false;
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
void PrintHandler::key(const std::string& k)
|
||||
{
|
||||
if (_value)
|
||||
{
|
||||
if (!_objStart) comma();
|
||||
_value = false;
|
||||
}
|
||||
_objStart = false;
|
||||
if (!_objStart) comma();
|
||||
|
||||
_objStart = true;
|
||||
|
||||
_out << _tab;
|
||||
Stringifier::formatString(k, _out);
|
||||
if (!printFlat()) _out << ' ';
|
||||
@ -137,7 +134,8 @@ void PrintHandler::null()
|
||||
{
|
||||
arrayValue();
|
||||
_out << "null";
|
||||
_value = true;
|
||||
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
@ -145,7 +143,7 @@ void PrintHandler::value(int v)
|
||||
{
|
||||
arrayValue();
|
||||
_out << v;
|
||||
_value = true;
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
@ -153,7 +151,7 @@ void PrintHandler::value(unsigned v)
|
||||
{
|
||||
arrayValue();
|
||||
_out << v;
|
||||
_value = true;
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
@ -162,7 +160,7 @@ void PrintHandler::value(Int64 v)
|
||||
{
|
||||
arrayValue();
|
||||
_out << v;
|
||||
_value = true;
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
@ -170,7 +168,7 @@ void PrintHandler::value(UInt64 v)
|
||||
{
|
||||
arrayValue();
|
||||
_out << v;
|
||||
_value = true;
|
||||
_objStart = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -179,7 +177,7 @@ void PrintHandler::value(const std::string& value)
|
||||
{
|
||||
arrayValue();
|
||||
Stringifier::formatString(value, _out);
|
||||
_value = true;
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
@ -188,7 +186,7 @@ void PrintHandler::value(double d)
|
||||
{
|
||||
arrayValue();
|
||||
_out << d;
|
||||
_value = true;
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
@ -196,7 +194,7 @@ void PrintHandler::value(bool b)
|
||||
{
|
||||
arrayValue();
|
||||
_out << b;
|
||||
_value = true;
|
||||
_objStart = false;
|
||||
}
|
||||
|
||||
|
||||
@ -208,9 +206,8 @@ void PrintHandler::comma()
|
||||
|
||||
void PrintHandler::arrayValue()
|
||||
{
|
||||
if (array())
|
||||
{
|
||||
if (_value) comma();
|
||||
if (!_objStart) comma();
|
||||
if (array()) {
|
||||
_out << _tab;
|
||||
}
|
||||
}
|
||||
|
@ -1220,6 +1220,22 @@ void JSONTest::testPrintHandler()
|
||||
parser.reset();
|
||||
parser.parse(json);
|
||||
assert (json == ostr.str());
|
||||
|
||||
json="[[\"a\"],[\"b\"],[[\"c\"],[\"d\"]]]";
|
||||
ostr.str("");
|
||||
pHandler->setIndent(0);
|
||||
parser.reset();
|
||||
parser.parse(json);
|
||||
std::cout << ostr.str() << std::endl;
|
||||
assert (json == ostr.str());
|
||||
|
||||
json="[{\"1\":\"one\",\"0\":[\"zero\",\"nil\"]}]";
|
||||
ostr.str("");
|
||||
pHandler->setIndent(0);
|
||||
parser.reset();
|
||||
parser.parse(json);
|
||||
assert (json == ostr.str());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1379,13 +1395,27 @@ void JSONTest::testStringify()
|
||||
|
||||
void JSONTest::testStringifyPreserveOrder()
|
||||
{
|
||||
Object jObj(true);
|
||||
jObj.set("foo", 0);
|
||||
jObj.set("bar", 0);
|
||||
jObj.set("baz", 0);
|
||||
Object presObj(true);
|
||||
presObj.set("foo", 0);
|
||||
presObj.set("bar", 0);
|
||||
presObj.set("baz", 0);
|
||||
std::stringstream ss;
|
||||
jObj.stringify(ss);
|
||||
presObj.stringify(ss);
|
||||
assert(ss.str() == "{\"foo\":0,\"bar\":0,\"baz\":0}");
|
||||
ss.str("");
|
||||
Stringifier::stringify(presObj, ss);
|
||||
assert(ss.str() == "{\"foo\":0,\"bar\":0,\"baz\":0}");
|
||||
|
||||
Object noPresObj;
|
||||
noPresObj.set("foo", 0);
|
||||
noPresObj.set("bar", 0);
|
||||
noPresObj.set("baz", 0);
|
||||
ss.str("");
|
||||
noPresObj.stringify(ss);
|
||||
assert(ss.str() == "{\"bar\":0,\"baz\":0,\"foo\":0}");
|
||||
ss.str("");
|
||||
Stringifier::stringify(noPresObj, ss);
|
||||
assert(ss.str() == "{\"bar\":0,\"baz\":0,\"foo\":0}");
|
||||
|
||||
std::string json = "{ \"Simpsons\" : { \"husband\" : { \"name\" : \"Homer\" , \"age\" : 38 }, \"wife\" : { \"name\" : \"Marge\", \"age\" : 36 }, "
|
||||
"\"children\" : [ \"Bart\", \"Lisa\", \"Maggie\" ], "
|
||||
|
Loading…
x
Reference in New Issue
Block a user