Gerasimov, Ivan wrote:
> Hello, Hans-Emil!
>> I would say that the problem lies in trying to sort the likes of:
> Yes, you are right. Though, in the case you mentioned, the sorting will
> be done properly, since ‘.’ < ‘0’.
> The problem will arise, if some separator that is “greater” than a digit
> is used, like:
> To handle such cases properly, the routine has to remember the whole
> numbers that are at the places, where the strings are different.
> So, here is the improved version of the sample routine, which solves the
> problem, mentioned above.
> I also tried to make it locale-aware. Additionally, I eliminated the
> need to convert literal number to integer. This way, huge numbers that
> will not fit into int can be compared. All the comparisons are done with
> the CompareString() function from WinAPI.
First, thanks for the compare function.
I've already used your first function in TSVN to have it sort the items
in the repobrowser (try a nightly build and enable the "sort
numerically" checkbox in the settings 'dialog 2' page).
But I had to modify the function. You see, compare functions don't just
return true/false, they have to return a tri-state value. Most compare
functions therefore return -1 for 'less than', 0 for 'equal' and 1 for
'greater than'. The reason is that sort functions need it that way to
Now, your new function doesn't work. It first looked like it did, then I
tried the Subversion tags folder. Here the sorting failed. First I had
no clue why, but then I noticed that your new function checks
specifically for '0' - why is that?
Also, you don't really parse the numbers anymore. In the first function,
you 'parsed' the numbers into real integers like this:
y_num = 10 * y_num + *str2_tmp - '0';
There's nothing like this anymore in your new function.
Maybe you can just start over from where I put your first function
(at the end, the static method CUtils::CompareNumerical()).
oo // \\ "De Chelonian Mobile"
(_,\/ \_/ \ TortoiseSVN
\ \_/_\_/> The coolest Interface to (Sub)Version Control
/_/ \_\ http://tortoisesvn.tigris.org
To unsubscribe, e-mail: firstname.lastname@example.org
For additional commands, e-mail: email@example.com
Received on Wed Apr 12 16:31:50 2006