diff --git a/ejson/Object.cpp b/ejson/Object.cpp index e7f464a..8152d52 100644 --- a/ejson/Object.cpp +++ b/ejson/Object.cpp @@ -155,6 +155,16 @@ const ejson::Object::iterator ejson::Object::end() const { return ejson::Object::iterator(*this, size()); } +std::string ejson::Object::generate() const { + std::string out; + if (m_data == nullptr) { + EJSON_ERROR("Can not remove (nullptr) ..."); + return out; + } + static_cast(m_data.get())->iGenerate(out, 0); + return out; +} + #include template class ejson::iterator; diff --git a/ejson/Object.h b/ejson/Object.h index 8839654..cd217e4 100644 --- a/ejson/Object.h +++ b/ejson/Object.h @@ -137,6 +137,12 @@ namespace ejson { * @return New valid iterator on the next element or this.end() */ iterator remove(const iterator& _it); + public: + /** + * @brief generate a string that contain the created XML + * @return generated data + */ + std::string generate() const; }; } diff --git a/ejson/internal/Object.cpp b/ejson/internal/Object.cpp index dfd179c..0373c5f 100644 --- a/ejson/internal/Object.cpp +++ b/ejson/internal/Object.cpp @@ -213,11 +213,11 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs return false; } bool ejson::internal::Object::iGenerate(std::string& _data, size_t _indent) const { - bool oneLine=true; + bool oneLine = true; if (m_value.size()>3) { - oneLine=false; + oneLine = false; } else if (_indent<=1) { - oneLine=false; + oneLine = false; } else { for (int32_t iii=0; iii tmp = m_value[iii]; @@ -243,13 +243,13 @@ bool ejson::internal::Object::iGenerate(std::string& _data, size_t _indent) cons } } } - if (true == oneLine) { + if (oneLine == true) { _data += "{ "; } else { _data += "{\n"; } - for (int32_t iii=0; iii