From 3cbd1038e20dcb2b25db4e74666ec21766642729 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 6 Apr 2022 23:45:42 -0700 Subject: toString works. It does indent automatically. I figure, you know, if you're converting to a string then a big part of the reason is so you can read it. In that case, why make it optional? --- c++-qt/src/dictionary.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'c++-qt/src/dictionary.cpp') diff --git a/c++-qt/src/dictionary.cpp b/c++-qt/src/dictionary.cpp index 10ec6c5..1d666ac 100644 --- a/c++-qt/src/dictionary.cpp +++ b/c++-qt/src/dictionary.cpp @@ -73,6 +73,52 @@ void Gats::Dictionary::read( QIODevice &rIn, char /*cType*/ ) } } +QString Gats::Dictionary::toString( int iIndent ) const +{ + if( count() == 0 ) + return "{ }"; + QString sRet("{"); + iIndent++; + for( const_iterator i = begin(); i != end(); i++ ) + { + if( i == begin() ) + { + sRet += "\n"; + } + else + { + sRet += ",\n"; + } + for( int j = 0; j < iIndent; j++ ) sRet += " "; + sRet += '"'; + for( QByteArray::const_iterator iS = i.key().begin(); + iS != i.key().end(); iS++ ) + { + switch( *iS ) + { + case '\\': + sRet += "\\"; + break; + + case '\"': + sRet += "\\\""; + break; + + default: + sRet += *iS; + break; + } + } + sRet += "\": "; + sRet += i.value()->toString( iIndent ); + } + iIndent--; + sRet += "\n"; + for( int j = 0; j < iIndent; j++ ) sRet += " "; + sRet += "}"; + return sRet; +} + void Gats::Dictionary::insert( const QByteArray &sKey, char i ) { ((QHash *)this)->insert( -- cgit v1.2.3