]> git.sesse.net Git - stockfish/commitdiff
UCI options names should not be case sensitive
authorMarco Costalba <mcostalba@gmail.com>
Sun, 21 Nov 2010 22:28:17 +0000 (23:28 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 21 Nov 2010 22:52:51 +0000 (23:52 +0100)
Correctly handle uci option names in a case insensitive way.

Alos fix some indentation while there.

No functional change.

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

index 9b9c20da0019e5b507468cca7f9aa22b3c432954..4194f839a3b77f7bc90c3aa2ff94d1910de7f9c4 100644 (file)
@@ -17,6 +17,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <cctype>
 #include <iostream>
 #include <sstream>
 
@@ -28,7 +29,25 @@ using std::string;
 using std::cout;
 using std::endl;
 
-OptionsMap Options;
+OptionsMap Options; // Global object
+
+
+// Our case insensitive less() function as required by UCI protocol
+bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
+
+  int c1, c2;
+  size_t i = 0;
+
+  while (i < s1.size() && i < s2.size())
+  {
+      c1 = tolower(s1[i]);
+      c2 = tolower(s2[i++]);
+
+      if (c1 != c2)
+          return c1 < c2;
+  }
+  return s1.size() < s2.size();
+}
 
 
 // stringify() converts a numeric value of type T to a std::string
index de75d1213e133362417fff8260c8bf38f90853cb..6c9812189744a5bd93cf0fbc9915360019917433 100644 (file)
@@ -47,25 +47,31 @@ private:
 template<typename T>
 inline T Option::value() const {
 
-    assert(type == "spin");
-    return T(atoi(currentValue.c_str()));
+  assert(type == "spin");
+  return T(atoi(currentValue.c_str()));
 }
 
 template<>
 inline std::string Option::value<std::string>() const {
 
-    assert(type == "string");
-    return currentValue;
+  assert(type == "string");
+  return currentValue;
 }
 
 template<>
 inline bool Option::value<bool>() const {
 
-    assert(type == "check" || type == "button");
-    return currentValue == "true";
+  assert(type == "check" || type == "button");
+  return currentValue == "true";
 }
 
-typedef std::map<std::string, Option> OptionsMap;
+
+// Custom comparator because UCI options should not be case sensitive
+struct CaseInsensitiveLess {
+  bool operator() (const std::string&, const std::string&) const;
+};
+
+typedef std::map<std::string, Option, CaseInsensitiveLess> OptionsMap;
 
 extern OptionsMap Options;
 extern void init_uci_options();