OpenTTD

Tasklist

FS#4214 - Natural Sorting in the Group GUI

Attached to Project: OpenTTD
Opened by Sylvain Devidal (MagicBuzz) - Wednesday, 10 November 2010, 14:34 GMT
Last edited by Jose Soler (Terkhen) - Saturday, 27 November 2010, 22:53 GMT
Type Patch
Category Interface
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Here is a patch for natural sorting in the Group GUI.

As a result, when nanimg groups using numbers, they will be sorted accorting number ascending order ie:

Group0
Group1
Group2
[...]
Group9
Group10
instead of
Group0
Group1
Group10
Group11
[...]
Group2
Group20
[...]

This patch uses a GNU natsort implementation of Martin Pool found at sourceforge.
This task depends upon

Closed by  Jose Soler (Terkhen)
Saturday, 27 November 2010, 22:53 GMT
Reason for closing:  Implemented
Additional comments about closing:  In r21344.
Comment by Zdeněk Sojka (SmatZ) - Wednesday, 10 November 2010, 15:37 GMT
That patch can't be applied due to those copyright restrictions.
Comment by Sylvain Devidal (MagicBuzz) - Wednesday, 10 November 2010, 15:44 GMT
Which copyright restrictions ?

On the sourceforge web site, it's wrote this code can be distributed like zlib can be. OTTD actually uses zlib, so why can't it use this code ?
Also, in the comments of this code itself, it's wrote anyone can use it, modify it as free as he can, for personnal or commercial use. The only restriction is that the comments in strnatcmp.cpp and strnatcmp.h must not be removed, and a reference to the author should be included in the final program documentation.

If needed I could rewrite the strnatcmp function, but I'm affraid I'll produce something very similar as the current implementation of the algorythm is quite standard...
Comment by Sylvain Devidal (MagicBuzz) - Wednesday, 10 November 2010, 16:40 GMT
Ok, then I removed the code from Martin Pool and used a discontinued patch instead :

 FS#2284  - Natural sort for names in vehicle lists - r14276
Opened by Gabor Heja (kakaopor) - Tuesday, 09 September 2008, 07:52 GMT

strnatcmp.cpp and strnatcmp.h should no longer have copyright issues I guess.

I also changed most GUI windows in order to use strnatcmp instead of strcmp for name sorting (vehicle name, industry name, cargotype name, town name, etc.)
Some were not really needed (cargo and town by exemple) but I think it's more elegant to use the same sorting function everywhere. Thus it could be usefull for people who are working on newgrf and still didn't set readable names to those things.
Comment by Sylvain Devidal (MagicBuzz) - Wednesday, 10 November 2010, 17:22 GMT
Here is the patch for trunk r21131
Comment by Remko Bijker (Rubidium) - Wednesday, 10 November 2010, 17:47 GMT
Interestingly sorting numbers is only a (small) subset of properly supporting natural sorting of strings. To do it properly you have to account for other things as well, e.g. in Swedish it is z < ö, but in German ö < z. Fun, right?
http://www.unicode.org/reports/tr10/ got (quite) some interesting information about all this.

Luckily it is already implemented in ICU but nobody ever bothered writing the actual code to use it, though that leaves people not using ICU with the old behaviour which isn't a problem in my opinion; they did chose NOT to have support for natural sorting strings. See http://userguide.icu-project.org/collation for more information.
Comment by Sylvain Devidal (MagicBuzz) - Monday, 15 November 2010, 10:35 GMT
Patch update :
- Merged strnatcmp.cpp with string.cpp : strcmp and strnatcmp are virtually the same functions, so it not a bad idea I guess to put theim together
- Added nat sorting to several other windows such as towns, vehicles, cargo, industry and station

I can't understand how to work with ICU, so there is still no international natural order support.

Loading...