gdpm/src/version.cpp
David J. Allen d2a77fe28f Bump default godot version for search
- Change error code from `NONE` TO `IGNORE`
- Added format function to utils
- Implement version functions
2024-01-27 14:34:17 -07:00

35 lines
No EOL
634 B
C++

#include "version.hpp"
#include <regex>
namespace gdpm::version{
void print(){
}
string to_string(const context& c){
return utils::format("{}.{}.{}", c.major, c.minor, c.patch);
}
result_t<context> to_version(const string& version){
context 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+)$"));
}
}