فهرست منبع

sort underscores first

David Rose 22 سال پیش
والد
کامیت
82295ee76d
2فایلهای تغییر یافته به همراه35 افزوده شده و 0 حذف شده
  1. 34 0
      pandaapp/src/indexify/rollDirectory.cxx
  2. 1 0
      pandaapp/src/indexify/rollDirectory.h

+ 34 - 0
pandaapp/src/indexify/rollDirectory.cxx

@@ -211,6 +211,12 @@ scan(const string &extension) {
       return false;
     }
 
+    // We want to sort the filenames in our own way, so that
+    // underscore is deemed to fall before anything else.  This allows
+    // the underscore, the only non-alphnumeric character we can have
+    // in a filename for an iso9660 image, to stand for "before 0".
+    sort(contents.begin(), contents.end(), compare_filenames);
+
     if (reverse_order) {
       reverse(contents.begin(), contents.end());
     }
@@ -776,3 +782,31 @@ generate_nav_buttons(ostream &html, const Filename &prev_roll_filename,
   }
   html << "</p>\n";
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: RollDirectory::compare_filenames
+//       Access: Private, Static
+//  Description: Returns true if filename a sorts before filename b,
+//               false otherwise.
+////////////////////////////////////////////////////////////////////
+bool RollDirectory::
+compare_filenames(const string &a, const string &b) {
+  size_t i = 0;
+  size_t min_length = min(a.length(), b.length());
+  while (i < min_length) {
+    char achar = a[i];
+    char bchar = b[i];
+    if (achar != bchar) {
+      if (achar == '_') {
+        return true;
+      } else if (bchar == '_') {
+        return false;
+      } else {
+        return achar < bchar;
+      }
+    }
+    ++i;
+  }
+
+  return a.length() < b.length();
+}

+ 1 - 0
pandaapp/src/indexify/rollDirectory.h

@@ -75,6 +75,7 @@ private:
 			    const Filename &prev_roll_filename,
 			    const Filename &next_roll_filename, 
 			    const string &up_href);
+  static bool compare_filenames(const string &a, const string &b);
 
 public:
   RollDirectory *_prev;