Table of strings sorting problem
John C
johnch_atms at hotmail.com
Sat Mar 11 04:14:03 PST 2006
Aarti wrote:
> Hello all D-Fans!
>
> I encountered a problem with string sorting according to Polish language
> rules. Here is a simple test program:
>
> // ----------------------------------
> import std.stdio;
> void main() {
> char[][] table;
> table.length=15;
>
> table[0]="ą";
> table[1]="a";
> table[2]="ć";
> table[3]="c";
> table[4]="ę";
> table[5]="e";
> table[6]="ń";
> table[7]="n";
> table[6]="ł";
> table[7]="l";
> table[8]="ó";
> table[9]="o";
> table[10]="ś";
> table[11]="s";
> table[12]="ź";
> table[13]="ż";
> table[14]="z";
>
> table.sort;
>
> foreach(char[] s; table) {
> writef(s);
> }
> writefln();
> }
> // ----------------------------------
>
> Output of this test is:
> aceloszóąćęłśźż
>
> when it should be:
> aącćeęlłoósśzźż
>
> It looks like sort doesn't sort properly according to language rules.
>
> Is it a known issue? How to sort strings in D according to language rules?
>
> PS. Possibility of using Polish characters in class identifiers is for
> me really cool. In C++ books in examples you can see all the time
> Trojkat instead of Trójkąt (triangle) and it looks awful.
>
> Regards
> Marcin Kuszczak
As others have implied, D's standard library isn't culturally aware.
I've been working on a locale package for Mango that will eventually
allow correct string sorting for specific languages. This is how you'd
sort a list of Polish characters:
const char[][] table = [ "a","ą","c","ć","e","ę" ];
Culture.current = Culture.getCulture("pl-PL");
table.sort();
More information about the Digitalmars-d
mailing list