FreePascal lijkt anders om te gaan met Utf8Decode dan Delphi (in ieder geval anders dan D7).
Wat is de output van onderstaand programma op een moderne Delphi?
Delphi Code:
program u;
{$apptype console}
{$assertions on}
{$ifdef fpc}
{$codepage cp1252}
{$mode objfpc}
{$h+}
{$endif fpc}
uses
SysUtils;
{$ifndef fpc}
type
UnicodeString = WideString;
{$endif}
var
AStr: AnsiString;
UStr: UnicodeString;
begin
AStr := 'äëï';
Assert((Byte(AStr[1])=$E4) and (Byte(AStr[2])=$EB) and (Byte(AStr[3])=$EF),'AStr is not singlebyte encoded.');
UStr := Utf8Decode(AStr);
writeln('Length(UStr)=',Length(UStr));
end.
Delphi 7: Length(UStr)=0
fpc: Length(UStr)=3
De type definitie van UnicodeString is wellicht overbodig in modernere Delphi's?
Die assert is om te checken of mijn editor niet per ongeluk de broncode toch als UTF-8 heeft opgslagen.
Bart
Bookmarks