]> git.sesse.net Git - stockfish/commitdiff
Fix get_option_value() for strings with spaces
authorMarco Costalba <mcostalba@gmail.com>
Sat, 28 Nov 2009 16:31:56 +0000 (17:31 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 28 Nov 2009 16:31:56 +0000 (17:31 +0100)
Problem is that

istream& operator>> (istream& is, char* str );

according to C++ documentation "Ends extraction when the
next character is either a valid whitespace or a null character,
or if the End-Of-File is reached."

So if the parameter value is a string with spaces the currently
used instruction 'ss >> ret;' copies the chars only up to the first
white space and not the whole string.

Use a specialization of get_option_value() to fix this corner case.

Bug reported by xiaozhi

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/ucioption.cpp

index 1b8665546a20297d1047c564db736cec0f7800ea..d1326a4c9be0b8c76f1bd86f79c5faf3d720abc3 100644 (file)
@@ -169,6 +169,18 @@ namespace {
       return ret;
   }
 
+  // Specialization for std::string where instruction 'ss >> ret;'
+  // would erroneusly tokenize a string with spaces.
+
+  template<>
+  string get_option_value<string>(const string& optionName) {
+
+      if (options.find(optionName) == options.end())
+          return string();
+
+      return options[optionName].currentValue;
+  }
+
 }
 
 ////