- ///
- /// Implementation of the UCIInputParser class.
- ///
-
- // Constructor for the UCIInputParser class. The constructor takes a
- // text string containing a single UCI command as input.
-
- UCIInputParser::UCIInputParser(const std::string &line) : inputLine(line) {
- this->currentIndex = 0;
- this->length = line.length();
- }
-
-
- // UCIInputParser::skip_whitspace() skips any number of whitespace
- // characters from the current location in an input string.
-
- void UCIInputParser::skip_whitespace() {
- while(isspace(std::char_traits<char>::to_int_type(this->inputLine[this->currentIndex])))
- this->currentIndex++;
- }
-
-
- // UCIInputParser::get_next_token() gets the next token in an UCI
- // command. A 'token' in an UCI command is simply any
- // whitespace-delimited sequence of characters.
-
- std::string UCIInputParser::get_next_token() {
- int i, j;
-
- this->skip_whitespace();
- for(i = j = this->currentIndex;
- j < this->length && !isspace(this->inputLine[j]);
- j++);
- this->currentIndex = j;
- this->skip_whitespace();
-
- std::string str = this->inputLine.substr(i, j - i);
-
- return str;
- }
-
-
- // UCIInputParser::get_rest_of_line() returns the rest of the input
- // line (from the current location) as a single string.
-
- std::string UCIInputParser::get_rest_of_line() {
- this->skip_whitespace();
- return this->inputLine.substr(this->currentIndex, this->length);
- }
-
-
- // UCIInputParser::at_end_of_line() tests whether we have reached the
- // end of the input string, i.e. if any more input remains to be
- // parsed.
-
- bool UCIInputParser::at_end_of_line() {
- return this->currentIndex == this->length;
- }
-
-
- ///
- /// Other functions
- ///
-
-
- // wait_for_command() waits for a command from the user, and passes
- // this command to handle_command. wait_for_command also intercepts