[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: Re: RE: Repobrowser - Numeric order filename sorting

From: Gerasimov, Ivan <Ivan.Gerasimov_at_transas.com>
Date: 2006-04-11 12:02:05 CEST

Hello, Stefan!

> > The comparing routine may not be so complicated. The following algorithm > may be used: 1) skip same leading chars, 2) if remaining parts begin with > digits, compare strings numerically 3) otherwise, compare strings
> literally.
>
> > Below is a sample function.
> > It's not perfect, but it works for the most cases.
                                                    ^^^^^^^^
> that's not good enough. It must work in all cases. Otherwise we'll get
> tons of bug reports like "numeric sorting doesn't work when ..." or
> "sorting corrupt if..." or " ...".
> Also, you should know that 'numeric sorting' depends on the currently
> used locale - it's not done the same way everywhere.

Yes, you're right on that.

> Another thing you might consider:
> what if the numbers actually are dates? The user then might want to
> sort by date, and the 'numeric sorting' does it wrong because it
> doesn't treat them as dates.
> So we then again will get bug reports (after all, the sorting doesn't
> do what the user expected).

2004.06.12
2005.06.12
2005.07.12
2005.07.13

What's wrong with dates?

> > // returns true, if x < y, false otherwise.
> > bool CompareNumericLess(LPCTSTR x_str, LPCTSTR y_str)
> > {
> > // skip same characters
> > while ((*x_str || *y_str) && *x_str == *y_str)

> I'm not comfortable with that. Imagine two identical strings "abc" and
> "abc".
> This loop will increment the pointer up to the \0 char terminating the
> strings, and then one char more (because the null char still makes the
> while clause true).

How come null char will make the clause true?
((0 || 0) && 0 == 0) == false.

> So after that while loop, the pointers x_str and y_str point *over the
> string*.

Nope.

> No you successfully handled strings like
> v103
> v204
> v387
> But, it still will be wrong for strings like
> v1.3.2
> v1.7.8
> because you stop at the first '.' char.
> You cold try using the atol() function, but that will also only work
> with one '.' char (or ',', depending on the locale), not two or three.

It doesn't stop at the first '.'
And the function will handle v1.3.2, v1.7.8 and alike correctly.
Just check it carefully :-)

> Implementing a feature just half way through is worse than having no
> feature at all - at least without the feature you don't have to deal
> with bugreport mails every day.

So far, I saw only one point against this routine - I don't know for sure, whether it work or not on different locales.
I'll try to investigate that then.

Sincerely yours,
Ivan Gerasimov

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Tue Apr 11 12:02:27 2006

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.