diff --git a/JString.cpp b/JString.cpp index 0a7b450..5687249 100644 --- a/JString.cpp +++ b/JString.cpp @@ -169,5 +169,39 @@ namespace coreutils { } reset(); } + + MString JString::pretty() { + MString output; + reset(); + char ch; + int index = 0; + while(!eod()) { + ch = nextChar(); + if(ch == '{') { + index += 3; + std::cout << "{\n"; + for(int ix = 0; ix < index; ++ix) + std::cout << ' '; + } + else if(ch == ':') { + std::cout << ": "; + } + else if(ch == '}') { + index -= 3; + std::cout << '\n'; + for(int ix = 0; ix < index; ++ix) + std::cout << ' '; + std::cout << ch << '\n'; + } + else if(ch == ',') { + std::cout << ",\n"; + for(int ix = 0; ix < index; ++ix) + std::cout << ' '; + } + else + std::cout << ch; + } + return output; + } } diff --git a/JString.h b/JString.h index 357b5b4..3897af6 100644 --- a/JString.h +++ b/JString.h @@ -67,7 +67,7 @@ namespace coreutils { return jstring.find(key).str(); } - Proxy& operator=(coreutils::ZString value) { + Proxy& operator=(coreutils::MString value) { jstring.set(key, value); return *this; } @@ -82,6 +82,8 @@ namespace coreutils { } JString & operator=(coreutils:: ZString value); + + MString pretty(); private: void removeWhitespace(); diff --git a/testing/jstring_test b/testing/jstring_test index 8f70ab9..22f23c7 100755 Binary files a/testing/jstring_test and b/testing/jstring_test differ diff --git a/testing/jstring_test.cpp b/testing/jstring_test.cpp index 0a23e1e..06e9230 100644 --- a/testing/jstring_test.cpp +++ b/testing/jstring_test.cpp @@ -27,6 +27,7 @@ int main(int argc, char **argv) { test1["object1"] = "{\"attr1\":\"value1\",\"attr2\":\"value2\",\"attr3\":\"value3\"}"; test1["object1.attr2"] = "{\"xattr1\":\"xvalue1\",\"xattr2\":\"xvalue2\",\"xattr3\":\"xvalue3\"}"; test1["object1.attr3"] = "Im not an object"; +// test1["age"] = 64; future std::cout << test1 << std::endl; @@ -58,6 +59,8 @@ int main(int argc, char **argv) { test9 = test1["object1"]; std::cout << test9 << std::endl; std::cout << test9["attr3"] << std::endl; + + std::cout << test1.pretty() << std::endl; return 0; }