Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
lookaheadparser.cpp File Reference
#include "rapidjson/reader.h"
#include "rapidjson/document.h"
#include <iostream>
Include dependency graph for lookaheadparser.cpp:

Go to the source code of this file.

Classes

class  LookaheadParserHandler
 
class  LookaheadParser
 

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void )

Definition at line 285 of file lookaheadparser.cpp.

285 {
286 using namespace std;
287
288 char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null,"
289 "\"i\":123, \"pi\": 3.1416, \"a\":[-1, 2, 3, 4, \"array\", []], \"skipArrays\":[1, 2, [[[3]]]], "
290 "\"skipObject\":{ \"i\":0, \"t\":true, \"n\":null, \"d\":123.45 }, "
291 "\"skipNested\":[[[[{\"\":0}, {\"\":[-9.87]}]]], [], []], "
292 "\"skipString\":\"zzz\", \"reachedEnd\":null, \"t\":true }";
293
294 LookaheadParser r(json);
295
296 RAPIDJSON_ASSERT(r.PeekType() == kObjectType);
297
298 r.EnterObject();
299 while (const char* key = r.NextObjectKey()) {
300 if (0 == strcmp(key, "hello")) {
301 RAPIDJSON_ASSERT(r.PeekType() == kStringType);
302 cout << key << ":" << r.GetString() << endl;
303 }
304 else if (0 == strcmp(key, "t") || 0 == strcmp(key, "f")) {
305 RAPIDJSON_ASSERT(r.PeekType() == kTrueType || r.PeekType() == kFalseType);
306 cout << key << ":" << r.GetBool() << endl;
307 continue;
308 }
309 else if (0 == strcmp(key, "n")) {
310 RAPIDJSON_ASSERT(r.PeekType() == kNullType);
311 r.GetNull();
312 cout << key << endl;
313 continue;
314 }
315 else if (0 == strcmp(key, "pi")) {
316 RAPIDJSON_ASSERT(r.PeekType() == kNumberType);
317 cout << key << ":" << r.GetDouble() << endl;
318 continue;
319 }
320 else if (0 == strcmp(key, "a")) {
321 RAPIDJSON_ASSERT(r.PeekType() == kArrayType);
322
323 r.EnterArray();
324
325 cout << key << ":[ ";
326 while (r.NextArrayValue()) {
327 if (r.PeekType() == kNumberType) {
328 cout << r.GetDouble() << " ";
329 }
330 else if (r.PeekType() == kStringType) {
331 cout << r.GetString() << " ";
332 }
333 else {
334 r.SkipArray();
335 break;
336 }
337 }
338
339 cout << "]" << endl;
340 }
341 else {
342 cout << key << ":skipped" << endl;
343 r.SkipValue();
344 }
345 }
346
347 return 0;
348}
const mie::Vuint & r
Definition bn.cpp:28
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:406
Definition name.hpp:106
@ kFalseType
false
Definition rapidjson.h:646
@ kObjectType
object
Definition rapidjson.h:648
@ kTrueType
true
Definition rapidjson.h:647
@ kStringType
string
Definition rapidjson.h:650
@ kNullType
null
Definition rapidjson.h:645
@ kArrayType
array
Definition rapidjson.h:649
@ kNumberType
number
Definition rapidjson.h:651