handling negative time input | bench 684523
This commit is contained in:
1 parent
960b32e6bd
commit
789503ceb2
1 file changed
+17
-6
+17
-6
@@ -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 = "";
|
||||||
|
|
||||||
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];
|
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