[DEV] add feature on json generation on Object
This commit is contained in:
parent
c41bcd52d4
commit
f8613d244e
@ -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<ejson::internal::Object*>(m_data.get())->iGenerate(out, 0);
|
||||
return out;
|
||||
}
|
||||
|
||||
#include <ejson/details/iterator.hxx>
|
||||
|
||||
template class ejson::iterator<ejson::Object>;
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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<m_value.size() ; iii++) {
|
||||
if (false == oneLine) {
|
||||
for (int32_t iii=0; iii<m_value.size(); ++iii) {
|
||||
if (oneLine == false) {
|
||||
addIndent(_data, _indent);
|
||||
}
|
||||
_data += "\"";
|
||||
@ -259,13 +259,13 @@ bool ejson::internal::Object::iGenerate(std::string& _data, size_t _indent) cons
|
||||
if (iii<m_value.size()-1) {
|
||||
_data += ",";
|
||||
}
|
||||
if (true == oneLine) {
|
||||
if (oneLine == true) {
|
||||
_data += " ";
|
||||
} else {
|
||||
_data += "\n";
|
||||
}
|
||||
}
|
||||
if (false == oneLine) {
|
||||
if (oneLine == false) {
|
||||
addIndent(_data, _indent-1);
|
||||
}
|
||||
_data += "}";
|
||||
|
@ -27,8 +27,11 @@ bool ejson::internal::Value::isWhiteChar(char32_t _val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ejson::internal::Value::addIndent(std::string& _data, size_t _indent) const {
|
||||
for (size_t iii=0; iii<_indent; iii++) {
|
||||
void ejson::internal::Value::addIndent(std::string& _data, int32_t _indent) const {
|
||||
if (_indent <= 0) {
|
||||
return;
|
||||
}
|
||||
for (int32_t iii=0; iii<_indent; iii++) {
|
||||
_data+="\t";
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ namespace ejson {
|
||||
* @param[in,out] _data String where the indentation is done.
|
||||
* @param[in] _indent Number of tab to add at the string.
|
||||
*/
|
||||
void addIndent(std::string& _data, size_t _indent) const;
|
||||
void addIndent(std::string& _data, int32_t _indent) const;
|
||||
/**
|
||||
* @brief Display the cuurent element that is curently parse.
|
||||
* @param[in] _val Char that is parsed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user