diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 5eac1cc..fbdf8fa 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -3182,6 +3182,7 @@ compare_by_name_using_number (const gchar *ap, const gchar *bi; guint ac; guint bc; + gint i; /* up until now the numbers match. Now compare the numbers by digit * count, the longest number is the largest. If the length are equal @@ -3197,6 +3198,53 @@ compare_by_name_using_number (const gchar *ap, break; } + /* this might be a hex number. */ + if (G_UNLIKELY (g_ascii_isxdigit (ac) && g_ascii_isxdigit (bc))) + { + /* hex numbers should have an equal size for the alpha digit to be + * considered part of the number. this means a hex number can be a + * ascii compare. + */ + /* compensate for the leading zeros in bp. */ + for (i = 0; i > leadingzero; --i, ++ai) + { + ac = *((const guchar *) ai); + if (!g_ascii_isxdigit (ac)) + break; + } + /* compensate for the leading zeros in ap. */ + for (i = 0; i < leadingzero; ++i, ++bi) + { + bc = *((const guchar *) bi); + if (!g_ascii_isxdigit (bc)) + break; + } + + /* look for the end of either hex numbers. */ + for (;; ++ai, ++bi) + { + ac = *((const guchar *) ai); + bc = *((const guchar *) bi); + if (!g_ascii_isxdigit (ac) || !g_ascii_isxdigit (bc)) + break; + } + + /* if both hex number and at the same location, do a ascii compares + * on the first digits. + */ + if (!g_ascii_isxdigit (ac) && !g_ascii_isxdigit (bc)) + { + /* with leading zeros ap or bp might not be on the first digit. */ + if (leadingzero > 0) + return -1; + else if (leadingzero < 0) + return 1; + + /* ap and bp are on the first digit. do an ascii compare. */ + return (*ap - *bp); + } + } + /* if one of the numbers still has a digit, that number is the largest. */ if (g_ascii_isdigit (ac)) return 1; @@ -3235,6 +3283,7 @@ skip_leading_zeros (const gchar **ap, { const gchar *bp; gchar bc = '0'; + gint zerocount = 0; /* **ap must be '0' when calling this function */ @@ -3251,16 +3300,15 @@ skip_leading_zeros (const gchar **ap, { for (bp = *ap + 1;; ++bp) { + ++zerocount; if (*bp != '0') break; } *ap = bp; - - return 1; } - return 0; + return zerocount; }