Created
November 8, 2020 01:34
-
-
Save mincrmatt12/ee57c220e71cc101d745bbb939d644a8 to your computer and use it in GitHub Desktop.
MSign json tester
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "json.h" | |
#include <iostream> | |
void show_stack(json::PathNode &pn) { | |
if (pn.is_root()) { | |
std::cout << "(root)"; | |
return; | |
} | |
std::cout << pn.name; | |
if (pn.is_array()) { | |
std::cout << "[" << (int)pn.index << "]"; | |
} | |
} | |
void callback(json::PathNode ** stack, uint8_t sptr, const json::Value& value) { | |
for (int i = 0; i < sptr; ++i) { | |
if (i) { | |
std::cout << "<-"; | |
} | |
show_stack(*stack[i]); | |
} | |
std::cout << " = "; | |
switch (value.type) { | |
case json::Value::BOOL: | |
if (value.bool_val) std::cout << "true"; | |
else std::cout << "false"; | |
break; | |
case json::Value::FLOAT: | |
std::cout << value.float_val << "f"; | |
break; | |
case json::Value::INT: | |
std::cout << value.int_val; | |
break; | |
case json::Value::NONE: | |
std::cout << "null"; | |
break; | |
case json::Value::OBJ: | |
std::cout << "{}"; | |
break; | |
case json::Value::STR: | |
std::cout << '"' << value.str_val << '"'; | |
default: | |
break; | |
} | |
std::cout << "\n"; | |
} | |
int main(int argc, char ** argv) { | |
json::JSONParser p(callback); | |
p.parse([]() -> int16_t { | |
int x = getchar(); | |
if (x == EOF) return 0; | |
return x; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment