forked from maxortner01/ck2-Save-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
64 lines (49 loc) · 1.21 KB
/
parser.cpp
File metadata and controls
64 lines (49 loc) · 1.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
#include "parser.h"
namespace ck2
{
// Returns Pair of strings given a string of a property
StringPair Parser::getProperty(std::string line, char del) const
{
StringPair r;
for (int i = 0; i < line.length(); i++)
{
if (line[i] != del) continue;
r.first = std::string(line.begin(), line.begin() + i);
r.second = std::string(line.begin() + i + 1, line.end());
break;
}
return r;
}
// Determines whether or not a given character is in a given string
bool Parser::contains(std::string line, char c) const
{
for (int i = 0; i < line.length(); i++)
if (line[i] == c)
return true;
return false;
}
// Replaces all occurences of one character with another
std::string Parser::replace(std::string line, char c, char rep) const
{
std::string r;
for (int i = 0; i < line.length(); i++)
{
if (line[i] != c)
r += line[i];
else
r += rep;
}
return r;
}
// Removes all occurrences of a character
std::string Parser::remove(std::string line, char c) const
{
std::string r;
for (int i = 0; i < line.length(); i++)
{
if (line[i] != c)
r += line[i];
}
return r;
}
}