From: Marco Costalba Date: Sun, 21 Nov 2010 22:28:17 +0000 (+0100) Subject: UCI options names should not be case sensitive X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=85df24624a78acb9da89242be4024eb00dd16dab UCI options names should not be case sensitive Correctly handle uci option names in a case insensitive way. Alos fix some indentation while there. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 9b9c20da..4194f839 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -17,6 +17,7 @@ along with this program. If not, see . */ +#include #include #include @@ -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 diff --git a/src/ucioption.h b/src/ucioption.h index de75d121..6c981218 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -47,25 +47,31 @@ private: template 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() const { - assert(type == "string"); - return currentValue; + assert(type == "string"); + return currentValue; } template<> inline bool Option::value() const { - assert(type == "check" || type == "button"); - return currentValue == "true"; + assert(type == "check" || type == "button"); + return currentValue == "true"; } -typedef std::map 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 OptionsMap; extern OptionsMap Options; extern void init_uci_options();