-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cpp
More file actions
99 lines (88 loc) · 1.79 KB
/
Copy pathcommon.cpp
File metadata and controls
99 lines (88 loc) · 1.79 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "common.h"
std::string GetDirectionName(Direction direction)
{
switch (direction)
{
case Direction::North:
return "north";
case Direction::East:
return "east";
case Direction::South:
return "south";
case Direction::West:
return "west";
default:
return "unknown";
}
}
Direction GetDirectionFromName(const std::string& name)
{
if (name == "north")
{
return Direction::North;
}
else if (name == "east")
{
return Direction::East;
}
else if (name == "south")
{
return Direction::South;
}
else if (name == "west")
{
return Direction::West;
}
return Direction::Unknown;
}
Direction GetOppositeDirection(Direction direction)
{
switch (direction)
{
case Direction::North:
return Direction::South;
case Direction::East:
return Direction::West;
case Direction::South:
return Direction::North;
case Direction::West:
return Direction::East;
default:
return Direction::Unknown;
}
}
void Tokenize(const std::string& input, std::vector<std::string>& output)
{
output.clear();
size_t prev = 0;
size_t next = 0;
next = input.find_first_of(' ', prev);
while (next != std::string::npos)
{
output.push_back(input.substr(prev, next - prev));
prev = next + 1;
next = input.find_first_of(' ', prev);
}
output.push_back(input.substr(prev, next - prev));
}
std::string JoinTokens(const std::vector<std::string>& tokens, int start, int end)
{
std::string name = "";
for (int i = start; i < end; ++i)
{
name += tokens[i];
if (i < end - 1)
{
name += " ";
}
}
return name;
}
bool CaseInsensitiveCompare(const std::string& string1, const std::string& string2)
{
std::string s1 = string1;
std::string s2 = string2;
std::transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
std::transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
return s1 == s2;
}