2019-09-03 11:58:42 +02:00
|
|
|
/*
|
|
|
|
Some helper string functions
|
|
|
|
JrCs 2014
|
|
|
|
*/
|
|
|
|
|
2020-08-17 21:40:52 +02:00
|
|
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-08-12 17:15:47 +02:00
|
|
|
XString8 NonDetected = "10.10.10"_XS8; //longer string
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Convert a Null-terminated ASCII string representing version number (separate by dots)
|
|
|
|
to a UINT64 value.
|
|
|
|
|
|
|
|
If Version is NULL, then result is 0. (Slice - no)
|
|
|
|
|
|
|
|
@param Version The pointer to a Null-terminated ASCII version string. Like 10.9.4
|
|
|
|
@param MaxDigitByPart Is the maximum number of digits between the dot separators
|
|
|
|
@param MaxParts Is the maximum number of parts (blocks between dot separators)
|
|
|
|
the version is composed. For a string like 143.5.77.26 the
|
|
|
|
MaxParts is 4
|
|
|
|
|
|
|
|
@return Result
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
2020-08-12 17:15:47 +02:00
|
|
|
UINT64 AsciiStrVersionToUint64(const XString8& Version_, UINT8 MaxDigitByPart, UINT8 MaxParts)
|
2020-05-18 21:40:47 +02:00
|
|
|
{
|
2019-09-03 11:58:42 +02:00
|
|
|
UINT64 result = 0;
|
|
|
|
UINT16 part_value = 0;
|
|
|
|
UINT16 part_mult = 1;
|
|
|
|
UINT16 max_part_value;
|
|
|
|
|
2020-08-12 17:15:47 +02:00
|
|
|
const XString8* VersionPtr = &Version_;
|
|
|
|
if (VersionPtr->isEmpty()) {
|
|
|
|
VersionPtr = &NonDetected; //pointer to non-NULL string
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-08-12 17:15:47 +02:00
|
|
|
const XString8& Version = *VersionPtr;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
while (MaxDigitByPart--) {
|
|
|
|
part_mult = part_mult * 10;
|
|
|
|
}
|
|
|
|
max_part_value = part_mult - 1;
|
2020-08-12 17:15:47 +02:00
|
|
|
size_t idx = 0;
|
|
|
|
while (idx < Version.length() && MaxParts > 0) { //Slice - NULL pointer dereferencing
|
|
|
|
if (Version[idx] >= '0' && Version[idx] <= '9') {
|
2020-11-02 14:45:11 +01:00
|
|
|
part_value = part_value * 10 + (UINT16)(Version[idx] - '0');
|
2019-09-03 11:58:42 +02:00
|
|
|
if (part_value > max_part_value)
|
|
|
|
part_value = max_part_value;
|
|
|
|
}
|
2020-08-12 17:15:47 +02:00
|
|
|
else if (Version[idx] == '.') {
|
2021-10-19 19:57:27 +02:00
|
|
|
result = (result * part_mult) + part_value;
|
2019-09-03 11:58:42 +02:00
|
|
|
part_value = 0;
|
|
|
|
MaxParts--;
|
|
|
|
}
|
2020-08-12 17:15:47 +02:00
|
|
|
idx++;
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
while (MaxParts--) {
|
2021-10-19 19:57:27 +02:00
|
|
|
result = (result * part_mult) + part_value;
|
2019-09-03 11:58:42 +02:00
|
|
|
part_value = 0; // part_value is only used at first pass
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|