mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
LibChess: SetOptionCommand: Set provided option name and value
This commit is contained in:
parent
06ee8c5aa8
commit
0f084e0531
1 changed files with 30 additions and 6 deletions
|
@ -82,13 +82,37 @@ SetOptionCommand SetOptionCommand::from_string(const StringView& command)
|
||||||
auto tokens = command.split_view(' ');
|
auto tokens = command.split_view(' ');
|
||||||
ASSERT(tokens[0] == "setoption");
|
ASSERT(tokens[0] == "setoption");
|
||||||
ASSERT(tokens[1] == "name");
|
ASSERT(tokens[1] == "name");
|
||||||
if (tokens.size() == 3) {
|
ASSERT(tokens.size() > 2);
|
||||||
return SetOptionCommand(tokens[1]);
|
|
||||||
} else if (tokens.size() == 4) {
|
StringBuilder name;
|
||||||
ASSERT(tokens[2] == "value");
|
StringBuilder value;
|
||||||
return SetOptionCommand(tokens[1], tokens[3]);
|
bool in_name = false;
|
||||||
|
bool in_value = false;
|
||||||
|
for (auto& part : tokens) {
|
||||||
|
if (in_name) {
|
||||||
|
if (part == "value") {
|
||||||
|
in_name = false;
|
||||||
|
in_value = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
name.append(part);
|
||||||
|
name.append(' ');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (in_value) {
|
||||||
|
value.append(part);
|
||||||
|
value.append(' ');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (part == "name") {
|
||||||
|
in_name = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
|
ASSERT(!name.is_empty());
|
||||||
|
|
||||||
|
return SetOptionCommand(name.to_string().trim_whitespace(), value.to_string().trim_whitespace());
|
||||||
}
|
}
|
||||||
|
|
||||||
String SetOptionCommand::to_string() const
|
String SetOptionCommand::to_string() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue