瀏覽代碼

Update Helper.cpp

michael 1 年之前
父節點
當前提交
aa2a4edf7e
共有 1 個文件被更改,包括 98 次插入6 次删除
  1. 98 6
      code/components/jomjol_helper/Helper.cpp

+ 98 - 6
code/components/jomjol_helper/Helper.cpp

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