[Gambas-user] Natural sorting in Gambas 3

2010-01-25 Thread Benoît Minisini
Hi,

I have implemented string natural comparison and sorting in the last Gambas 3 
revision.

With that, you can, for example, sort a file name array returned by Dir() that 
way:

Photo1.jpg Photo1a.jpg Photo1b.jpg Photo2.jpg ... Photo9.jpg Photo10.jpg
Photo11.jpg

Instead of:

Photo1.jpg Photo10.jpg Photo 11.jpg Photo1a.jpg Photo1b.jpg Photo2.jpg 
... 
Photo9.jpg

For that, use the gb.Natural constant as sort flag.

Moreover, if you have non-ASCII letters, you can add gb.Language to the flag, 
and non-ASCII characters will be correctly sorted too. You will get:

Baba.jpg Bébé1.jpg Bébé8.jpg Bébé20.jpg Bibi.jpg Bobo.jpg

instead of:

Baba.jpg Bibi.jpg Bobo.jpg Bébé1.jpg Bébé20.jpg Bébé8.jpg 

How does it work?

The string is splitted between parts having digits only (0-9), and parts 
having no digits.

Parts having no digits are sorted as normal strings. 

Parts having digits are sorted according to their numerical values, unless it 
starts with a zero.

Enjoy it!

-- 
Benoît Minisini

--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Natural sorting in Gambas 3

2010-01-25 Thread Steven James Drinnan
Wow that must be a first in a programming language, as most don't even
bother. It's something that I always had a bug bear about. But have
never had the time to implement this sort of sort on my programs. 

Great work, it this sort of functionality that has made Gambas great.

Steven Drinnan
On Mon, 2010-01-25 at 20:33 +0100, Olivier Cruilles wrote:
 Hi Benoit,
 
 Thank you for this great new, I need exactly this kind of sort possibility, 
 but in Gambas 2.xx... 
 
 I'll wait for the stable Gambas 3.
 
 Le 25 janv. 2010 à 20:16, Benoît Minisini a écrit :
 
  Hi,
  
  I have implemented string natural comparison and sorting in the last Gambas 
  3 
  revision.
  
  With that, you can, for example, sort a file name array returned by Dir() 
  that 
  way:
  
  Photo1.jpg Photo1a.jpg Photo1b.jpg Photo2.jpg ... Photo9.jpg Photo10.jpg
  Photo11.jpg
  
  Instead of:
  
  Photo1.jpg Photo10.jpg Photo 11.jpg Photo1a.jpg Photo1b.jpg Photo2.jpg 
  ... 
  Photo9.jpg
  
  For that, use the gb.Natural constant as sort flag.
  
  Moreover, if you have non-ASCII letters, you can add gb.Language to the 
  flag, 
  and non-ASCII characters will be correctly sorted too. You will get:
  
  Baba.jpg Bébé1.jpg Bébé8.jpg Bébé20.jpg Bibi.jpg Bobo.jpg
  
  instead of:
  
  Baba.jpg Bibi.jpg Bobo.jpg Bébé1.jpg Bébé20.jpg Bébé8.jpg 
  
  How does it work?
  
  The string is splitted between parts having digits only (0-9), and parts 
  having no digits.
  
  Parts having no digits are sorted as normal strings. 
  
  Parts having digits are sorted according to their numerical values, unless 
  it 
  starts with a zero.
  
  Enjoy it!
  
  -- 
  Benoît Minisini
  
  --
  The Planet: dedicated and managed hosting, cloud storage, colocation
  Stay online with enterprise data centers and the best network in the 
  business
  Choose flexible plans and management services without long-term contracts
  Personal 24x7 support from experience hosting pros just a phone call away.
  http://p.sf.net/sfu/theplanet-com
  ___
  Gambas-user mailing list
  Gambas-user@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/gambas-user
 
 Olivier Cruilles
 Mail: linu...@club-internet.fr
 
 
 
 --
 The Planet: dedicated and managed hosting, cloud storage, colocation
 Stay online with enterprise data centers and the best network in the business
 Choose flexible plans and management services without long-term contracts
 Personal 24x7 support from experience hosting pros just a phone call away.
 http://p.sf.net/sfu/theplanet-com
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user
 


--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user