forked from duckman6969/fix-skill-issue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
83 lines (72 loc) · 2.16 KB
/
Utils.cpp
File metadata and controls
83 lines (72 loc) · 2.16 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include <iostream>
#include <sstream>
#include <sys/uio.h>
#include <math.h>
#include <algorithm>
#include <cctype>
#include <locale>
#include <iterator>
#include <chrono>
#include <thread>
#include <random>
static std::minstd_rand RandomGenerator { std::random_device()() };
namespace utils
{
template <typename T>
std::string convertNumberToString(const T a_value)
{
std::ostringstream out;
out.precision(6);
out << std::fixed << a_value;
return out.str();
}
// trim from start (in place)
static inline void ltrim(std::string &s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch)
{ return !std::isspace(ch); }));
}
// trim from end (in place)
static inline void rtrim(std::string &s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch)
{ return !std::isspace(ch); })
.base(),
s.end());
}
// trim from both ends (in place)
static inline void trim(std::string &s)
{
ltrim(s);
rtrim(s);
}
std::vector<std::string> static inline split(std::string s)
{
std::stringstream ss(s);
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
std::vector<std::string> tokens(begin, end);
return tokens;
}
bool toBool(std::string str)
{
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
std::istringstream is(str);
bool b;
is >> std::boolalpha >> b;
return b;
}
int randomInt(int minValue, int maxValue) {
return std::uniform_int_distribution<int>(minValue, maxValue)(RandomGenerator);
}
float randomFloat(float minValue, float maxValue) {
return std::uniform_real_distribution<float>(minValue, maxValue)(RandomGenerator);
}
void randomSleep(int minSleep, int maxSleep) {
std::this_thread::sleep_for(std::chrono::milliseconds(randomInt(minSleep, maxSleep)));
}
void clearScreen() {
printf("\e[H\e[2J\e[3J");
}
}