-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelper.cpp
More file actions
41 lines (35 loc) · 962 Bytes
/
helper.cpp
File metadata and controls
41 lines (35 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "helper.h"
#include "../utils/string_utils.h"
#include <algorithm>
#include <sstream>
VersionHelper::VersionHelper(std::string str)
{
// Remove whitespaces chars and a leading 'v'
str = left_trim<char>(trim<char>(str), "v");
// Replace '.' with spaces
replace_chars(str, ".", ' ');
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");
}
}
VersionHelper::VersionHelper(const size_t major, const size_t minor, const size_t revision) :
major{ major },
minor{ minor },
revision{ revision }
{
}
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;
}