6 #ifndef SWIFT_MISC_SIMULATION_XPLANE_XPLANQTFREEUTILS_H
7 #define SWIFT_MISC_SIMULATION_XPLANE_XPLANQTFREEUTILS_H
20 namespace swift::misc::simulation::xplane::qtfreeutils
25 const std::string seperator =
"/\\";
26 const std::size_t sepPos = filePath.find_last_of(seperator);
27 if (sepPos != std::string::npos) {
return filePath.substr(sepPos + 1, filePath.size() - 1); }
28 else {
return filePath; }
32 inline std::string
getDirName(
const std::string &filePath)
34 const std::string seperator =
"/\\";
35 const std::size_t sepPos = filePath.find_last_of(seperator);
36 if (sepPos != std::string::npos)
38 std::string dirPath = filePath.substr(0, sepPos);
47 const std::string seperator =
".";
49 std::size_t sepPos = fileName.find(seperator);
50 if (sepPos != std::string::npos) {
return fileName.substr(0, sepPos); }
51 else {
return fileName; }
55 inline std::vector<std::string>
split(
const std::string &str,
size_t maxSplitCount = 0,
56 const std::string &delimiter =
" ")
60 std::vector<std::string> tokens;
61 while ((pos = s.find(delimiter)) != std::string::npos)
63 tokens.push_back(s.substr(0, pos));
64 s.erase(0, pos + delimiter.length());
65 if (maxSplitCount > 0 && tokens.size() == maxSplitCount) {
break; }
75 if (value >= start && value <=
end) {
return value; }
76 const double width =
end - start;
77 const double offsetValue = value - start;
78 return (offsetValue - (floor(offsetValue / width) * width)) + start;
94 if (!acfProperties.
author.empty())
98 if (acfProperties.
modelName.find(acfProperties.
author) != std::string::npos)
115 std::transform(s.begin(), s.end(), s.begin(), [](
unsigned char c) { return std::tolower(c); });
122 if (str1.size() != str2.size()) {
return false; }
123 return std::equal(str1.begin(), str1.end(), str2.begin(), [](
const char &c1,
const char &c2) {
124 return (c1 == c2 || std::toupper(c1) == std::toupper(c2));
131 static const std::string y(
"yes");
132 static const std::string n(
"no");
139 static const std::string tr(
"true");
140 static const std::string fa(
"false");
149 static const double Epsilon = 1E-08;
150 return (fabs(v1 - v2) < Epsilon);
161 if (!result.empty() && result.back() !=
' ') { result.push_back(
' '); }
163 else { result.push_back(c); }
165 while (!result.empty() && result.back() ==
' ') { result.pop_back(); }
172 std::ifstream fs(filePath, std::ios::in);
173 if (!fs.is_open()) {
return {}; }
180 std::getline(fs, version);
182 std::getline(fs, acf);
187 if (i ==
"i" && version.find(
"version") != std::string::npos && acf ==
"acf")
190 while (std::getline(fs, line))
192 auto tokens =
split(line, 2);
193 if (tokens.size() < 3 || tokens.at(0) !=
"P") {
continue; }
195 if (tokens.at(1) ==
"acf/_ICAO") { acfProperties.
aircraftIcaoCode = tokens.at(2); }
196 else if (tokens.at(1) ==
"acf/_descrip") { acfProperties.
modelDescription =
"[ACF] " + tokens.at(2); }
197 else if (tokens.at(1) ==
"acf/_name") { acfProperties.
modelName = tokens.at(2); }
198 else if (tokens.at(1) ==
"acf/_studio") { acfProperties.
author = tokens.at(2); }
199 else if (tokens.at(1) ==
"acf/_author")
201 if (!acfProperties.
author.empty()) {
continue; }
202 std::string author = tokens.at(2);
204 author.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_");
205 author = author.substr(0, pos);
206 if (author.empty()) {
continue; }
207 acfProperties.
author = author;
214 return acfProperties;
218 template <
typename I>
223 using value_type =
typename std::iterator_traits<I>::value_type;
225 using reference =
typename std::iterator_traits<I>::reference;
226 using pointer =
typename std::iterator_traits<I>::pointer;
255 constexpr
auto isContinuation = [](
auto c) {
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
bool stringCompareCaseInsensitive(const std::string &str1, const std::string &str2)
Compare case insensitive.
std::string stringForFlyableModel(const AcfProperties &acfProperties, const std::string &acfFile)
Get the model string for a flyable aircraft.
bool isFuzzyEqual(double v1, double v2)
Qt free version of fuzzy compare.
std::string getBaseName(const std::string &filePath)
Get the base name of the file.
AcfProperties extractAcfProperties(const std::string &filePath)
Extract ACF properties from an aircraft file.
const std::string & boolTotrueFalse(bool t)
True/false from bool.
std::string simplifyWhitespace(const std::string &s)
Trim whitespace from the beginning and end, and replace sequences of whitespace with single space cha...
std::string getFileName(const std::string &filePath)
Get filename (including all extensions) from a filePath.
std::string toLower(std::string s)
String to lower case.
double normalizeValue(const double value, const double start, const double end)
Normalize value to range start -> end (like for +-180degrees)
std::string getDirName(const std::string &filePath)
Get the name of the parent directory.
std::vector< std::string > split(const std::string &str, size_t maxSplitCount=0, const std::string &delimiter=" ")
Split string by delimiter and maxSplitCount times.
std::string author
Model author.
std::string modelDescription
Model description.
std::string aircraftIcaoCode
Aircraft ICAO code.
std::string modelString
Generated model string.
std::string modelName
Model name.
Encoding-aware iterator adaptor for std::u8string.
Utf8Iterator & operator++()
Pre-increment.
typename std::iterator_traits< I >::pointer pointer
STL compatibility.
Utf8Iterator()=default
Default constructor.
typename std::iterator_traits< I >::difference_type difference_type
STL compatibility.
friend bool operator==(Utf8Iterator a, I b)
Equality.
friend bool operator==(Utf8Iterator a, Utf8Iterator b)
Equality.
friend bool operator!=(Utf8Iterator a, I b)
Equality.
friend bool operator!=(I a, Utf8Iterator b)
Equality.
friend bool operator!=(Utf8Iterator a, Utf8Iterator b)
Equality.
Utf8Iterator(I base, I end)
Constructor.
std::forward_iterator_tag iterator_category
STL compatibility.
Utf8Iterator operator++(int)
Post-increment.
I base
Underlying iterator.
typename std::iterator_traits< I >::reference reference
STL compatibility.
reference operator*() const
Dereference (not encoding-aware)
pointer operator->() const
Pointer indirection (not encoding-aware)
typename std::iterator_traits< I >::value_type value_type
STL compatibility.
I end
Underlying end iterator.
friend bool operator==(I a, Utf8Iterator b)
Equality.