-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.cpp
44 lines (40 loc) · 1.11 KB
/
format.cpp
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
42
43
44
#include "semverutil/format.hpp"
#include "semverutil/detail/format.hpp"
#include <sstream>
auto semver::write_formatted(SemVer const& semver,
std::string_view format_string,
std::string& output) -> bool
{
auto const handler = [&](std::string_view val, char token_type) {
if (token_type == 0) {
output += val;
return true;
}
std::stringstream writer {};
switch (token_type) {
case 'M':
writer << semver.major();
break;
case 'N':
writer << semver.minor();
break;
case 'P':
writer << semver.patch();
break;
case 'R':
writer << semver.revision();
break;
case 'L':
writer << semver.prerelease;
break;
case 'D':
writer << semver.metadata;
break;
default:
return false;
}
output += writer.str();
return true;
};
return detail::parse_format_string(format_string, handler);
}