added a pretty output to JString. Initial.
This commit is contained in:
parent
d1e5e41ab2
commit
d74fa9689d
34
JString.cpp
34
JString.cpp
@ -170,4 +170,38 @@ namespace coreutils {
|
|||||||
reset();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ namespace coreutils {
|
|||||||
return jstring.find(key).str();
|
return jstring.find(key).str();
|
||||||
}
|
}
|
||||||
|
|
||||||
Proxy& operator=(coreutils::ZString value) {
|
Proxy& operator=(coreutils::MString value) {
|
||||||
jstring.set(key, value);
|
jstring.set(key, value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -83,6 +83,8 @@ namespace coreutils {
|
|||||||
|
|
||||||
JString & operator=(coreutils:: ZString value);
|
JString & operator=(coreutils:: ZString value);
|
||||||
|
|
||||||
|
MString pretty();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void removeWhitespace();
|
void removeWhitespace();
|
||||||
|
|
||||||
|
Binary file not shown.
@ -27,6 +27,7 @@ int main(int argc, char **argv) {
|
|||||||
test1["object1"] = "{\"attr1\":\"value1\",\"attr2\":\"value2\",\"attr3\":\"value3\"}";
|
test1["object1"] = "{\"attr1\":\"value1\",\"attr2\":\"value2\",\"attr3\":\"value3\"}";
|
||||||
test1["object1.attr2"] = "{\"xattr1\":\"xvalue1\",\"xattr2\":\"xvalue2\",\"xattr3\":\"xvalue3\"}";
|
test1["object1.attr2"] = "{\"xattr1\":\"xvalue1\",\"xattr2\":\"xvalue2\",\"xattr3\":\"xvalue3\"}";
|
||||||
test1["object1.attr3"] = "Im not an object";
|
test1["object1.attr3"] = "Im not an object";
|
||||||
|
// test1["age"] = 64; future
|
||||||
|
|
||||||
std::cout << test1 << std::endl;
|
std::cout << test1 << std::endl;
|
||||||
|
|
||||||
@ -59,6 +60,8 @@ int main(int argc, char **argv) {
|
|||||||
std::cout << test9 << std::endl;
|
std::cout << test9 << std::endl;
|
||||||
std::cout << test9["attr3"] << std::endl;
|
std::cout << test9["attr3"] << std::endl;
|
||||||
|
|
||||||
|
std::cout << test1.pretty() << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user