Time fix #36
+16
-5
@@ -40,18 +40,29 @@ static void ParsePosition(Board &board, std::string_view command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int ReadParam(std::string param, std::string &command) {
|
static int ReadParam(std::string param, std::string &command) {
|
||||||
size_t pos = -1;
|
size_t pos = command.find(param);
|
||||||
pos = command.find(param);
|
|
||||||
|
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
std::string result = "";
|
|
||||||
pos += param.length() + 1;
|
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])) {
|
while (pos < command.length() && std::isdigit(command[pos])) {
|
||||||
result += command[pos];
|
result += command[pos];
|
||||||
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;
|
return 0;
|
||||||
|
|||||||
Reference in new issue
Block a user