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. 1
      src/bakatoolspch.h

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

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

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

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

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

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

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