Working json

main
anulax1225 ago%!(EXTRA string=11 months)
parent 6f850b9e9e
commit e73d4f3cfb
  1. 1
      premake5.lua
  2. 1
      src/bakatools/json/json_lexer.h
  3. 59
      src/bakatools/json/json_node.cpp
  4. 2
      src/bakatools/json/json_node.h
  5. 2
      src/bakatools/json/json_parser.cpp
  6. 2
      src/bakatools/json/json_parser.h
  7. 3
      src/bakatoolspch.h

@ -8,6 +8,7 @@ project "bakatools"
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}")
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}")
--buildoptions { "-Wall", "-Wextra" }
includedirs
{
"%{IncludeDirs.spdlog}",

@ -4,7 +4,6 @@
#include <bakatools/file_system/file.h>
#include <bakatools/container/data_stream.h>
#include <bakatools/string/format.h>
#include <bakatools/logging/log.h>
#include "json_node.h"
namespace Bk::Json

@ -2,63 +2,64 @@
namespace Bk::Json
{
std::string Node::to_string(int indent) {
std::string spaceString = std::string(indent, ' ');
std::string outputString = "";
std::string space_string = std::string(indent, ' ');
std::string output_string = "";
switch (type) {
case Type::STRING:
{
outputString += spaceString + *values.s;
break;
output_string += '"' + *values.s + '"';
return output_string;
}
case Type::NUMBER:
{
outputString += spaceString + std::to_string(values.fValue);
break;
output_string += std::to_string(values.fValue);
return output_string;
}
case Type::BOOLEAN:
{
outputString += spaceString + (values.bValue ? "true" : "false");
break;
output_string += (values.bValue ? "true" : "false");
return output_string;
}
case Type::NULL_TYPE:
{
outputString += spaceString + "null";
break;
output_string += "null";
return output_string;
}
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";
output_string += "\n" + space_string + "[\n";;
for (int i = 0; i < (*values.list).size() - 1; i++)
{
output_string += get_list()[i]->to_string(indent + 4);
if (i < (*values.list).size() - 2)
{
output_string += ",\n";
} else {
break;
}
index++;
}
outputString += "\n" + spaceString + "]\n";
break;
output_string += "\n" + space_string + "]";
return output_string;
}
case Type::OBJECT:
{
outputString += spaceString + "{\n";
for (JSONObject::iterator i = (*values.object).begin(); i != (*values.object).end(); i++)
output_string += space_string + "{\n";
for (Object::iterator i = (*values.object).begin(); i != (*values.object).end(); i++)
{
outputString += spaceString + " " + "\"" + i->first + "\"" + ": ";
outputString += i->second->toString(indent + 1);
JSONObject::iterator next = i;
output_string += space_string + " " + "\"" + i->first + "\"" + ": ";
output_string += i->second->to_string(indent + 4);
Object::iterator next = i;
next++;
if ((next) != (*values.object).end())
{
outputString += ",\n";
output_string += ",\n";
}
outputString += spaceString + "\n";
}
outputString += spaceString + "}";
output_string += "\n" + space_string + "}";
return output_string;
}
}
return outputString;
return "";
}
void Node::set_object(Object *object)
{

@ -39,7 +39,7 @@ namespace Bk::Json
void set_null();
bool is_null();
std::string to_string(int indent = 3);
std::string to_string(int indent = 0);
private:
union Values {

@ -76,7 +76,7 @@ namespace Bk::Json
}
}
}
catch(std::logic_error e)
catch(std::logic_error& e)
{
BK_INFO(e.what());
auto node = std::shared_ptr<Json::Node>();

@ -1,8 +1,6 @@
#pragma once
#include <bakatoolspch.h>
#include <bakatools/file_system/file.h>
#include <bakatools/container/data_stream.h>
#include "json_lexer.h"
namespace Bk::Json

@ -19,4 +19,5 @@
#include <thread>
#include <chrono>
#include <bakatools/base.h>
#include <bakatools/base.h>
#include <bakatools/logging/log.h>
Loading…
Cancel
Save