aboutsummaryrefslogtreecommitdiff
path: root/c++-qt/src/dictionary.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2022-04-06 23:45:42 -0700
committerMike Buland <eichlan@xagasoft.com>2022-04-06 23:45:42 -0700
commit3cbd1038e20dcb2b25db4e74666ec21766642729 (patch)
tree1fab95855d344196a44feadda75bfc0a5a63b61f /c++-qt/src/dictionary.cpp
parentb522669649e81c61c6a5e390991b8fd70bfdeed9 (diff)
downloadlibgats-3cbd1038e20dcb2b25db4e74666ec21766642729.tar.gz
libgats-3cbd1038e20dcb2b25db4e74666ec21766642729.tar.bz2
libgats-3cbd1038e20dcb2b25db4e74666ec21766642729.tar.xz
libgats-3cbd1038e20dcb2b25db4e74666ec21766642729.zip
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?
Diffstat (limited to '')
-rw-r--r--c++-qt/src/dictionary.cpp46
1 files changed, 46 insertions, 0 deletions
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*/ )
73 } 73 }
74} 74}
75 75
76QString Gats::Dictionary::toString( int iIndent ) const
77{
78 if( count() == 0 )
79 return "{ }";
80 QString sRet("{");
81 iIndent++;
82 for( const_iterator i = begin(); i != end(); i++ )
83 {
84 if( i == begin() )
85 {
86 sRet += "\n";
87 }
88 else
89 {
90 sRet += ",\n";
91 }
92 for( int j = 0; j < iIndent; j++ ) sRet += " ";
93 sRet += '"';
94 for( QByteArray::const_iterator iS = i.key().begin();
95 iS != i.key().end(); iS++ )
96 {
97 switch( *iS )
98 {
99 case '\\':
100 sRet += "\\";
101 break;
102
103 case '\"':
104 sRet += "\\\"";
105 break;
106
107 default:
108 sRet += *iS;
109 break;
110 }
111 }
112 sRet += "\": ";
113 sRet += i.value()->toString( iIndent );
114 }
115 iIndent--;
116 sRet += "\n";
117 for( int j = 0; j < iIndent; j++ ) sRet += " ";
118 sRet += "}";
119 return sRet;
120}
121
76void Gats::Dictionary::insert( const QByteArray &sKey, char i ) 122void Gats::Dictionary::insert( const QByteArray &sKey, char i )
77{ 123{
78 ((QHash<QByteArray, Gats::Object *> *)this)->insert( 124 ((QHash<QByteArray, Gats::Object *> *)this)->insert(