diff --git a/MongoDB/include/Poco/MongoDB/Array.h b/MongoDB/include/Poco/MongoDB/Array.h index 56dbb98fa..0a5f417bc 100644 --- a/MongoDB/include/Poco/MongoDB/Array.h +++ b/MongoDB/include/Poco/MongoDB/Array.h @@ -72,7 +72,7 @@ struct ElementTraits static std::string toString(const Array::Ptr& value, int indent = 0) { //TODO: - return value.isNull() ? "null" : value->toString(); + return value.isNull() ? "null" : value->toString(indent); } }; diff --git a/MongoDB/src/Array.cpp b/MongoDB/src/Array.cpp index 6e28bf59e..191ee8d43 100644 --- a/MongoDB/src/Array.cpp +++ b/MongoDB/src/Array.cpp @@ -64,28 +64,32 @@ std::string Array::toString(int indent) const { if ( it != _elements.begin() ) { - if ( indent > 0 ) - { - for(int i = 0; i < indent; ++i) - { - oss << ' '; - } - } oss << ","; if ( indent > 0 ) { oss << std::endl; } } + + for(int i = 0; i < indent; ++i) + { + oss << ' '; + } oss << (*it)->toString(); } - oss << "]"; - if ( indent > 0 ) + if ( indent > 0 ) { oss << std::endl; + indent -= 2; + for(int i = 0; i < indent; ++i) + { + oss << ' '; + } } + oss << "]"; + return oss.str(); } diff --git a/MongoDB/src/Document.cpp b/MongoDB/src/Document.cpp index d33c62d74..a6771929e 100644 --- a/MongoDB/src/Document.cpp +++ b/MongoDB/src/Document.cpp @@ -155,10 +155,40 @@ std::string Document::toString(int indent) const { if ( it != _elements.begin() ) { - oss << ", "; + oss << ","; + if ( indent > 0 ) + { + oss << std::endl; + } + } + if ( indent > 0 ) + { + for(int i = 0; i < indent; ++i) + { + oss << ' '; + } + } + oss << '"' << (*it)->name() << '"' << " : "; + if ( indent > 0 ) + { + oss << (*it)->toString(indent + 2); + } + else + { + oss << (*it)->toString(); } - oss << '"' << (*it)->name() << '"' << " : " << (*it)->toString(); } + + if ( indent > 0 ) + { + oss << std::endl; + indent -= 2; + for(int i = 0; i < indent; ++i) + { + oss << ' '; + } + } + oss << "}" << std::endl; return oss.str(); }