-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtc_tools.cpp
More file actions
42 lines (33 loc) · 1.07 KB
/
rtc_tools.cpp
File metadata and controls
42 lines (33 loc) · 1.07 KB
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
#include "irtc.hpp"
#include <numeric>
#include <range/v3/algorithm.hpp>
#include <range/v3/view/common.hpp>
#include <range/v3/view/drop.hpp>
#include <range/v3/view/split.hpp>
#include <range/v3/view/take.hpp>
#include <ranges>
#include <numeric>
#include <fmt/format.h>
#include <stdexcept>
namespace rg = ranges;
namespace rgv = ranges::views;
using std::literals::operator""sv;
auto IRTC::parse_adjfile(std::string_view adj) -> Clock {
rg::split_view view{adj, "\n"sv};
auto tz = view | rgv::drop(2) | rgv::take(1);
IRTC::Clock res = IRTC::Clock::INVALID;
constexpr auto UTC_literal = "UTC"sv;
constexpr auto LOCAL_literal = "LOCAL"sv;
for (const auto v : tz) {
if (rg::equal(rg::begin(v), rg::end(v), UTC_literal.begin(),
UTC_literal.end())) {
res = IRTC::Clock::UTC;
} else if (rg::equal(rg::begin(v), rg::end(v), LOCAL_literal.begin(),
LOCAL_literal.end())) {
res = IRTC::Clock::LOCAL;
};
}
if (res == IRTC::Clock::INVALID)
throw std::runtime_error("malformed adjustment file");
return res;
}