mirror of
https://github.com/davidallendj/gdpm.git
synced 2025-12-20 03:27:02 -07:00
- Change error code from `NONE` TO `IGNORE` - Added format function to utils - Implement version functions
35 lines
No EOL
634 B
C++
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+)$"));
|
|
}
|
|
} |