Fix duplicate name of _mutex in ExceptionStore and some of its children.
[dcpomatic.git] / src / lib / image_filename_sorter.cc
index 7bb1b4c376bb24762a860b3990fb4b5acebc1087..69114b2bd46a569a2844b975baa4feed489fc99d 100644 (file)
@@ -20,7 +20,7 @@
 #include <iostream>
 #include <boost/filesystem.hpp>
 #include <boost/optional.hpp>
-#include <dcp/raw_convert.h>
+#include "raw_convert.h"
 
 class ImageFilenameSorter
 {
@@ -30,7 +30,6 @@ public:
                boost::optional<int> na = extract_number (a);
                boost::optional<int> nb = extract_number (b);
                if (!na || !nb) {
-                       std::cout << a << " " << b << " " << (a.string() < b.string()) << "\n";
                        return a.string() < b.string();
                }
 
@@ -42,21 +41,35 @@ private:
        {
                p = p.leaf ();
                
-               std::string number;
+               std::list<std::string> numbers;
+
+               std::string current;
                for (size_t i = 0; i < p.string().size(); ++i) {
                        if (isdigit (p.string()[i])) {
-                               number += p.string()[i];
+                               current += p.string()[i];
                        } else {
-                               if (!number.empty ()) {
-                                       break;
+                               if (!current.empty ()) {
+                                       numbers.push_back (current);
+                                       current.clear ();
                                }
                        }
                }
 
-               if (number.empty ()) {
+               if (!current.empty ()) {
+                       numbers.push_back (current);
+               }
+
+               std::string longest;
+               for (std::list<std::string>::const_iterator i = numbers.begin(); i != numbers.end(); ++i) {
+                       if (i->length() > longest.length()) {
+                               longest = *i;
+                       }
+               }
+
+               if (longest.empty ()) {
                        return boost::optional<int> ();
                }
 
-               return dcp::raw_convert<int> (number);
+               return raw_convert<int> (longest);
        }
 };