]> granicus.if.org Git - pdns/commitdiff
Implement sort properly with POSIX locale
authorAki Tuomi <cmouse@desteem.org>
Sun, 14 Jul 2013 15:28:15 +0000 (18:28 +0300)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Tue, 26 Nov 2013 11:26:31 +0000 (12:26 +0100)
pdns/arguments.cc
pdns/misc.hh

index b22a9ba7359c60ff13bbcb872b11e3571d412506..849118c10d832d72a21907b8d972cc8b20062ef7 100644 (file)
@@ -475,7 +475,7 @@ bool ArgvMap::file(const char *fname, bool lax, bool included)
          throw ArgException(params["include-dir"] + " is not accessible");
       }
       
-      std::list<std::string> extraConfigs;
+      std::vector<std::string> extraConfigs;
       while((ent = readdir(dir)) != NULL) {
          if (ent->d_name[0] == '.') continue; // skip any dots
          if (boost::ends_with(ent->d_name, ".conf")) {
@@ -488,7 +488,7 @@ bool ArgvMap::file(const char *fname, bool lax, bool included)
             extraConfigs.push_back(std::string(namebuf));
          }
       }
-      extraConfigs.sort();
+      std::sort(extraConfigs.begin(), extraConfigs.end(), CIStringComparePOSIX());
       BOOST_FOREACH(const std::string& fn, extraConfigs) {
             std::cout << "parsing " << fn << std::endl;
             if (!file(fn.c_str(), lax, true)) {
index 00a0e1caf3c50554fb2aa50e6ef0a741269e56ac..27af400c2d432b3b5603914d0a71d70f788eb096 100644 (file)
@@ -410,6 +410,22 @@ struct CIStringCompare: public std::binary_function<string, string, bool>
   }
 };
 
+struct CIStringComparePOSIX
+{
+   bool operator() (const std::string& lhs, const std::string& rhs)
+   {
+      std::string::const_iterator a,b;
+      const std::locale &loc = std::locale("POSIX");
+      a=lhs.begin();b=rhs.begin();
+      while(a!=lhs.end()) {
+          if (b==rhs.end() || std::tolower(*b,loc)<std::tolower(*a,loc)) return false;
+          else if (std::tolower(*a,loc)<std::tolower(*b,loc)) return true;
+          a++;b++;
+      }
+      return (b!=rhs.end());
+   }
+};
+
 struct CIStringPairCompare: public std::binary_function<pair<string, uint16_t>, pair<string,uint16_t>, bool>  
 {
   bool operator()(const pair<string, uint16_t>& a, const pair<string, uint16_t>& b) const