Time fix #36

Merged
rektdie merged 4 commits from time_fix into main 2025-03-27 22:32:47 +01:00
Showing only changes of commit 789503ceb2 - Show all commits
+16 -5
View File
@@ -40,18 +40,29 @@ static void ParsePosition(Board &board, std::string_view command) {
}
static int ReadParam(std::string param, std::string &command) {
size_t pos = -1;
pos = command.find(param);
size_t pos = command.find(param);
if (pos != std::string::npos) {
std::string result = "";
pos += param.length() + 1;
bool isNegative = false;
std::string result = "";
// Check for negative sign
if (pos < command.length() && command[pos] == '-') {
isNegative = true;
pos++;
}
// Extract digits
while (pos < command.length() && std::isdigit(command[pos])) {
result += command[pos];
pos++;
}
return stoi(result);
// Ensure result is not empty before calling stoi
if (!result.empty()) {
int value = std::stoi(result);
return isNegative ? -value : value;
}
}
return 0;