-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_utilities.cpp
More file actions
80 lines (66 loc) · 2.21 KB
/
random_utilities.cpp
File metadata and controls
80 lines (66 loc) · 2.21 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
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <chrono>
#include <memory>
#include <array>
#include <unordered_map>
namespace utils
{
enum log_index
{
TIME = 0,
STATE = 1,
PLAYER_USER = 3,
TARGET = 7,
ID = 10,
NAME = 11,
CRIT = 39
};
// I'm using a fixed array because it's good enough and a vector takes way, way longer (well, relative to whatever it's at right now)
std::array<std::string, log_index::CRIT+1> populate_index( const std::string& str )
{
std::array<std::string, log_index::CRIT+1> fields {};
size_t end = str.find(" ") + 1;
size_t start = str.find(" ");
fields[log_index::TIME] = str.substr( start + 1, str.find("-") - start - 1 );
for ( int z = log_index::STATE; z < fields.size(); z++ )
{
start = end;
end = str.find_first_of( ',' , end+1 );
fields[z] = str.substr( start + 1, end - start - 1 );
if ( end == std::string::npos )
return fields;
}
return fields;
}
std::string format_zeros( const double& n, const size_t& placements = 3 )
{
std::string s = std::to_string( n );
for ( int i = 0; i < placements + 1; i++ )
if ( ( s.back() == '0' && i < placements ) || s.back() == '.' )
s.pop_back();
else
return s;
return s;
}
std::string format_alignment( const std::string& sv, const unsigned placements = 21 )
{
unsigned s_len = sv.length();
if ( !placements || s_len >= placements )
return static_cast<std::string>(sv);
return static_cast<std::string>(sv).append( placements - s_len, ' ' );
}
std::string between_char( const std::string& str, const char end = '"', const char start = '"' )
{
const size_t a = str.find( start );
if ( a == std::string::npos )
return str;
const size_t b = start == end ? str.rfind( end ) : str.find( end ) ;
if ( b == std::string::npos )
return str;
return static_cast<std::string>( str ).substr( a+1, b - a - 1 );
}
}