Added json parser module

main
anulax1225 ago%!(EXTRA string=11 months)
parent fc90bfb982
commit 6f850b9e9e
  1. 59
      src/bakatools/json/json_node.cpp
  2. 2
      src/bakatools/json/json_node.h

@ -1,6 +1,65 @@
#include "json_node.h" #include "json_node.h"
namespace Bk::Json namespace Bk::Json
{ {
std::string Node::to_string(int indent) {
std::string spaceString = std::string(indent, ' ');
std::string outputString = "";
switch (type) {
case Type::STRING:
{
outputString += spaceString + *values.s;
break;
}
case Type::NUMBER:
{
outputString += spaceString + std::to_string(values.fValue);
break;
}
case Type::BOOLEAN:
{
outputString += spaceString + (values.bValue ? "true" : "false");
break;
}
case Type::NULL_TYPE:
{
outputString += spaceString + "null";
break;
}
case Type::LIST:
{
// std::cout << "[";
outputString += spaceString + "[\n";
int index = 0;
for (auto node : (*values.list)) {
outputString += node->toString(indent + 1);
if (index < (*values.list).size() - 1) {
outputString += ",\n";
}
index++;
}
outputString += "\n" + spaceString + "]\n";
break;
}
case Type::OBJECT:
{
outputString += spaceString + "{\n";
for (JSONObject::iterator i = (*values.object).begin(); i != (*values.object).end(); i++)
{
outputString += spaceString + " " + "\"" + i->first + "\"" + ": ";
outputString += i->second->toString(indent + 1);
JSONObject::iterator next = i;
next++;
if ((next) != (*values.object).end())
{
outputString += ",\n";
}
outputString += spaceString + "\n";
}
outputString += spaceString + "}";
}
}
return outputString;
}
void Node::set_object(Object *object) void Node::set_object(Object *object)
{ {
values.object = object; values.object = object;

@ -39,6 +39,8 @@ namespace Bk::Json
void set_null(); void set_null();
bool is_null(); bool is_null();
std::string to_string(int indent = 3);
private: private:
union Values { union Values {
Object* object; Object* object;

Loading…
Cancel
Save