handling negative time input | bench 684523

This commit is contained in:
rektdie committed 2025-03-27 20:27:50 +01:00
1 parent 960b32e6bd
commit 789503ceb2
1 file changed
+17 -6
+17 -6
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 = "";
while(pos < command.length() && std::isdigit(command[pos])){
// 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;