2020-02-25 16:44:13 +08:00
|
|
|
#include "pch.h"
|
|
|
|
#include "VersionHelper.h"
|
|
|
|
|
2020-08-26 20:03:53 +08:00
|
|
|
#include "string_utils.h"
|
|
|
|
|
2020-02-25 16:44:13 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
VersionHelper::VersionHelper(std::string str)
|
|
|
|
{
|
2020-08-26 20:03:53 +08:00
|
|
|
// Remove whitespaces chars and a leading 'v'
|
2020-09-02 23:34:17 +08:00
|
|
|
str = left_trim<char>(trim<char>(str), "v");
|
2020-08-26 20:03:53 +08:00
|
|
|
// Replace '.' with spaces
|
|
|
|
replace_chars(str, ".", ' ');
|
2020-02-25 16:44:13 +08:00
|
|
|
|
2020-08-26 20:03:53 +08:00
|
|
|
std::istringstream ss{ str };
|
|
|
|
ss >> major;
|
|
|
|
ss >> minor;
|
|
|
|
ss >> revision;
|
|
|
|
if (ss.fail() || !ss.eof())
|
|
|
|
{
|
|
|
|
throw std::logic_error("VersionHelper: couldn't parse the supplied version string");
|
|
|
|
}
|
2020-02-25 16:44:13 +08:00
|
|
|
}
|
|
|
|
|
2020-08-26 20:03:53 +08:00
|
|
|
VersionHelper::VersionHelper(const size_t major, const size_t minor, const size_t revision) :
|
|
|
|
major{ major },
|
|
|
|
minor{ minor },
|
|
|
|
revision{ revision }
|
2020-02-25 16:44:13 +08:00
|
|
|
{
|
|
|
|
}
|
2020-04-27 18:39:47 +08:00
|
|
|
|
|
|
|
std::wstring VersionHelper::toWstring() const
|
|
|
|
{
|
|
|
|
std::wstring result{ L"v" };
|
|
|
|
result += std::to_wstring(major);
|
|
|
|
result += L'.';
|
|
|
|
result += std::to_wstring(minor);
|
|
|
|
result += L'.';
|
|
|
|
result += std::to_wstring(revision);
|
|
|
|
return result;
|
|
|
|
}
|