Hi,
I'm trying to fix bug http://bugs.freepascal.org/view.php?id=14135 but
could not get a way to do case insensitive comparison of UTF8 strings
with non ascii characters (in the test even ansi strings failed).
See the attached test program. I tried StrIComp, AnsiCompareText,
CompareText and even widestringmanager.CompareTextWideStringProc.
On Linux, only AnsiCompareText worked. On Windows none worked.
Any hints on how to do such comparison or this is a limitation of
current fpc? Or i'm doing something wrong?
BTW:
Key := 'ç';
Key will be encoded in the current system encoding Ok?
Key := Utf8Encode('ç');
'ç' will be converted to widestring and then back to Utf8 Ok?
Luiz
program bugCompInsensitiveUTF8;
{$mode objfpc}{$H+}
uses
{$ifdef unix}
cwstring,
{$endif}
Classes, SysUtils;
var
Key, Str: String;
begin
Key := 'c';
Str := 'C';
WriteLn('Testing C/c');
if stricomp(PChar(Key), PChar(Str)) = 0 then
WriteLn('StrIComp OK');
if AnsiCompareText(Key, Str) = 0 then
WriteLn('AnsiCompareText OK');
if CompareText(Key, Str) = 0 then
WriteLn('CompareText OK');
Key := 'ç';
Str := 'Ã';
WriteLn('Testing Ã/ç');
if stricomp(PChar(Key), PChar(Str)) = 0 then
WriteLn('StrIComp OK');
if AnsiCompareText(Key, Str) = 0 then
WriteLn('AnsiCompareText OK');
if CompareText(Key, Str) = 0 then
WriteLn('CompareText OK');
Key := UpperCase('ç');
Str := 'Ã';
WriteLn('Testing Ã/Uppercase(ç)');
if strcomp(PChar(Key), PChar(Str)) = 0 then
WriteLn('StrComp OK');
if AnsiCompareStr(Key, Str) = 0 then
WriteLn('AnsiCompareStr OK');
if CompareStr(Key, Str) = 0 then
WriteLn('CompareStr OK');
//test UTF8
Key := UTF8Encode('ç');
Str := UTF8Encode('Ã');
WriteLn('Testing UTF8 Ã/ç');
if stricomp(PChar(Utf8ToAnsi(Key)), PChar(Utf8ToAnsi(Str))) = 0 then
WriteLn('StrIComp OK');
if AnsiCompareText(Utf8ToAnsi(Key), Utf8ToAnsi(Str)) = 0 then
WriteLn('AnsiCompareText OK');
if CompareText(Utf8ToAnsi(Key), Utf8ToAnsi(Str)) = 0 then
WriteLn('CompareText OK');
if widestringmanager.CompareTextWideStringProc(UTF8Decode(Key), UTF8Decode(Str)) = 0 then
WriteLn('WideStringManager OK');
end.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal