From 82a68f09ecf2440b22c2604fe207bbee1c5f4d3a Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 14 Jun 2026 22:24:52 +1200 Subject: feat: Added arrays for all literal types --- src/json.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/json.hpp') diff --git a/src/json.hpp b/src/json.hpp index 8ecd947..fb3a0b0 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -1,3 +1,5 @@ +#pragma once + #include "json.h" #include @@ -53,4 +55,21 @@ namespace TehJSON }; data = std::make_shared(value); } + + template + std::vector JSON::readVector(TokenType type, T(*strToT)(const std::string)) + { + std::vector vec; + while(nextTokenType() != TokenType::RSquare) + { + if(nextTokenType() != type) + throw std::runtime_error("Array must be of all the same type"); + vec.push_back(strToT(consume(type).content)); + if(nextTokenType() == TokenType::Comma) + { + consume(TokenType::Comma); + } + } + return vec; + } } -- cgit v1.2.3