-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.h
More file actions
221 lines (200 loc) · 6.35 KB
/
utils.h
File metadata and controls
221 lines (200 loc) · 6.35 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
vSID is a plugin for the Euroscope controller software on the Vatsim network.
The aim auf vSID is to ease the work of any controller that edits and assigns
SIDs to flightplans.
Copyright (C) 2024 Gameagle (Philip Maier)
Repo @ https://github.com/Gameagle/vSID
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "airport.h"
#include "include/es/EuroScopePlugIn.h"
#include <vector>
#include <string>
#include <algorithm>
#include <ranges>
namespace vsid
{
namespace utils
{
/**
* @brief trim spaces on the left side of a string
*
* @param string
* @return std::string
*/
std::string ltrim(const std::string& string);
/**
* @brief trim spaces on the right side of a string
*
* @param string
* @return std::string
*/
std::string rtrim(const std::string& string);
/**
* @brief trims spaces on both sides of a string
*
* @param string
* @return std::string
*/
std::string trim(const std::string& string);
/**
* @brief Splits a string based on a given delimiter
*
* @param string
* @param del - delimiter
* @return std::vector<std::string>
*/
std::vector<std::string> split(const std::string& string, const char& del, const bool keepWhitespace = false);
/**
* @brief Joins a vector of strings into one string
*
* @param toJoin - Vector to join
* @param del - delimiter
* @return std::string
*/
std::string join(const std::vector<std::string>& toJoin, const char del = ' ');
/**
* @brief Joins a set of strings into one string
*
* @param toJoin - Vector to join
* @param del - delimiter
* @return std::string
*/
std::string join(const std::set<std::string>& toJoin, const char del = ' ');
/**
* @brief Splits a string based on spaces - splits again for '/' delimiter. Used to vectorize the filed route - WILL BE DELETED
*
* @param string
* @return std::vector<std::string>
*/
std::vector<std::string> splitRoute(std::string& string);
/**
* @brief Fixed for airport icao checks - possible change to template
*
* @param airportVector - vector containing all active airports
* @param toSearch - string to search for, should be icao of an airport to check
* @return true - if the icao was found in active airports
* @return false - if the icao was NOT found in active airports
*/
bool isIcaoInVector(const std::vector<vsid::Airport>& airportVector, const std::string& toSearch);
/**
* @brief Checks if a number is contained in another number, e.g. if 2 is in 123
*
* @param number number to be checked for
* @param digit number to be checked in
* @return true
* @return false
*/
bool containsDigit(int number, int digit);
/**
* @brief Get a minimum climb for an airport (rounded to the next thousand ft above field + 500 ft)
*
* @param elevation
* @return int
*/
int getMinClimb(int elevation);
/**
* @brief Transforms the input string to lowercase
*
* @param input - the string to transform
* @return lowercase input
*/
std::string tolower(std::string input);
/**
* @brief Transforms the input to uppercase
*
* @param input - the input to transform
* @return uppercase input
*/
std::string toupper(std::string input);
//************************************
// Method: contains
// FullName: vsid::utils::contains
// Access: public
// Return: bool
// Qualifier:
// Parameter: const R & range - object container, e.g. std::vector
// Parameter: const T & value - value to search for
//************************************
template<std::ranges::range R, typename T>
bool contains(const R& range, const T& value)
{
return std::ranges::find(range, value) != std::ranges::end(range);
}
//************************************
// Description: Checks if the last character of a string is a digit
// Method: lastIsDigit
// FullName: vsid::utils::lastIsDigit
// Access: public
// Returns: bool
// Qualifier:
// Parameter: std::string_view s
//************************************
inline bool lastIsDigit(std::string_view s)
{
return std::isdigit(s.back());
}
//************************************
// Description: Checks if a string contains a digit
// Method: containsDigit
// FullName: vsid::utils::containsDigit
// Access: public
// Returns: bool
// Qualifier:
// Parameter: std::string_view s
//************************************
inline bool containsDigit(std::string_view s)
{
for (unsigned char c : s)
if (std::isdigit(c)) return true;
return false;
}
//************************************
// Description: Counts digits present in a string
// Method: countDigits
// FullName: vsid::utils::countDigits
// Access: public
// Returns: int
// Qualifier:
// Parameter: const std::string_view s
//************************************
inline int countDigits(const std::string_view s)
{
int counter = 0;
for (unsigned char c : s)
if (std::isdigit(c)) counter++;
return counter;
}
//************************************
// Description: Creates a decimal position pair
// Method: toPoint
// FullName: vsid::utils::toPoint
// Access: public
// Returns: EuroScopePlugIn::CPosition
// Qualifier:
// Parameter: const std::pair<std::string
// Parameter: std::string> & pos
//************************************
EuroScopePlugIn::CPosition toPoint(const std::pair<std::string, std::string>& pos);
//************************************
// Description: Transforms lat/long string value into decimal equivalent
// Method: toDeg
// FullName: vsid::utils::toDeg
// Access: public
// Returns: double
// Qualifier:
// Parameter: const std::string & coord
//************************************
double toDeg(const std::string& coord);
}
}