Recent

Author Topic: TStringList.Sort  (Read 11509 times)

typo

  • Hero Member
  • *****
  • Posts: 3051
TStringList.Sort
« on: February 27, 2010, 08:43:54 pm »
Sorting wide characters in a TStringList is not made correctly, because the accented words are positioned before all the other words. Is it a bug? Should I create a bug report?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: TStringList.Sort
« Reply #1 on: February 27, 2010, 08:50:58 pm »
Sorting wide characters in a TStringList is not made correctly, because the accented words are positioned before all the other words. Is it a bug? Should I create a bug report?

Can you show how you do this?
TStringList works with AnsiString not with WideString/WideChar

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStringList.Sort
« Reply #2 on: February 27, 2010, 08:53:09 pm »
I simply used a sorted TStringList to sort a list of words in a literary text in portuguese. The words that began with accented characters were positioned before all the other words.

Better saying, the words beginning with accented characters were position following the word "a".
« Last Edit: February 27, 2010, 09:08:39 pm by typo »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStringList.Sort
« Reply #3 on: February 27, 2010, 09:03:32 pm »
Like this:

A
à
às
ônibus
é
época
aba
abateria
abatia-se
aberta
aberto
aborrecido
abraçado
Abriu
acaju
acenava
achatadas

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStringList.Sort
« Reply #4 on: February 27, 2010, 09:14:54 pm »
Or this:

andava
anos
ansiedade
Antônio  <<<
antes     
ao
última   <<<<<<<<<<<<<<<<<<<<
úmido   <<<<<<<<<<<<<<<<<<<<
Aonde
aos
aparência   <<<<<
aparecendo
aparecer
apareceu
« Last Edit: February 27, 2010, 09:20:46 pm by typo »

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: TStringList.Sort
« Reply #5 on: February 27, 2010, 09:20:11 pm »
Try to use you own compare function. TStringList does an AnsiCompare by default.
Try this:

function UTF8Compare(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result:=WideCompareStr(UTF8Decode(List[Index1]),UTF8Decode(List[Index2]));
end;

...

sl.CustomSort(@UTF8Compare);

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStringList.Sort
« Reply #6 on: February 27, 2010, 10:39:05 pm »
If I implement my own sorting algorithm to the list, TStringList will still doing the task inappropriately...

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: TStringList.Sort
« Reply #7 on: February 27, 2010, 10:55:08 pm »
Why? I'm getting this result when using the code above and your words:

andava
anos
ansiedade
antes
Antônio
ao
Aonde
aos
aparecendo
aparecer
apareceu
aparência
última
úmido

This looks quite "appropriate" to me.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStringList.Sort
« Reply #8 on: February 27, 2010, 11:04:41 pm »
Well, if you call this "appropriate"...

aparência
última

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: TStringList.Sort
« Reply #9 on: February 27, 2010, 11:08:25 pm »
Well, if you call this "appropriate"...

aparência
última

You should probably explain what you expect.
I can't see a problem here.
What's wrong with

aparência
última
?

 

TinyPortal © 2005-2018