Skip to content

Commit

Permalink
Update Helper.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SybexX authored Jul 17, 2024
1 parent 8012b7f commit aa2a4ed
Showing 1 changed file with 98 additions and 6 deletions.
104 changes: 98 additions & 6 deletions code/components/jomjol_helper/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ bool isInString(std::string &s, std::string const &toFind)
{
std::size_t pos = s.find(toFind);

if (pos == std::string::npos)
if (pos == std::string::npos)
{
// Not found
return false;
Expand All @@ -1210,9 +1210,101 @@ bool isInString(std::string &s, std::string const &toFind)
// from https://stackoverflow.com/a/14678800
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) {
s.replace(pos, toReplace.length(), replaceWith);
pos += replaceWith.length();
}
size_t pos = 0;

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");
}

0 comments on commit aa2a4ed

Please sign in to comment.