summaryrefslogtreecommitdiff
path: root/src/test_gason.cc
blob: d78c385084cf0a44c627d85b415f0d69f4033e24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>

/*
 * https://github.com/vivkin/gason
 *
 */
#include "gason/gason.h"

using namespace std;


void
print(const char *s)
{
  string u(s);
  u = u.substr(1, 4);
  if (u == "Goal") {
    cerr << u << endl;
  }
}

void
walk(JsonValue o)
{
	switch (o.getTag()) {
		case JSON_TAG_NUMBER:
			break;
		case JSON_TAG_BOOL:
			break;
		case JSON_TAG_STRING:
			print(o.toString());
			break;
		case JSON_TAG_ARRAY:
			if (!o.toNode())
				break;
			for (auto i : o)
				walk(i->value);
			break;
		case JSON_TAG_OBJECT:
			if (!o.toNode())
				break;
			for (auto i : o) {
				print(i->key);
				walk(i->value);
			}
			break;
		case JSON_TAG_NULL:
			break;
	}
}

int
main(int argc, char** argv)
{
  ifstream ifs(argv[1]);
  string json_str((istreambuf_iterator<char>(ifs)),
                   (istreambuf_iterator<char>()));

  char* s = strdup(json_str.c_str());
  char *p;
  JsonValue v;
  JsonAllocator a;
  JsonParseStatus status = jsonParse(s, &p, &v, a);
  walk(v);

  return 0;
}