added a pretty output to JString.

This commit is contained in:
barant 2024-12-18 09:49:34 -08:00
parent d74fa9689d
commit 7eb2417456
4 changed files with 29 additions and 18 deletions

View File

@ -179,27 +179,40 @@ namespace coreutils {
ch = nextChar(); ch = nextChar();
if(ch == '{') { if(ch == '{') {
index += 3; index += 3;
std::cout << "{\n"; output << ch << '\n';
for(int ix = 0; ix < index; ++ix) for(int ix = 0; ix < index; ++ix)
std::cout << ' '; output << ' ';
}
else if(ch == '[') {
index += 3;
output << ch << '\n';
for(int ix = 0; ix < index; ++ix)
output << ' ';
} }
else if(ch == ':') { else if(ch == ':') {
std::cout << ": "; output << ": ";
} }
else if(ch == '}') { else if(ch == '}') {
index -= 3; index -= 3;
std::cout << '\n'; output << '\n';
for(int ix = 0; ix < index; ++ix) for(int ix = 0; ix < index; ++ix)
std::cout << ' '; output << ' ';
std::cout << ch << '\n'; output << ch;
}
else if(ch == ']') {
index -= 3;
output << '\n';
for(int ix = 0; ix < index; ++ix)
output << ' ';
output << ch;
} }
else if(ch == ',') { else if(ch == ',') {
std::cout << ",\n"; output << ch << '\n';
for(int ix = 0; ix < index; ++ix) for(int ix = 0; ix < index; ++ix)
std::cout << ' '; output << ' ';
} }
else else
std::cout << ch; output << ch;
} }
return output; return output;
} }

View File

@ -186,13 +186,11 @@ namespace coreutils {
return *this; return *this;
} }
// MString &MString::operator<<(std::string value) { MString &MString::operator<<(char value) {
// int temp = length; setSize(length + 1);
// int len = length + value.length(); data[length - 1] = value;
// setSize(len); return *this;
// memcpy(data + temp, value.c_str(), value.length()); }
// return *this;
// }
// MString &MString::operator<<(std::ostream (*f)(std::ostream&)) { // MString &MString::operator<<(std::ostream (*f)(std::ostream&)) {
MString &MString::operator<<(std::basic_ostream<char> (*pf)(std::basic_ostream<char>&)) { MString &MString::operator<<(std::basic_ostream<char> (*pf)(std::basic_ostream<char>&)) {

View File

@ -157,7 +157,7 @@ namespace coreutils {
/// ///
/// ///
// MString &operator<<(std::string value); MString &operator<<(char value);
/// ///
/// ///

Binary file not shown.