-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperfunctions.h
More file actions
51 lines (43 loc) · 1.14 KB
/
helperfunctions.h
File metadata and controls
51 lines (43 loc) · 1.14 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
#pragma once
#include <algorithm>
#include <cctype>
#include <locale>
#include <string>
// trim from start (in place)
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)
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)
inline void trim(std::string &s) {
rtrim(s);
ltrim(s);
}
inline bool IsNumeric(const std::string& s)
{
if (s.length() == 0) return false;
for (int i = 0; i < s.length(); ++i)
{
if ((s[i] >= '0' && s[i] <= '9')
|| s[i] == ' '
|| s[i] == '.'
|| (s[i] == '-' && i == 0))
continue;
return false;
}
return true;
}
/// Returns the number of ticks since an undefined time (usually system startup).
inline uint64_t GetTickCountMs()
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint64_t)(ts.tv_nsec / 1000000) + ((uint64_t)ts.tv_sec * 1000ull);
}