From 1d379a5cf34475f66f2ab9359f77dac162c0a40e Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 6 Jun 2026 19:36:41 +1200 Subject: feat: JSON reading - Implemented a tokenizer for json - Implemented a method which will read json from a string using the tokenizer --- src/json.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/json.h') diff --git a/src/json.h b/src/json.h index d1d7938..efde542 100644 --- a/src/json.h +++ b/src/json.h @@ -1,7 +1,12 @@ +#pragma once + +#include "tokenizer.h" + #include #include #include #include +#include namespace TehJSON { @@ -12,14 +17,19 @@ namespace TehJSON JSON(const JSON& other) = default; ~JSON(); + // Writing methods + std::string getSerialized(); + std::string _getSerialized(int currIndent); + + // Reading methods + void readFromString(std::string s); + // Leaf methods template T& get(); template void set(T value); std::string leafType(); - std::string getSerialized(); - std::string _getSerialized(int currIndent); template static std::string serializeData(std::shared_ptr data); @@ -30,6 +40,14 @@ namespace TehJSON private: bool isLeaf = false; + // Reading data fields + std::vector tokens; + int tokenPos = 0; + Token consume(); + Token consume(TokenType type); + TokenType nextTokenType(); + int readFromTokens(std::vector tokens, int pos); + // Leaf data fields std::shared_ptr data; std::string (*dataSerializer)(std::shared_ptr); -- cgit v1.2.3