diff --git a/src/engine.cc b/src/engine.cc index 31f8301887..423206640e 100644 --- a/src/engine.cc +++ b/src/engine.cc @@ -357,7 +357,8 @@ void EngineLoop::CmdIsReady() { SendResponse("readyok"); } -void EngineLoop::CmdSetOption(const std::string& name, const std::string& value, +void EngineLoop::CmdSetOption(const std::string& name, + const std::string& value, const std::string& context) { options_.SetUciOption(name, value, context); // Set the log filename for the case it was set in UCI option. diff --git a/src/utils/optionsparser.cc b/src/utils/optionsparser.cc index 64fb0c2d4d..bc099c7234 100644 --- a/src/utils/optionsparser.cc +++ b/src/utils/optionsparser.cc @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include "utils/commandline.h" #include "utils/configfile.h" @@ -64,17 +66,34 @@ std::vector OptionsParser::ListOptionsUci() const { return result; } +std::vector SplitString(const std::string& str, char delimiter) { + std::vector tokens; + std::string token; + std::istringstream tokenStream(str); + while (std::getline(tokenStream, token, delimiter)) { + tokens.push_back(token); + } + return tokens; +} + void OptionsParser::SetUciOption(const std::string& name, const std::string& value, const std::string& context) { - auto option = FindOptionByUciName(name); - if (option) { - option->SetValue(value, GetMutableOptions(context)); - return; - } - throw Exception("Unknown option: " + name); + if (name.empty()) { + throw Exception("An option name must be provided"); + } else { + auto option = FindOptionByUciName(name); + if (option) { + option->SetValue(value, GetMutableOptions(context)); + } else { + // If name is not valid throw an error. + throw Exception("Unknown option: " + name); + } + return; + } } + void OptionsParser::HideOption(const OptionId& id) { const auto option = FindOptionById(id); if (option) option->hidden_ = true;