--- a/thunar/thunar-file.c +++ a/thunar/thunar-file.c @@ -3168,24 +3168,40 @@ compare_by_name_using_number (const gchar *ap, const gchar *bp) { - guint64 anum; - guint64 bnum; + gint alen = 0, blen = 0; + const gchar *ap_start = ap; + const gchar *bp_start = bp; + const gchar *p; - /* determine the numbers in ap and bp */ - anum = strtouq (ap, NULL, 10); - bnum = strtouq (bp, NULL, 10); + /* skip leading zeroes */ + for (; *ap == '0'; ap++); + for (; *bp == '0'; bp++); + + /* count significant digits */ + for (p = ap; g_ascii_isdigit(*p); p++); + alen = p - ap; + + for (p = bp; g_ascii_isdigit(*p); p++); + blen = p - bp; + + /* compare the lengths */ + if (alen < blen) + return -1; + if (alen > blen) + return 1; /* compare the numbers */ - if (anum < bnum) + int cmp = strncmp(ap, bp, alen); + if (cmp < 0) return -1; - else if (anum > bnum) + if (cmp > 0) return 1; /* the numbers are equal, and so the higher first digit should * be sorted first, i.e. 'file10' before 'file010', since we * also sort 'file10' before 'file011'. */ - return (*bp - *ap); + return (*bp_start - *ap_start); }