-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.h
66 lines (54 loc) · 1.86 KB
/
main.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include <iostream>
#include <chrono>
#include <map>
class PlayerStats;
void FindAndReplaceAll(std::string &data, const std::string& toSearch, const std::string& replaceStr)
{
// Get the first occurrence
size_t pos = data.find(toSearch);
// Repeat until end is reached
while (pos != std::string::npos)
{
// Replace this substring occurrence
data.replace(pos, toSearch.size(), replaceStr);
// Get the next occurrence from the current position
pos = data.find(toSearch, pos + replaceStr.size());
}
}
std::string ConvertMSToHHMMSS(std::chrono::milliseconds ms)
{
using namespace std::chrono;
std::stringstream ss;
// compute h, m, s
auto secs = duration_cast<seconds>(ms);
ms -= duration_cast<milliseconds>(secs);
auto mins = duration_cast<minutes>(secs);
secs -= duration_cast<seconds>(mins);
auto hour = duration_cast<hours>(mins);
mins -= duration_cast<minutes>(hour);
std::string hr(std::to_string(hour.count()));
std::string min(std::to_string(mins.count()));
std::string s(std::to_string(secs.count()));
//std::string msecs(std::to_string(ms.count()));
// msecs = msecs.substr(0, 2);
// add leading zero if needed
std::string hh = std::string(4 - hr.length(), '0') + hr;
std::string mm = std::string(2 - min.length(), '0') + min;
std::string sec = std::string(2 - s.length(), '0') + s;
// return mm:ss if hh is 0000
if (hh.compare("0000") != 0)
{
ss << hr << ":" << mm << ":" << sec;
}
else
{
ss << mm << ":" << sec;
}
return ss.str();
}
std::map<std::string, std::string> FetchDescriptions();
template<class T>
std::string getDescriptionForStat(const std::map<std::string, std::string>& desc, T stat);
PlayerStats FetchResults(const std::string& apiUrl);
void ParseResults(const PlayerStats& stats);