static bool string_sort_predicate(const wcstring& d1, const wcstring& d2) { return wcsfilecmp(d1.c_str(), d2.c_str()) < 0; }
int wcsfilecmp( const wchar_t *a, const wchar_t *b ) { CHECK( a, 0 ); CHECK( b, 0 ); if( *a==0 ) { if( *b==0) return 0; return -1; } if( *b==0 ) { return 1; } int secondary_diff=0; if( iswdigit( *a ) && iswdigit( *b ) ) { wchar_t *aend, *bend; long al; long bl; int diff; errno = 0; al = wcstol( a, &aend, 10 ); bl = wcstol( b, &bend, 10 ); if( errno ) { /* Huuuuuuuuge numbers - fall back to regular string comparison */ return wcscmp( a, b ); } diff = al - bl; if( diff ) return diff>0?2:-2; secondary_diff = (aend-a) - (bend-b); a=aend-1; b=bend-1; } else { int diff = towlower(*a) - towlower(*b); if( diff != 0 ) return (diff>0)?2:-2; secondary_diff = *a-*b; } int res = wcsfilecmp( a+1, b+1 ); if( abs(res) < 2 ) { /* No primary difference in rest of string. Use secondary difference on this element if found. */ if( secondary_diff ) { return secondary_diff>0?1:-1; } } return res; }
/** Wrapper for wcsfilecmp */ static int str_cmp( const void *a, const void *b ) { wchar_t *c= *((wchar_t **)a); wchar_t *d= *((wchar_t **)b); return wcsfilecmp( c, d ); }