[fpc-pascal] StringList encoding question
Bart
bartjunk64 at gmail.com
Sun Dec 22 16:22:20 CET 2019
Hi,
Consider this code:
{$codepage utf8}
{$mode objfpc}
{$H+}
uses
SysUtils, Classes;
var
SL: TSTringList;
S: String;
begin
writeln('DefaultSystemCodePage = ',DefaultSystemCodePage);
SL := TStringList.Create;
{$if fpc_fullversion > 30200}
SL.WriteBom := False;
{$endif}
SL.SkipLastLineBreak := True;
S := 'ä'; //S has CodePage CP_UTF8
SL.Add(S);
SL.SaveToFile('slU.txt'{$if fpc_fullversion > 30200}, TEncoding.UTF8{$endif});
SL.SaveToFile('slA.txt'{$if fpc_fullversion > 30200}, TEncoding.ANSI{$endif});
SL.Free;
end.
Tested with fpc trunk (form a few days ago).
It outputs:
DefaultSystemCodePage = 1252 (I'm on Windows as you might have guessed)
The file slA.txt contains the bytes C3 A4 (which is ä in UTF8 encoding)
The file slU.txt contains the bytes C3 83 C2 A4
I struggle to understand why.
What is the codepage of the stringlist's internal list of strings
(array of TStringItem's)?
It seems that the stringlist considers it's internal
TStringItem.FString that has #$C3A#$A4 to have a codepage of CP_ACP
(always)?
Bart
--
Bart
More information about the fpc-pascal
mailing list