From d2a77fe28f965ad9b147f0472082b910fb2ead2f Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Sat, 27 Jan 2024 14:34:17 -0700 Subject: [PATCH] Bump default godot version for search - Change error code from `NONE` TO `IGNORE` - Added format function to utils - Implement version functions --- include/error.hpp | 4 ++-- include/rest_api.hpp | 2 +- include/utils.hpp | 6 ++++++ include/version.hpp | 18 ++++++++++++------ src/config.cpp | 2 +- src/version.cpp | 29 ++++++++++++++++++++++++----- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/include/error.hpp b/include/error.hpp index 59bacb3..8ce1b33 100644 --- a/include/error.hpp +++ b/include/error.hpp @@ -11,7 +11,7 @@ namespace gdpm::constants::error{ enum class ec{ - NONE = 0, + IGNORE = 0, UNKNOWN, UNKNOWN_COMMAND, UNKNOWN_ARGUMENT, @@ -93,7 +93,7 @@ namespace gdpm{ namespace ce = constants::error; class error { public: - constexpr explicit error(ec code = ec::NONE, const string& message = "{default}"): + constexpr explicit error(ec code = ec::IGNORE, const string& message = "{default}"): m_code(code), m_message(utils::replace_all(message, "{default}", ce::get_message(code))) {} diff --git a/include/rest_api.hpp b/include/rest_api.hpp index efcc351..0c11c1f 100644 --- a/include/rest_api.hpp +++ b/include/rest_api.hpp @@ -53,7 +53,7 @@ namespace gdpm::rest_api{ int support; string user = ""; string cost = ""; - string godot_version = "4.0"; + string godot_version = "4.3"; int max_results = 500; int page; int offset; diff --git a/include/utils.hpp b/include/utils.hpp index 3a75be3..dfebb51 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -78,6 +78,11 @@ namespace gdpm::utils { return a; } + template + std::string format(std::string_view fmt, Args&&...args){ + return std::vformat(fmt, std::make_format_args(args...)); + } + bool to_bool(const std::string& s); std::vector split_lines(const std::string& contents); std::string readfile(const std::string& path); @@ -97,6 +102,7 @@ namespace gdpm::utils { std::string join(const std::vector& target, const std::string& delimiter = ", "); std::string join(const std::unordered_map& target, const std::string& prefix = "", const std::string& delimiter = "\n"); std::string convert_size(long size); + // TODO: Add function to get size of decompressed zip namespace json { diff --git a/include/version.hpp b/include/version.hpp index b06715f..d267b2c 100644 --- a/include/version.hpp +++ b/include/version.hpp @@ -1,14 +1,20 @@ #pragma once +#include "error.hpp" +#include "result.hpp" + #include + namespace gdpm::version{ - struct version_context{ - int major; - int minor; - int patch; + struct context{ + int major = 0; + int minor = 0; + int patch = 0; + string commit = ""; }; - std::string to_string(const version_context& context); - version_context to_version(const std::string& version); + std::string to_string(const context& context); + result_t to_version(const std::string& version); + bool is_valid_version_string(const std::string& version); } \ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index c501b31..fc00107 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -343,7 +343,7 @@ namespace gdpm::config{ error.set_message("Key `remote_sources` is not a JSON object."); return error; } - error.set_code(ec::NONE); + error.set_code(ec::IGNORE); return error; } diff --git a/src/version.cpp b/src/version.cpp index 167f502..9cf8922 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -1,16 +1,35 @@ + #include "version.hpp" +#include + namespace gdpm::version{ + + void print(){ + + } - std::string to_string(const version_context& context){ - return std::string(); + string to_string(const context& c){ + return utils::format("{}.{}.{}", c.major, c.minor, c.patch); } - version_context to_version(const std::string& version){ - version_context v; + result_t to_version(const string& version){ + context v; - return v; + // check if string is valid + if(!is_valid_version_string(version)){ + return result_t(context(), error(ec::IGNORE, "invalid version string")); + } + + // convert string to version context + + + return result_t(v, error()); + } + + bool is_valid_version_string(const string &version){ + return std::regex_match(version, std::regex("^(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$")); } } \ No newline at end of file