]> git.sesse.net Git - stockfish/commitdiff
Use std::lexicographical_compare() in UCI options
authorMarco Costalba <mcostalba@gmail.com>
Wed, 3 Aug 2011 13:24:55 +0000 (14:24 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 3 Aug 2011 14:00:23 +0000 (15:00 +0100)
Instead of our home grown function to perform a case
insensitive compare on option names as required by UCI
protocol.

No functional change.

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

index 1dfc474a9c0a3098ce82e0aa181dfb1bfa89195a..9e718c02c89ca8a5670b555ed05ccca93fb9026a 100644 (file)
@@ -17,6 +17,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <algorithm>
 #include <cctype>
 #include <iostream>
 #include <sstream>
@@ -33,20 +34,10 @@ 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++]);
+static bool ci_less(char c1, char c2) { return tolower(c1) < tolower(c2); }
 
-      if (c1 != c2)
-          return c1 < c2;
-  }
-  return s1.size() < s2.size();
+bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
+  return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
 }
 
 
index b6ad959cc353a9e5a3579d2973410fc2d88d2b10..c764ac8bb088636cb8b9aec08aa2e39a2d35773a 100644 (file)
@@ -36,7 +36,7 @@ public:
   template<typename T> T value() const;
 
 private:
-  friend class OptionsMap;
+  friend struct OptionsMap;
 
   std::string defaultValue, currentValue, type;
   int minValue, maxValue;
@@ -44,15 +44,14 @@ private:
 };
 
 
-/// Custom comparator because UCI options should not be case sensitive
+/// Custom comparator because UCI options should be case insensitive
 struct CaseInsensitiveLess {
   bool operator() (const std::string&, const std::string&) const;
 };
 
 
 /// Our options container is actually a map with a customized c'tor
-class OptionsMap : public std::map<std::string, UCIOption, CaseInsensitiveLess> {
-public:
+struct OptionsMap : std::map<std::string, UCIOption, CaseInsensitiveLess> {
   OptionsMap();
   std::string print_all() const;
 };