aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/object.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2013-02-10 21:53:22 +0000
committerMike Buland <eichlan@xagasoft.com>2013-02-10 21:53:22 +0000
commit1538ef47d1d4cc08e5f9c5894350bfa225866d40 (patch)
treecaacdbe75db8a134a14074229892af2dbebf1ad1 /c++-libbu++/src/object.cpp
parent058caf24d2b48ab6b49ae8efe5e1eb1ed246eff1 (diff)
downloadlibgats-1538ef47d1d4cc08e5f9c5894350bfa225866d40.tar.gz
libgats-1538ef47d1d4cc08e5f9c5894350bfa225866d40.tar.bz2
libgats-1538ef47d1d4cc08e5f9c5894350bfa225866d40.tar.xz
libgats-1538ef47d1d4cc08e5f9c5894350bfa225866d40.zip
Made the gats text parser much more robust.
Diffstat (limited to '')
-rw-r--r--c++-libbu++/src/object.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/c++-libbu++/src/object.cpp b/c++-libbu++/src/object.cpp
index db7b80b..faeca16 100644
--- a/c++-libbu++/src/object.cpp
+++ b/c++-libbu++/src/object.cpp
@@ -80,12 +80,12 @@ Gats::Object *Gats::Object::read( Bu::Stream &rIn )
80 return pObj; 80 return pObj;
81} 81}
82 82
83void Gats::Object::skipWs( Bu::String::const_iterator &i ) 83void Gats::Object::skipWs( Gats::Object::StrPos &i )
84{ 84{
85 for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { } 85 for(; *i == ' ' || *i == '\t' || *i == '\r' || *i == '\n'; i++ ) { }
86} 86}
87 87
88Bu::String Gats::Object::token( Bu::String::const_iterator &i ) 88Bu::String Gats::Object::token( Gats::Object::StrPos &i )
89{ 89{
90 Bu::String sRet; 90 Bu::String sRet;
91 if( *i == '\"' ) 91 if( *i == '\"' )
@@ -111,7 +111,12 @@ Bu::String Gats::Object::token( Bu::String::const_iterator &i )
111 return sRet; 111 return sRet;
112} 112}
113 113
114Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i ) 114Bu::String::FormatProxy Gats::Object::posError( Gats::Object::StrPos &i, const Bu::String &msg )
115{
116 return msg.format( new Thrower(i) );
117}
118
119Gats::Object *Gats::Object::strToGats( Gats::Object::StrPos &i )
115{ 120{
116 skipWs( i ); 121 skipWs( i );
117 122
@@ -145,7 +150,8 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i )
145 return pLst; 150 return pLst;
146 151
147 default: 152 default:
148 throw Bu::ExceptionBase("Invalid character found."); 153 posError(i, "Expected ',' or ']' but found '%1'.").
154 arg( *i );
149 } 155 }
150 } 156 }
151 } 157 }
@@ -164,16 +170,18 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i )
164 return pDict; 170 return pDict;
165 } 171 }
166 if( *i != '\"' ) 172 if( *i != '\"' )
167 throw Bu::ExceptionBase("Keys must be quoted strings."); 173 posError(i, "Dictionary keys must be quoted strings.");
168 Bu::String sKey = token( i ); 174 Bu::String sKey = token( i );
169 skipWs( i ); 175 skipWs( i );
170 if( *i != ':' ) 176 if( *i != ':' )
171 throw Bu::ExceptionBase("Keys and values must be " 177 posError(i, "Dictionary keys and values must be "
172 "seperated with colons."); 178 "seperated with colons.");
179 StrPos ih( i );
173 i++; 180 i++;
181 skipWs( i );
174 Gats::Object *pObj = strToGats( i ); 182 Gats::Object *pObj = strToGats( i );
175 if( !pObj ) 183 if( !pObj )
176 throw Bu::ExceptionBase("No value object found."); 184 posError(ih, "Dictionary key has no value.");
177 pDict->insert( sKey, pObj ); 185 pDict->insert( sKey, pObj );
178 skipWs( i ); 186 skipWs( i );
179 switch( *i ) 187 switch( *i )
@@ -187,7 +195,8 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i )
187 return pDict; 195 return pDict;
188 196
189 default: 197 default:
190 throw Bu::ExceptionBase("Invalid character found."); 198 posError(i, "Expected ',' or '}' but found '%1'.")
199 .arg( *i );
191 } 200 }
192 } 201 }
193 } 202 }
@@ -277,7 +286,7 @@ Gats::Object *Gats::Object::strToGats( Bu::String::const_iterator &i )
277 286
278Gats::Object *Gats::Object::strToGats( const Bu::String &sStr ) 287Gats::Object *Gats::Object::strToGats( const Bu::String &sStr )
279{ 288{
280 Bu::String::const_iterator i = sStr.begin(); 289 StrPos i( sStr.begin() );
281 290
282 return strToGats( i ); 291 return strToGats( i );
283} 292}