+2015-07-17 Carl Hetherington <cth@carlh.net>
+
+ * Improve still-image filename sorting.
+
2015-07-16 Carl Hetherington <cth@carlh.net>
* Updated ru_RU translation from Igor Voytovich.
public:
bool operator() (boost::filesystem::path a, boost::filesystem::path b)
{
- boost::optional<int> na = extract_number (a);
- boost::optional<int> nb = extract_number (b);
- if (!na || !nb) {
- return a.string() < b.string();
+ std::vector<int> na = extract_numbers (a);
+ std::vector<int> nb = extract_numbers (b);
+
+ std::vector<int>::const_iterator i = na.begin ();
+ std::vector<int>::const_iterator j = nb.begin ();
+
+ while (true) {
+ if (i == na.end () || j == nb.end ()) {
+ return false;
+ }
+
+ if (*i != *j) {
+ return *i < *j;
+ }
+
+ ++i;
+ ++j;
}
- return na.get() < nb.get();
+ /* NOT REACHED */
+ return false;
}
private:
- boost::optional<int> extract_number (boost::filesystem::path p)
+ std::vector<int> extract_numbers (boost::filesystem::path p)
{
p = p.leaf ();
+ std::vector<int> numbers;
std::string number;
for (size_t i = 0; i < p.string().size(); ++i) {
if (isdigit (p.string()[i])) {
number += p.string()[i];
- } else {
- if (!number.empty ()) {
- break;
- }
+ } else if (!number.empty ()) {
+ numbers.push_back (raw_convert<int> (number));
+ number.clear ();
}
}
- if (number.empty ()) {
- return boost::optional<int> ();
+ if (!number.empty ()) {
+ numbers.push_back (raw_convert<int> (number));
}
- return raw_convert<int> (number);
+ return numbers;
}
};
BOOST_CHECK (x ("1", "999"));
BOOST_CHECK (x ("00057.tif", "00166.tif"));
BOOST_CHECK (x ("/my/numeric999/path/00057.tif", "/my/numeric999/path/00166.tif"));
+ BOOST_CHECK (x ("1_01.tif", "1_02.tif"));
BOOST_CHECK (!x ("abc0000000002", "abc0000000001"));
BOOST_CHECK (!x ("2", "1"));
BOOST_CHECK (!x ("2", "0001"));
BOOST_CHECK (!x ("999", "1"));
BOOST_CHECK (!x ("/my/numeric999/path/00166.tif", "/my/numeric999/path/00057.tif"));
+ BOOST_CHECK (!x ("1_02.tif", "1_01.tif"));
}