diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index f8fd98a..a0f5a07 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -3218,6 +3218,11 @@ compare_by_name_using_number (const gchar *ap, gchar bc; guint skipped_zeros_a; guint skipped_zeros_b; + const gchar *original_ap = ap; + const gchar *original_bp = bp; + guint i; + gchar hex_ac; + gchar hex_bc; /* up until now the numbers match. Now compare the numbers by digit * count, the longest number is the largest. If the lengths are equal @@ -3237,6 +3242,43 @@ 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. + */ + /* look for the end of either hex numbers. */ + for (ai = original_ap, bi = original_bp;; ++ai, ++bi) + { + hex_ac = *ai; + hex_bc = *bi; + if (!g_ascii_isxdigit (hex_ac) || !g_ascii_isxdigit (hex_bc)) + break; + } + + /* if both hex number and at the same location, do a ascii compares + * on the first digits. + */ + if (!g_ascii_isxdigit (hex_ac) && !g_ascii_isxdigit (hex_bc)) + { + /* ap and bp are on the first digit that differs. + * or on the digit before. do an ascii compare. + */ + hex_ac = *original_ap; + hex_bc = *original_bp; + if (hex_ac == hex_bc) + { + original_ap += 1; + original_bp += 1; + hex_ac = *original_ap; + hex_bc = *original_bp; + } + return hex_ac - hex_bc; + } + } + /* if one of the numbers still has a digit, that number is the largest. */ if (g_ascii_isdigit (ac)) return 1;