mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-06 11:36:51 +03:00
Update Helper.cpp
This commit is contained in:
@@ -1211,8 +1211,100 @@ bool isInString(std::string &s, std::string const &toFind)
|
||||
void replaceAll(std::string& s, const std::string& toReplace, const std::string& replaceWith)
|
||||
{
|
||||
size_t pos = 0;
|
||||
while ((pos = s.find(toReplace, pos)) != std::string::npos) {
|
||||
|
||||
while ((pos = s.find(toReplace, pos)) != std::string::npos)
|
||||
{
|
||||
s.replace(pos, toReplace.length(), replaceWith);
|
||||
pos += replaceWith.length();
|
||||
}
|
||||
}
|
||||
|
||||
bool isStringNumeric(std::string &input)
|
||||
{
|
||||
int start = 0;
|
||||
int punkt_existiert_schon = 0;
|
||||
|
||||
if (input[0] == '-')
|
||||
{
|
||||
start = 1;
|
||||
}
|
||||
|
||||
for (int i = start; i < input.size(); i++)
|
||||
{
|
||||
// if ((ispunct(input[i])) && (i > 0) && (punkt_existiert_schon == 0))
|
||||
if (((input[i] == '.') || (input[i] == ',')) && (i > 0) && (punkt_existiert_schon == 0))
|
||||
{
|
||||
punkt_existiert_schon = 1;
|
||||
i++;
|
||||
}
|
||||
else if (!isdigit(input[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isStringAlphabetic(std::string &input)
|
||||
{
|
||||
for (int i = 0; i < input.size(); i++)
|
||||
{
|
||||
if (!isalpha(input[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isStringAlphanumeric(std::string &input)
|
||||
{
|
||||
for (int i = 0; i < input.size(); i++)
|
||||
{
|
||||
if (!isalnum(input[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool alphanumericToBoolean(std::string &input)
|
||||
{
|
||||
if (isStringAlphabetic(input))
|
||||
{
|
||||
return stringToBoolean(toUpper(input));
|
||||
}
|
||||
else if (isStringNumeric(input))
|
||||
{
|
||||
return numericStrToBool(input);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int clipInt(int input, int high, int low)
|
||||
{
|
||||
if (input < low)
|
||||
{
|
||||
input = low;
|
||||
}
|
||||
else if (input > high)
|
||||
{
|
||||
input = high;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
bool numericStrToBool(std::string input)
|
||||
{
|
||||
return (std::stoi(input) != 0);
|
||||
}
|
||||
|
||||
bool stringToBoolean(std::string input)
|
||||
{
|
||||
return (input == "TRUE");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user