X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fimage_filename_sorter.cc;h=47f46e81d75ecbe5aa589c4b1fd592241a5f150d;hp=c32b07115245145061bd4c87c206db9c565cb3a0;hb=386e25f3b9d3fa59cbdeed458d9b3e0d21e338b8;hpb=fd30397b1a1d0df6b43aedbb205913d2eec09fd0 diff --git a/src/lib/image_filename_sorter.cc b/src/lib/image_filename_sorter.cc index c32b07115..47f46e81d 100644 --- a/src/lib/image_filename_sorter.cc +++ b/src/lib/image_filename_sorter.cc @@ -33,16 +33,22 @@ using boost::optional; bool ImageFilenameSorter::operator() (boost::filesystem::path a, boost::filesystem::path b) { - optional na = extract_numbers (a); - optional nb = extract_numbers (b); - if (!na || !nb) { - return a.string() < b.string(); + string an = extract_numbers (a); + string bn = extract_numbers (b); + + int const anl = an.length (); + int const bnl = bn.length (); + + if (anl > bnl) { + bn = string(anl - bnl, '0') + bn; + } else if (bnl > anl) { + an = string(bnl - anl, '0') + an; } - return *na < *nb; + return an < bn; } -optional +string ImageFilenameSorter::extract_numbers (boost::filesystem::path p) { string numbers; @@ -52,13 +58,5 @@ ImageFilenameSorter::extract_numbers (boost::filesystem::path p) numbers += ps[i]; } } - - if (numbers.empty ()) { - return optional (); - } - - /* locale_convert is quicker than raw_convert and numbers can only contain - things which are isdigit() so locale_convert is fine to use. - */ - return locale_convert (numbers); + return numbers; }