-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.cpp
More file actions
85 lines (70 loc) · 1.95 KB
/
helpers.cpp
File metadata and controls
85 lines (70 loc) · 1.95 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
84
85
#include <sstream>
#include <string>
#include <vector>
// Parses a string of whitespace seperated integers into a vector.
std::vector<int> parseLineOfNumbers(const std::string_view line)
{
std::stringstream lineStream;
int nextNr;
std::vector<int> result{};
lineStream << line;
while (true)
{
lineStream >> nextNr; // Resharper seems to think this is invalid...
if (lineStream.fail())
{
break;
}
result.push_back(nextNr);
}
return result;
}
// Parses a string of whitespace seperated long long integers into a vector.
std::vector<long long> parseLineOfNumbersToLongLong(const std::string_view line)
{
std::stringstream lineStream;
long long nextNr;
std::vector<long long> result{};
lineStream << line;
while (true)
{
lineStream >> nextNr; // Resharper seems to also think this is invalid...
if (lineStream.fail())
{
break;
}
result.push_back(nextNr);
}
return result;
}
// Parses a string of integers seperated by a single non-whitespace symbol (such as ',') into a vector.
std::vector<int> parseLineOfSymbolSeperatedNumbers(const std::string_view line)
{
std::stringstream lineStream;
int nextNr;
std::vector<int> result{};
lineStream << line;
while (true)
{
lineStream >> nextNr; // Resharper seems to think this is invalid...
if (lineStream.fail())
{
break;
}
result.push_back(nextNr);
lineStream.ignore(1);
}
return result;
}
std::vector<std::string> splitStringBySeperator(std::string_view string, char seperator)
{
std::vector<std::string> result{};
std::string::size_type index;
while((index = string.find(seperator)) != std::string::npos)
{
result.emplace_back(string.substr(0, index));
string.remove_prefix(index + 1);
}
result.emplace_back(string);
return result;
}