Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ファイラの自然順ソートをエクスプローラとあわせる (#347)
従来の自然順ソートアルゴリズムでは数字の桁数で大小を比較しているため、
先頭に 0 がついている場合にソート順がエクスプローラとずれる場合があった。

例)
  3.txt
  02.txt
  001.txt

数字部分に関しては数値に変換した上で大小を比較するように変更する。
  • Loading branch information
x022235 committed Jul 30, 2012
1 parent 2d34c72 commit 4f50648
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/filer.cc
Expand Up @@ -583,18 +583,10 @@ compare_filename (const char *s1, const char *s2, int param)
u_char c1 = *p1++, c2 = *p2++;
if (digit_char_p (c1) && digit_char_p (c2))
{
const u_char *const b1 = p1 - 1;
for (; digit_char_p (*p1); p1++)
;
const u_char *const b2 = p2 - 1;
for (; digit_char_p (*p2); p2++)
;
int l1 = p1 - b1, l2 = p2 - b2;
if (l1 != l2)
return l1 - l2;
int d = memcmp (b1, b2, l1);
if (d)
return d;
int n1 = atoi (reinterpret_cast <const char *> (p1 - 1));
int n2 = atoi (reinterpret_cast <const char *> (p2 - 1));
if (n1 != n2)
return n1 - n2;
}
else
{
Expand Down

0 comments on commit 4f50648

Please sign in to comment.