Include tidying src/lib/a-j*.h
[dcpomatic.git] / src / lib / image_filename_sorter.cc
index 0cb6adc6bf182705490e44eed16c80b70ccd0741..69114b2bd46a569a2844b975baa4feed489fc99d 100644 (file)
 
 */
 
-#include "raw_convert.h"
+#include <iostream>
 #include <boost/filesystem.hpp>
 #include <boost/optional.hpp>
-#include <iostream>
+#include "raw_convert.h"
 
 class ImageFilenameSorter
 {
@@ -41,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 raw_convert<int> (number);
+               return raw_convert<int> (longest);
        }
 };